Skip to content

Commit be41061

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

14 files changed

Lines changed: 360 additions & 110 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.0
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.0
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

.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:
Lines changed: 127 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,138 @@
1-
name: Test Resources Post Merge
1+
name: GitHub Jobs Post Merge
2+
23
on:
34
push:
45
branches:
56
- main
67
paths:
7-
- "test-resources/**"
8-
- ".github/workflows/job_push-docker-image.yml"
9-
- ".github/workflows/job_upload-sam-artifact.yml"
10-
- ".github/workflows/test-resources-post-merge.yml"
11-
- "!test-resources/**/*.md"
12-
- "!test-resources/**/*.png"
8+
- ".github/workflows/job_**"
139
workflow_dispatch:
1410

1511
permissions:
16-
contents: read
12+
contents: write
1713
id-token: write
1814

19-
defaults:
20-
run:
21-
shell: bash
22-
working-directory: ./test-resources
23-
2415
jobs:
25-
ci-checks:
26-
name: Pre-deployment
27-
uses:
28-
./.github/workflows/job_ci-checks.yml
29-
with:
30-
WORKING_DIRECTORY: test-resources
31-
32-
run-test-suite:
33-
name: Pre-deployment
34-
needs: ci-checks
35-
uses:
36-
./.github/workflows/job_test-suite.yml
37-
with:
38-
SONARQUBE_CONTINUE_ON_ERROR: true
39-
WORKING_DIRECTORY: test-resources
40-
secrets: inherit
41-
42-
push-docker-image-dev:
43-
name: Dev
44-
needs:
45-
- ci-checks
46-
- run-test-suite
47-
uses:
48-
./.github/workflows/job_push-docker-image.yml
49-
with:
50-
WORKING_DIRECTORY: test-resources
51-
secrets:
52-
CONTAINER_SIGN_KMS_KEY: ${{ secrets.DEV_CONTAINER_SIGN_KMS_KEY }}
53-
GH_ACTIONS_ROLE_ARN: ${{ secrets.TEST_RESOURCES_DEV_GH_ACTIONS_ROLE_ARN }}
54-
TEST_IMAGE_REPOSITORY_URI: ${{ secrets.TEST_RESOURCES_DEV_TEST_IMAGE_REPOSITORY_URI }}
55-
56-
upload-sam-artifact-dev:
57-
name: Dev
58-
needs: push-docker-image-dev
59-
uses:
60-
./.github/workflows/job_upload-sam-artifact.yml
61-
with:
62-
WORKING_DIRECTORY: test-resources
63-
secrets:
64-
ARTIFACT_BUCKET: ${{ secrets.TEST_RESOURCES_DEV_ARTIFACT_BUCKET }}
65-
GH_ACTIONS_ROLE_ARN: ${{ secrets.TEST_RESOURCES_DEV_GH_ACTIONS_ROLE_ARN }}
66-
SIGNING_PROFILE_NAME: ${{ secrets.DEV_SIGNING_PROFILE_NAME }}
67-
68-
push-docker-image-build:
69-
name: Build
70-
needs:
71-
- ci-checks
72-
- run-test-suite
73-
uses:
74-
./.github/workflows/job_push-docker-image.yml
75-
with:
76-
WORKING_DIRECTORY: test-resources
77-
secrets:
78-
CONTAINER_SIGN_KMS_KEY: ${{ secrets.BUILD_CONTAINER_SIGN_KMS_KEY }}
79-
GH_ACTIONS_ROLE_ARN: ${{ secrets.TEST_RESOURCES_BUILD_GH_ACTIONS_ROLE_ARN }}
80-
TEST_IMAGE_REPOSITORY_URI: ${{ secrets.TEST_RESOURCES_BUILD_TEST_IMAGE_REPOSITORY_URI }}
81-
82-
upload-sam-artifact-build:
83-
name: Build
84-
needs: push-docker-image-build
85-
uses:
86-
./.github/workflows/job_upload-sam-artifact.yml
87-
with:
88-
WORKING_DIRECTORY: test-resources
89-
secrets:
90-
ARTIFACT_BUCKET: ${{ secrets.TEST_RESOURCES_BUILD_ARTIFACT_BUCKET }}
91-
GH_ACTIONS_ROLE_ARN: ${{ secrets.TEST_RESOURCES_BUILD_GH_ACTIONS_ROLE_ARN }}
92-
SIGNING_PROFILE_NAME: ${{ secrets.BUILD_SIGNING_PROFILE_NAME }}
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"

0 commit comments

Comments
 (0)