Skip to content

Commit b99099b

Browse files
DCMAW-12245: github action versioning spike
1 parent b3e84ef commit b99099b

15 files changed

Lines changed: 386 additions & 6 deletions

.github/workflows/backend-api-post-merge.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ jobs:
2626
ci-checks:
2727
name: Pre-deployment
2828
uses:
29-
./.github/workflows/job_ci-checks.yml
29+
govuk-one-login/mobile-id-check-async/.github/workflows/jobs_ci-checks.yml@ci-checks/v1.0.0
3030
with:
3131
PRIVATE_PACKAGES_REQUIRED: true
3232
WORKING_DIRECTORY: backend-api
3333

3434
run-test-suite:
3535
name: Pre-deployment
3636
uses:
37-
./.github/workflows/job_test-suite.yml
37+
govuk-one-login/mobile-id-check-async/.github/workflows/jobs_test-suite.yml@test-suite/v1.0.0
3838
with:
3939
PRIVATE_PACKAGES_REQUIRED: true
4040
RUN_PACT_TESTS: true

.github/workflows/backend-api-pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
name: CI checks
2828
if: github.event.pull_request.draft == false
2929
uses:
30-
./.github/workflows/job_ci-checks.yml
30+
govuk-one-login/mobile-id-check-async/.github/workflows/jobs_ci-checks.yml@ci-checks/v1.0.1
3131
with:
3232
PRIVATE_PACKAGES_REQUIRED: true
3333
WORKING_DIRECTORY: backend-api
@@ -36,7 +36,7 @@ jobs:
3636
name: Run test suite
3737
needs: ci-checks
3838
uses:
39-
./.github/workflows/job_test-suite.yml
39+
govuk-one-login/mobile-id-check-async/.github/workflows/jobs_test-suite.yml@test-suite/v1.0.1
4040
with:
4141
PRIVATE_PACKAGES_REQUIRED: true
4242
RUN_PACT_TESTS: true

