Notes

Fastlane - Check if a release notes file exists (for Android)

Check if a release notes file for the current version exists and use it when releasing to Firebase. If one for the version code doesn’t exist then check for the default.txt file and use that. If that also doesn’t exist then use the default release text message.

Edit on GitHub

Fastlane
2 minutes
  • You can use File.exist() to check if a file exists. File.exists() (with an S at the end) is deprecated
  • You can get the version code for Android using the fastlane-plugin-versioning_android plugin’s android_get_version_code()
  • You can get the Android app’s metadata from the Play Console using Fastlane supply
  • The changelogs for Android are saved in metadata/android/en-GB/changelogs/. Every language gets its own folder
  • Get the file path for the changelog for the versionCode i.e. build version that you’re releasing. For example: 'metadata/android/en-GB/changelogs/' + ANDROID_BUILD + '.txt'
  • Use if/else to set which file to use depending on whether it exists or not.

Check if a file exists

# Does this file already exist?
File.exist?("log.txt")

Get the path for the version specific release notes file

release_notes_file_path = 'metadata/android/en-GB/changelogs/' + ANDROID_BUILD + '.txt' # metadata/android/en-GB/changelogs/18.txt
if File.exist?(release_notes_file_path)
  puts "file exists"
else
  puts "file #{release_notes_file_path} does not exist"
end
 1android_version_code = android_get_version_code(
 2  gradle_file: "android/app/build.gradle"
 3)
 4
 5# get the path for the relevat release notes file
 6release_notes_version_file_path = 'metadata/android/en-GB/changelogs/' + ANDROID_BUILD + '.txt' # metadata/android/en-GB/changelogs/18.txt
 7release_notes_default_file_path = 'metadata/android/en-GB/changelogs/default.txt'
 8release_notes_default_text = "Bug fixes and performance improvements"
 9
10if File.exist?(release_notes_version_file_path)
11  puts "version file exists #{release_notes_version_file_path}"
12elsif File.exist?(release_notes_default_file_path)
13  puts "default file exists #{release_notes_default_file_path}"
14else
15  puts "neither #{release_notes_version_file_path}, nor #{release_notes_default_file_path} exist"
16end
 1android_version_code = android_get_version_code(
 2  gradle_file: "android/app/build.gradle"
 3)
 4
 5# get the path for the relevat release notes file
 6release_notes_version_file_path = 'metadata/android/en-GB/changelogs/' + ANDROID_BUILD + '.txt' # metadata/android/en-GB/changelogs/18.txt
 7release_notes_default_file_path = 'metadata/android/en-GB/changelogs/default.txt'
 8release_notes_default_text = "Bug fixes and performance improvements"
 9
10if File.exist?(release_notes_version_file_path)
11  puts "version file exists #{release_notes_version_file_path}"
12elsif File.exist?(release_notes_default_file_path)
13  puts "default file exists #{release_notes_default_file_path}"
14else
15  puts "neither #{release_notes_version_file_path}, nor #{release_notes_default_file_path} exist"
16end
17
18firebase_app_distribution(
19  app: ENV["FIREBASE_APP_ID"],
20  # testers: ENV["FIREBASE_TESTERS"],
21  testers: "aamnah@aamnah.com",
22  # groups: ENV['FIREBASE_GROUPS'],
23  apk_path: "android/app/build/outputs/apk/release/app-release.apk"
24
25  # release_notes: ENV['DEFAULT_RELEASE_NOTE'],
26  if File.exist?(release_notes_version_file_path)
27    release_notes_file: "#{release_notes_version_file_path}"
28  elsif File.exist?(release_notes_default_file_path)
29    release_notes_file: "#{release_notes_default_file_path}"
30  else
31    release_notes: "#{release_notes_default_text}"
32  end
33)

Related