Skip to content

Commit 8459461

Browse files
authored
chore: use shared lane file (#1282)
1 parent cbbc308 commit 8459461

File tree

2 files changed

+31
-140
lines changed

2 files changed

+31
-140
lines changed

.github/workflows/release_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
RELEASE_MANAGER_TOKEN: ${{ secrets.RELEASE_MANAGER_TOKEN }}
4343
run: |
4444
cd scripts
45-
bundle exec fastlane android create_next_release_pr repo:${{ github.repository }} product_name:"Amplify Android"
45+
bundle exec fastlane android create_next_release_pr
4646
- name: Check modified file content
4747
run: |
4848
cat gradle.properties

scripts/fastlane/Fastfile

Lines changed: 30 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,38 @@
1-
RELEASE_TAG_PREFIX = 'release_v'
21
default_platform(:android)
32

4-
platform :android do |options|
5-
gradle_properties_path = File.expand_path("#{Dir.pwd()}/../../gradle.properties")
6-
gradle_project_root = File.dirname(gradle_properties_path)
7-
change_log_path = "#{gradle_project_root}/CHANGELOG.md"
8-
main_readme_path = "#{gradle_project_root}/README.md"
9-
rx_readme_path = "#{gradle_project_root}/rxbindings/README.md"
10-
version_regex = /(\d*)\.(\d*)\.(\d*)(?:-unstable\.)?(\d*)?/
11-
pr_body = %Q(
12-
## Release PR review checklist
13-
- [ ] Verify version name in gradle.properties
14-
- [ ] Verify CHANGELOG.md
3+
import_from_git(
4+
url: '[email protected]:aws-amplify/amplify-ci-support.git',
5+
branch: 'android/fastlane-actions',
6+
path: './src/fastlane/release_actions/fastlane/AndroidAppsFastfile'
157
)
168

17-
desc "Fetch all tags to ensure accurate calculation of the next release number."
18-
before_all do
19-
sh('git', 'fetch', '--tags')
20-
sh('git', 'fetch')
21-
end
22-
23-
lane :configure_git_options do |options|
24-
sh('git', 'config', 'user.email', options[:git_user_email])
25-
sh('git', 'config', 'user.name', options[:git_user_name])
26-
end
27-
28-
lane :create_next_release_pr do |options|
29-
# This will be used in the commit and PR title
30-
product_name = options[:product_name]
31-
maven_group_name = CredentialsManager::AppfileConfig.try_fetch_value(:package_name)
32-
# Find the tag for the last release
33-
last_release_tag = last_git_tag(pattern: "#{RELEASE_TAG_PREFIX}*")
34-
last_version = last_release_tag.dup
35-
last_version.slice! "#{RELEASE_TAG_PREFIX}"
36-
37-
# Calculate the next version
38-
next_version, commits = calculate_next_release_version(release_tag_prefix: RELEASE_TAG_PREFIX, from_tag: last_release_tag)
39-
# Build the tag name for the new release
40-
release_tag_name = "#{RELEASE_TAG_PREFIX}#{next_version}"
41-
42-
UI.message("Version change #{last_release_tag} => #{next_version}")
43-
44-
# Get the changelog body and append to the change log.
45-
changelog_body = generate_changelog(last_release_tag: last_release_tag)
46-
update_change_log(
47-
changelog_body: changelog_body,
48-
last_version: last_version,
49-
next_version: next_version,
50-
repo: options[:repo])
51-
# Update gradle.properties with the new version
52-
update_gradle_properties(version: next_version)
53-
# Update the version in the README.md file
54-
update_docs(file_path:main_readme_path, version: next_version, maven_group_name:maven_group_name)
55-
update_docs(file_path:rx_readme_path, version: next_version, maven_group_name:maven_group_name)
56-
57-
# Commit and push those changes to the branch we're using to do the version bump.
58-
git_add(path: [gradle_properties_path, change_log_path, main_readme_path, rx_readme_path])
59-
git_commit(path: [gradle_properties_path, change_log_path, main_readme_path, rx_readme_path], message: "release: #{product_name} - #{next_version}")
60-
push_to_git_remote(force: true)
61-
62-
# Create the PR for the new release
63-
create_pull_request(base: 'main',
64-
title: "release: #{next_version}",
65-
body:pr_body,
66-
repo: options[:repo],
67-
api_token: ENV["RELEASE_MANAGER_TOKEN"])
68-
69-
# Create the new Github release in draft status. This will be updated manually after the binaries get pushed to Maven.
70-
set_github_release(
71-
repository_name: options[:repo],
72-
api_token: ENV["RELEASE_MANAGER_TOKEN"],
73-
name: "#{product_name} #{next_version}",
74-
tag_name: release_tag_name,
75-
description: changelog_body,
76-
is_draft: true)
77-
end
78-
79-
# Updates the version numbers in the README.md
80-
private_lane :update_docs do |options|
81-
readme_path = options[:file_path]
82-
readme_contents = File.read(readme_path)
83-
maven_group_name = options[:maven_group_name]
84-
85-
# Regex voodoo. \\1 refers to the module name which is the first capture group of the regex. We need that to rebuild the string with the new version.
86-
readme_contents = readme_contents.gsub(/implementation\s'#{maven_group_name}:(.*):(.*)'/,"implementation \'#{maven_group_name}:\\1:#{options[:version]}\'")
87-
open(readme_path, 'w') { |f|
88-
f.puts readme_contents
89-
}
90-
end
91-
92-
# Generate the changelog notes for the new release.
93-
private_lane :generate_changelog do |options|
94-
releases = {
95-
feat: "minor",
96-
fix: "patch",
97-
chore: "patch",
98-
refactor: "patch",
99-
perf: "patch",
100-
test: "patch",
101-
docs: "patch",
102-
no_type: "patch"
103-
}
9+
# When testing against local changes, comment out the above and use the line below instead.
10+
# import '~/github/aws-amplify/amplify-ci-support/src/fastlane/release_actions/fastlane/AndroidAppsFastfile'
10411

105-
# The analyze_commits function is a pre-requisite to running conventional_changelog. However, the versioning logic
106-
# used by analyze_commits increments the version number once for each commit that's part of the release. As a result,
107-
# you end up "wasting" version numbers. For example, your last release is 1.1.2 and you have 5 bug fixes to go in the
108-
# next release, the version calculated by analyze_commit would be 1.1.7. We'll just use the version number we
109-
# get from calculate_next_release_version. We'll use semantic_release for generating the change log since it has
110-
# a richer feature set.
111-
isReleasable = analyze_commits(match: "#{options[:last_release_tag]}", codepush_friendly:[], releases: releases)
112-
113-
# We won't display the title generated by conventional_changelog because it will have the
114-
# incorrect version.
115-
conventional_changelog(
116-
display_title: false,
117-
display_links: false,
118-
sections: {
119-
feat: 'Features',
120-
fix: 'Bug Fixes',
121-
no_type: 'Miscellaneous'
122-
}
123-
)
124-
end
125-
126-
desc "Append the changes to the CHANGELOG file."
127-
private_lane :update_change_log do |options|
128-
open(change_log_path, 'a') { |f|
129-
f.puts "# Release #{options[:next_version]}\n\n"
130-
f.puts "#{options[:changelog_body]}\n\n"
131-
last_version_tag = "#{RELEASE_TAG_PREFIX}#{options[:last_version]}"
132-
next_version_tag = "#{RELEASE_TAG_PREFIX}#{options[:next_version]}"
133-
compare_tags = "#{last_version_tag}...#{next_version_tag}"
134-
diff_text = "See all changes between #{options[:last_version]} and #{options[:next_version]}"
135-
diff_link = "https://github.com/#{options[:repo]}/compare/#{compare_tags}"
136-
f.puts "[#{diff_text}](#{diff_link})"
12+
platform :android do |options|
13+
override_lane :build_parameters do
14+
project_root = File.expand_path("#{Dir.pwd()}/../..")
15+
UI.message("Building version groups for amplify-android from #{project_root}")
16+
{
17+
repo: 'aws-amplify/amplify-android',
18+
product_name: 'Amplify Android',
19+
releases: [
20+
{
21+
release_tag_prefix: 'release_v',
22+
gradle_properties_path: "#{project_root}/gradle.properties",
23+
doc_files_to_update: ["#{project_root}/README.md", "#{project_root}/rxbindings/README.md"],
24+
release_title: 'Amplify Android',
25+
changelog_path: "#{project_root}/CHANGELOG.md",
26+
},
27+
{
28+
release_tag_prefix: 'release-kotlin_v',
29+
gradle_properties_path: "#{project_root}/core-kotlin/gradle.properties",
30+
doc_files_to_update: [],
31+
release_title: 'Amplify Android Kotlin Facade',
32+
changelog_path: "#{project_root}/core-kotlin/CHANGELOG.md",
33+
}
34+
]
13735
}
13836
end
139-
140-
desc "Increment versions"
141-
private_lane :update_gradle_properties do |options|
142-
version = options[:version].to_s
143-
segments = version.match(version_regex).captures # version.split('.')
144-
UI.message("Updating versionName in gradle.properties")
145-
set_key_value(file: gradle_properties_path, key: 'VERSION_NAME', value: version)
146-
end
14737
end
38+

0 commit comments

Comments
 (0)