.github/workflows/helper-scripts-pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ jobs:
2222
name: CI checks
2323
if: github.event.pull_request.draft == false
2424
uses:
25-
./.github/workflows/job_ci-checks.yml
25+
govuk-one-login/mobile-id-check-async/.github/workflows/jobs_ci-checks.yml@ci-checks/v1.0.0
2626
with:
2727
WORKING_DIRECTORY: helper-scripts
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Initialise New GitHub Actions Job
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
JOB_NAME:
7+
description: The Name of the New Job
8+
type: string
9+
10+
jobs:
11+
create-tag:
12+
runs-on: ubuntu-24.04
13+
steps:
14+
- name: Create Tag v0.0.1
15+
run: |
16+
$job_name=${{ inputs.JOB_NAME }}
17+
18+
git tag $job_name/v0.0.1
19+
git push origin $job_name/v0.0.1
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: GitHub Jobs Post Merge
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- ".github/workflows/job_**"
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
id-token: write
14+
15+
jobs:
16+
get-file-names:
17+
name: Get Names of Files Changed
18+
runs-on: ubuntu-24.04
19+
env:
20+
SAM_CLI_TELEMETRY: 0
21+
defaults:
22+
run:
23+
shell: bash
24+
working-directory: .
25+
outputs:
26+
FILE_NAMES: ${{ steps.get-files.outputs.NAMES }}
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
with:
31+
submodules: true
32+
fetch-depth: 0
33+
34+
# This is ugly but can't get anything else to work
35+
- name: Get File Names
36+
id: get-files
37+
run: |
38+
files=$( git diff origin/main --name-only -- ./.github/workflows/job_** )
39+
40+
JSON="["
41+
for file in ${files[@]}; do
42+
echo $file
43+
JSONline="\"$file\","
44+
if [[ "$JSON" != *"$JSONline"* ]]; then
45+
JSON="$JSON$JSONline"
46+
fi
47+
done
48+
49+
if [[ $JSON == *, ]]; then
50+
JSON="${JSON%?}"
51+
fi
52+
JSON="$JSON]"
53+
54+
echo $JSON
55+
echo "NAMES=$( echo "$JSON" )" >> $GITHUB_OUTPUT
56+
57+
create-tags:
58+
name: Validate Versions and Create Tags
59+
runs-on: ubuntu-24.04
60+
needs: get-file-names
61+
strategy:
62+
matrix:
63+
file_name: ${{ fromJSON(needs.get-file-names.outputs.FILE_NAMES) }}
64+
env:
65+
SAM_CLI_TELEMETRY: 0
66+
FILE_NAME: ${{ matrix.file_name }}
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
defaults:
69+
run:
70+
shell: bash
71+
working-directory: jobs
72+
steps:
73+
- name: Checkout Repository
74+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
75+
with:
76+
submodules: true
77+
fetch-depth: 0
78+
79+
- name: Setup NodeJS
80+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
81+
with:
82+
cache: npm
83+
cache-dependency-path: jobs/package-lock.json
84+
node-version-file: jobs/.nvmrc
85+
86+
- name: Install Dependencies
87+
run: |
88+
npm clean-install
89+
90+
- name: Validate Job Name
91+
id: job-name
92+
run: |
93+
name=$( yq .description ../$FILE_NAME | jq .name | tr -d '"' )
94+
95+
if [[ $FILE_NAME == ".github/workflows/job_$name" ]]; then
96+
echo "Error: Job name does not match file name."
97+
exit 1
98+
fi
99+
100+
if [[ "$name" =~ ^[a-z0-9-]+$ ]]; then
101+
echo "Valid job name."
102+
echo "NAME=$name" >> $GITHUB_OUTPUT
103+
else
104+
echo "Error: Invalid job name."
105+
exit 1
106+
fi
107+
108+
- name: Get Version
109+
id: get-version
110+
run: |
111+
version=$( yq .description ../$FILE_NAME | jq .version | tr -d '"' )
112+
echo "VERSION=$version" >> $GITHUB_OUTPUT
113+
114+
- name: Validate Version
115+
run: |
116+
npm run validate-version $FILE_NAME
117+
118+
- name: Get Message
119+
id: get-message
120+
run: |
121+
message=$( yq .description ../$FILE_NAME | jq .message )
122+
echo "MESSAGE=$message" >> $GITHUB_OUTPUT
123+
124+
- name: Create and Push Tag
125+
run: |
126+
job_name=${{ steps.job-name.outputs.NAME }}
127+
new_version=${{ steps.get-version.outputs.VERSION }}
128+
129+
git tag $job_name/$new_version
130+
git push origin $job_name/$new_version
131+
132+
- name: Create GitHub Release
133+
run: |
134+
job_name=${{ steps.job-name.outputs.NAME }}
135+
message=${{ steps.get-message.outputs.MESSAGE }}
136+
new_version=${{ steps.get-version.outputs.VERSION }}
137+
138+
gh release create $job_name/$new_version --latest=false --notes "$message"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: GitHub Jobs Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types:
8+
- opened
9+
- reopened
10+
- ready_for_review
11+
- synchronize
12+
paths:
13+
- ".github/workflows/job_**"
14+
15+
workflow_dispatch:
16+
17+
permissions:
18+
contents: write
19+
id-token: write
20+
21+
jobs:
22+
get-file-names:
23+
name: Get Names of Files Changed
24+
runs-on: ubuntu-24.04
25+
env:
26+
SAM_CLI_TELEMETRY: 0
27+
defaults:
28+
run:
29+
shell: bash
30+
working-directory: .
31+
outputs:
32+
FILE_NAMES: ${{ steps.get-files.outputs.NAMES }}
33+
steps:
34+
- name: Checkout Repository
35+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
36+
with:
37+
submodules: true
38+
fetch-depth: 0
39+
40+
# This is ugly but can't get anything else to work
41+
- name: Get File Names
42+
id: get-files
43+
run: |
44+
files=$( git diff origin/main --name-only -- ./.github/workflows/job_** )
45+
46+
JSON="["
47+
for file in ${files[@]}; do
48+
echo $file
49+
JSONline="\"$file\","
50+
if [[ "$JSON" != *"$JSONline"* ]]; then
51+
JSON="$JSON$JSONline"
52+
fi
53+
done
54+
55+
if [[ $JSON == *, ]]; then
56+
JSON="${JSON%?}"
57+
fi
58+
JSON="$JSON]"
59+
60+
echo $JSON
61+
echo "NAMES=$( echo "$JSON" )" >> $GITHUB_OUTPUT
62+
63+
create-tags:
64+
name: Validate Versions and Create Tags
65+
runs-on: ubuntu-24.04
66+
needs: get-file-names
67+
strategy:
68+
matrix:
69+
file_name: ${{ fromJSON(needs.get-file-names.outputs.FILE_NAMES) }}
70+
env:
71+
SAM_CLI_TELEMETRY: 0
72+
FILE_NAME: ${{ matrix.file_name }}
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
defaults:
75+
run:
76+
shell: bash
77+
working-directory: jobs
78+
steps:
79+
- name: Checkout Repository
80+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
81+
with:
82+
submodules: true
83+
fetch-depth: 0
84+
85+
- name: Setup NodeJS
86+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
87+
with:
88+
cache: npm
89+
cache-dependency-path: jobs/package-lock.json
90+
node-version-file: jobs/.nvmrc
91+
92+
- name: Install Dependencies
93+
run: |
94+
npm clean-install
95+
96+
- name: Validate Job Name
97+
id: job-name
98+
run: |
99+
name=$( yq .description ../$FILE_NAME | jq .name | tr -d '"' )
100+
101+
if [[ $FILE_NAME == ".github/workflows/job_$name" ]]; then
102+
echo "Error: Job name does not match file name."
103+
exit 1
104+
fi
105+
106+
if [[ "$name" =~ ^[a-z0-9-]+$ ]]; then
107+
echo "Valid job name."
108+
echo "NAME=$name" >> $GITHUB_OUTPUT
109+
else
110+
echo "Error: Invalid job name."
111+
exit 1
112+
fi
113+
114+
- name: Validate Version
115+
run: |
116+
npm run validate-version $FILE_NAME
117+

.github/workflows/job_ci-checks.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: CI Checks
22

3+
description: {
4+
"name": "ci-checks",
5+
"version": "v1.0.0",
6+
"message":
7+
"This update adds versioning to the ci-checks job."
8+
}
9+
310
on:
411
workflow_call:
512
inputs:

.github/workflows/job_push-docker-image.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: Build, Push, Sign and Tag Test Image
22

3+
description: {
4+
"name": "push-docker-image",
5+
"version": "v1.0.0",
6+
"message":
7+
"This update adds versioning to the push-docker-image job."
8+
}
9+
310
on:
411
workflow_call:
512
inputs:

.github/workflows/job_test-suite.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: Run Test Suite
22

3+
description: {
4+
"name": "test-suite",
5+
"version": "v1.0.0",
6+
"message":
7+
"This update adds versioning to the test-suite job."
8+
}
9+
310
on:
411
workflow_call:
512
inputs:

.github/workflows/job_upload-sam-artifact.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: Validate, Build, and Upload Artifact to S3
22

3+
description: {
4+
"name": "upload-sam-artifact",
5+
"version": "v1.0.0",
6+
"message":
7+
"This update adds versioning to the upload-sam-artifact job."
8+
}
9+
310
on:
411
workflow_call:
512
inputs:

0 commit comments

Comments
 (0)