Skip to content

Commit 345a018

Browse files
committed
chore: Adding unstable releases. Removing need of a release branch and instead kicking off the release by merging into main
1 parent 9f0cd72 commit 345a018

File tree

3 files changed

+119
-25
lines changed

3 files changed

+119
-25
lines changed

.github/workflows/release_authenticator.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
name: Release Authenticator
22
on:
33
push:
4-
branches: [ release ]
4+
branches: [ main ]
55

66
permissions:
77
id-token: write
88
contents: write
99

1010
jobs:
11+
determine-release-type:
12+
name: Determine the release type
13+
runs-on: ubuntu-latest
14+
outputs:
15+
release-type: ${{ steps.release-type.outputs.value }}
16+
steps:
17+
- id: release-type
18+
run: |
19+
if ${{ github.event.head_commit.author.username == 'github-actions[bot]' && startsWith(github.event.head_commit.message, 'chore: Release ') }}; then
20+
VALUE=stable
21+
else
22+
VALUE=unstable
23+
fi
24+
echo "value=$VALUE" >> $GITHUB_OUTPUT
25+
1126
unit-tests:
1227
name: Run Unit Tests
1328
uses: ./.github/workflows/unit_tests.yml
@@ -16,8 +31,8 @@ jobs:
1631

1732
release:
1833
environment: Release
19-
name: Release new Authenticator version
20-
needs: [unit-tests]
34+
name: Release new Authenticator ${{ needs.determine-release-type.outputs.release-type }} version
35+
needs: [determine-release-type, unit-tests]
2136
runs-on: macos-latest
2237
env:
2338
GITHUB_EMAIL: [email protected]
@@ -53,5 +68,24 @@ jobs:
5368
ruby-version: '3.2.1'
5469
bundler-cache: true
5570

56-
- name: Release Authenticator
57-
run: bundle exec fastlane release
71+
- name: Release unstable version
72+
if: needs.determine-release-type.outputs.release-type == 'unstable'
73+
env:
74+
GH_TOKEN: ${{ github.token }}
75+
run: bundle exec fastlane unstable_release
76+
77+
- name: Determine stable release version
78+
id: determine-release-version
79+
if: needs.determine-release-type.outputs.release-type == 'stable'
80+
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
81+
with:
82+
result-encoding: string
83+
script: |
84+
const matches = `${{ github.event.head_commit.message }}`.match(/[0-9]+\.[0-9]+\.[0-9]+/) ?? []
85+
return matches.length > 0 ? matches[0] : ""
86+
87+
- name: Release stable version
88+
if: steps.determine-release-version.outputs.result != ''
89+
env:
90+
GH_TOKEN: ${{ github.token }}
91+
run: bundle exec fastlane stable_release version:${{ steps.determine-release-version.outputs.result }}

.github/workflows/release_kickoff.yml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,49 @@ on:
33
workflow_dispatch:
44

55
permissions:
6+
id-token: write
67
pull-requests: write
78

89
jobs:
910
release:
10-
name: Release
11-
runs-on: ubuntu-latest
12-
11+
environment: Release
12+
name: Kick off new Authenticator release
13+
runs-on: macos-latest
14+
env:
15+
GITHUB_EMAIL: [email protected]
16+
GITHUB_USER: aws-amplify-ops
1317
steps:
14-
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
15-
- name: Create PR to push main to release branch
18+
- name: Configure AWS credentials
19+
uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4
20+
with:
21+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
22+
role-session-name: ${{ format('{0}.release', github.run_id) }}
23+
aws-region: ${{ secrets.AWS_REGION }}
24+
mask-aws-account-id: true
25+
26+
- id: retrieve-token
27+
name: Retrieve Token
28+
env:
29+
DEPLOY_SECRET_ARN: ${{ secrets.DEPLOY_SECRET_ARN }}
30+
run: |
31+
PAT=$(aws secretsmanager get-secret-value \
32+
--secret-id "$DEPLOY_SECRET_ARN" \
33+
| jq -r ".SecretString | fromjson | .Credential")
34+
echo "token=$PAT" >> $GITHUB_OUTPUT
35+
36+
- name: Checkout repo
37+
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
38+
with:
39+
fetch-depth: 10
40+
token: ${{steps.retrieve-token.outputs.token}}
41+
42+
- name: Setup Ruby
43+
uses: ruby/setup-ruby@22fdc77bf4148f810455b226c90fb81b5cbc00a7 # v1.171.0
44+
with:
45+
ruby-version: '3.2.1'
46+
bundler-cache: true
47+
48+
- name: Kick off Authenticator release
1649
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
run: "gh pr create --title 'chore: kickoff release' --body 'kickoff release' --head main --base release"
50+
GH_TOKEN: ${{ github.token }}
51+
run: bundle exec fastlane kickoff_release

fastlane/Fastfile

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ platform :swift do
99
sh('git', 'fetch')
1010
end
1111

12-
desc "Create a release version by building and committing a changelog, pushing a tag to GitHub"
13-
lane :release do
12+
desc "Kickoff the next release by updating the changelog, updating the component version, and creating a PR to main"
13+
lane :kickoff_release do
1414
next_version, commits = calculate_next_release_version
1515

16-
UI.message("Releasing version: #{next_version}")
17-
16+
UI.message("Kicking off new release for version: #{next_version}")
1817
# Increment all specs and plists
1918
increment_versions(version: next_version)
2019

@@ -25,11 +24,16 @@ platform :swift do
2524
# Update Package dependencies
2625
sh('bundle', 'exec', 'swift', 'package', 'update')
2726

27+
# Create and push the new branch
28+
release_branch = "release/#{next_version}"
29+
sh('git', 'checkout', '-b', release_branch)
30+
sh('git', 'push', '--set-upstream', 'origin', release_branch)
31+
2832
# Commit and push
29-
release_commit(version: next_version)
33+
pr_title = release_commit(version: next_version).to_s
3034

31-
# Create tag and push to origin
32-
add_tag(version: next_version)
35+
# Open the PR to main
36+
sh('gh', 'pr', 'create', '--title', pr_title, '--body', 'Kicking off new release', '--base', 'main', '--head', release_branch)
3337
end
3438

3539
desc "Increment versions"
@@ -45,18 +49,41 @@ platform :swift do
4549
sh('git', 'config', '--global', 'user.email', ENV['GITHUB_EMAIL'])
4650
sh('git', 'config', '--global', 'user.name', ENV['GITHUB_USER'])
4751

48-
commit_message = "chore: Release #{next_version} [skip ci]"
52+
commit_message = "chore: Release #{next_version}"
4953
sh('git', 'commit', '-am', commit_message)
54+
sh('git', 'push')
55+
commit_message
56+
end
57+
58+
desc "Create a pre-release version by pushing a new tag to GitHub"
59+
lane :unstable_release do
60+
next_version = calculate_next_canary_version
61+
62+
UI.message("Releasing Authenticator unstable version: #{next_version}")
63+
64+
# Create tag and push to origin
65+
add_tag(version: next_version)
66+
end
67+
68+
desc "Create a release version by pushing a new tag to GitHub and creating a new draft release"
69+
lane :stable_release do |options|
70+
next_version = options[:version]
71+
72+
UI.message("Releasing Authenticator version: #{next_version}")
5073

51-
# push to origin
52-
sh('git', 'push', 'origin', 'release')
53-
sh('git', 'push', 'origin', 'release:main')
74+
# Create and push the new tag
75+
add_tag(version: next_version)
76+
77+
# Create draft release
78+
release_date = sh("echo $(date +%F)")
79+
release_title = "#{next_version} (#{release_date})"
80+
sh('gh', 'release', 'create', next_version, '--draft', '--title', release_title)
5481
end
5582

83+
5684
desc "Tag in git and push to GitHub"
5785
private_lane :add_tag do |options|
58-
next_version = options[:version]
59-
next_tag = "#{next_version}"
86+
next_tag = options[:version].to_s
6087

6188
add_git_tag(tag: next_tag)
6289
push_git_tags(tag: next_tag)

0 commit comments

Comments
 (0)