Skip to content

Commit 563ce4f

Browse files
committed
ci: add release workflow
1 parent f0a3f5c commit 563ce4f

File tree

3 files changed

+121
-2
lines changed

3 files changed

+121
-2
lines changed

.github/workflows/build-on-minimum-supported-platform.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ name: Build on minimum supported platforms
22

33
on:
44
workflow_dispatch:
5+
workflow_call:
6+
inputs:
7+
identifier:
8+
required: true
9+
type: string
510
pull_request:
611
branches:
712
- main
813

914
permissions: {}
1015

1116
concurrency:
12-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1318
cancel-in-progress: true
1419

1520
jobs:

.github/workflows/release.yaml

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- release
7+
8+
permissions:
9+
id-token: write
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
extract-release-version:
15+
name: Extract release version
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version: ${{ steps.extract-release-version.outputs.result }}
19+
steps:
20+
- name: Extract release version
21+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
22+
id: extract-release-version
23+
with:
24+
result-encoding: string
25+
script: |
26+
const matches = `${{ github.event.head_commit.message }}`.match(/[0-9]+\.[0-9]+\.[0-9]+/) ?? []
27+
return matches.length > 0 ? matches[0] : ""
28+
29+
validate-version-format:
30+
name: Validate Version Format
31+
needs:
32+
- extract-release-version
33+
if: ${{ needs.extract-release-version.outputs.version != '' }}
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Validated
37+
run: echo "Releasing new version ${{ needs.extract-release-version.outputs.version }}"
38+
39+
unit-test:
40+
name: Unit Tests
41+
needs:
42+
- validate-version-format
43+
uses: ./.github/workflows/unit-test.yaml
44+
with:
45+
identifier: workflow-call-unit-test
46+
47+
build-on-minimum-supported-platforms:
48+
name: Build on minimum supported platforms
49+
needs:
50+
- validate-version-format
51+
uses: ./.github/workflows/build-on-minimum-supported-platform.yaml
52+
with:
53+
identifier: workflow-call-build-on-minimum-platforms
54+
55+
release:
56+
name: Release new version
57+
needs:
58+
- extract-release-version
59+
- unit-test
60+
- build-on-minimum-supported-platforms
61+
runs-on: ubuntu-latest
62+
env:
63+
RELEASE_VERSION: ${{ needs.extract-release-version.outputs.version }}
64+
steps:
65+
- name: Checkout Code
66+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
67+
with:
68+
ref: release
69+
fetch-depth: 0
70+
persist-credentials: false
71+
72+
- name: Configure AWS Credentials
73+
uses: aws-actions/configure-aws-credentials@v4
74+
with:
75+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
76+
role-session-name: ${{ format('{0}.release', github.run_id) }}
77+
aws-region: ${{ secrets.AWS_REGION }}
78+
79+
- name: Setup Github Token
80+
id: setup-pat
81+
env:
82+
DEPLOY_SECRET_ARN: ${{ secrets.DEPLOY_SECRET_ARN }}
83+
run: |
84+
PAT=$(aws secretsmanager get-secret-value \
85+
--secret-id "${DEPLOY_SECRET_ARN}" \
86+
| jq -r ".SecretString")
87+
echo "token=$PAT" >> $GITHUB_OUTPUT
88+
89+
- name: Create new version tag ${{ needs.extract-release-version.outputs.version }}
90+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
91+
with:
92+
script: |
93+
github.rest.git.createRef({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
ref: `refs/tags/${process.env.RELEASE_VERSION}`,
97+
sha: context.sha,
98+
force: true
99+
})
100+
101+
- name: Sync Back to Main
102+
env:
103+
PAT: ${{ steps.setup-pat.outputs.token }}
104+
GITHUB_USER: aws-amplify-ops
105+
GITHUB_EMAIL: aws-amplify-ops@amazon.com
106+
run: |
107+
git config user.name $GITHUB_USER
108+
git config user.email $GITHUB_EMAIL
109+
git push "https://${PAT}@github.com/${{ github.repository }}" HEAD:main

.github/workflows/unit-test.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ name: Unit Test
22

33
on:
44
workflow_dispatch:
5+
workflow_call:
6+
inputs:
7+
identifier:
8+
required: true
9+
type: string
510
pull_request:
611
branches:
712
- main
813

914
permissions: {}
1015

1116
concurrency:
12-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
17+
group: ${{ inputs.identifier || github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1318
cancel-in-progress: true
1419

1520
jobs:

0 commit comments

Comments
 (0)