Skip to content

Instantly share code, notes, and snippets.

@ronjunevaldoz
Last active September 15, 2019 01:10
Show Gist options
  • Save ronjunevaldoz/8b58afdb38e84ad51658ee09cd5b446f to your computer and use it in GitHub Desktop.
Save ronjunevaldoz/8b58afdb38e84ad51658ee09cd5b446f to your computer and use it in GitHub Desktop.
desc "Add google play changelog"
private_lane :add_google_play_changelog do |options|
root_changelog = File.read("../CHANGELOG")
log = root_changelog.split("##")
version_code = options[:version_code] or 0
version_name = options[:version_name] or ""
current_log = log[0]
if current_log.nil?
puts "Invalid: No root changelog found!"
else
changelog_dir = "#{Dir.pwd}/metadata/android/en-US/changelogs"
Dir.mkdir(changelog_dir) unless Dir.exist?(changelog_dir)
if File.directory?(changelog_dir)
new_changelog = "#{changelog_dir}/#{version_code}.txt"
puts "Creating new changelog: #{new_changelog}"
unless version_code.nil? || version_code == 0
begin
file = File.new(new_changelog, 'w+')
file.puts(current_log)
puts "Success: #{version_code}.txt changelog created"
rescue IOError => e
#some error occur, dir not writable etc.
puts e
ensure
file.close unless file.nil?
end
else
puts "Invalid: Version code"
end
else
puts "Directory does not exists: #{changelog_dir}"
end
end
end
# Sample usage
# can use GRADLE_ALL_OUTPUT_JSON_OUTPUT_PATHS is now supported https://github.com/fastlane/fastlane/releases/tag/2.131.0
lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS].each do | apk |
output = load_json(json_path: File.dirname(apk) + "/output.json" )
puts output
apk_data = output[0]["apkData"]
version_name = apk_data["versionName"]
version_code = apk_data["versionCode"]
add_google_play_changelog(
version_code: version_code,
version_name: version_name
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment