Skip to content

Commit e240f67

Browse files
committed
chore: refactoring to avoid release branch
1 parent 9f0cd72 commit e240f67

File tree

3 files changed

+100
-25
lines changed

3 files changed

+100
-25
lines changed

.github/workflows/release_authenticator.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,48 @@
11
name: Release Authenticator
22
on:
33
push:
4-
branches: [ release ]
4+
branches: [ ruisebas/main ]
55

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

1010
jobs:
11+
determine-next-version:
12+
name: Determine the next release version
13+
runs-on: ubuntu-latest
14+
outputs:
15+
version: ${{ steps.extract-release-version.outputs.result }}
16+
if: "${{ github.event.head_commit.author == 'github-actions' && startsWith(github.event.head_commit.message, 'chore: Release ') }}"
17+
steps:
18+
- name: Extract release version
19+
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
20+
id: extract-release-version
21+
with:
22+
result-encoding: string
23+
script: |
24+
const matches = `${{ github.event.head_commit.message }}`.match(/[0-9]+\.[0-9]+\.[0-9]+/) ?? []
25+
return matches.length > 0 ? matches[0] : ""
26+
27+
validate-version-format:
28+
name: Validate Version Format
29+
needs: [determine-next-version]
30+
if: ${{ needs.determine-next-version.outputs.version != '' }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- run: echo "Releasing new version ${{ needs.determine-next-version.outputs.version }}"
34+
1135
unit-tests:
1236
name: Run Unit Tests
37+
needs: [validate-version-format]
1338
uses: ./.github/workflows/unit_tests.yml
1439
with:
1540
identifier: 'workflow-call-unit-test'
1641

1742
release:
1843
environment: Release
1944
name: Release new Authenticator version
20-
needs: [unit-tests]
45+
needs: [unit-tests, determine-next-version]
2146
runs-on: macos-latest
2247
env:
2348
GITHUB_EMAIL: [email protected]
@@ -54,4 +79,6 @@ jobs:
5479
bundler-cache: true
5580

5681
- name: Release Authenticator
57-
run: bundle exec fastlane release
82+
env:
83+
GH_TOKEN: ${{ github.token }}
84+
run: bundle exec fastlane perform_release version:${{ needs.determine-next-version.outputs.version }}
Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
11
name: Release - Kick-off
22
on:
33
workflow_dispatch:
4+
push:
5+
branches: [ dev ]
46

57
permissions:
8+
id-token: write
69
pull-requests: write
710

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

fastlane/Fastfile

Lines changed: 28 additions & 15 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 "Preparing next release by building and committing a changelog, updating the component version, and creating a PR to main"
13+
lane :prepare_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', 'ruisebas/main', '--head', release_branch)
3337
end
3438

3539
desc "Increment versions"
@@ -45,20 +49,29 @@ 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
5057

51-
# push to origin
52-
sh('git', 'push', 'origin', 'release')
53-
sh('git', 'push', 'origin', 'release:main')
58+
desc "Push a new tag to GitHub and creating a new draft release"
59+
lane :perform_release do |options|
60+
next_version = options[:version]
61+
# Create and push the new tag
62+
add_tag(version: next_version)
63+
64+
# Create draft release
65+
release_title = sh("echo $(date +%F)")
66+
sh('gh', 'release', 'create', '--draft', '--verify-tag', '--title', release_title)
5467
end
5568

5669
desc "Tag in git and push to GitHub"
5770
private_lane :add_tag do |options|
58-
next_version = options[:version]
59-
next_tag = "#{next_version}"
71+
next_tag = options[:version].to_s
6072

61-
add_git_tag(tag: next_tag)
62-
push_git_tags(tag: next_tag)
73+
puts "Creating new tag #{next_tag}"
74+
#add_git_tag(tag: next_tag)
75+
#push_git_tags(tag: next_tag)
6376
end
6477
end

0 commit comments

Comments
 (0)