Skip to content

Commit 359fed8

Browse files
authored
Merge pull request #440 from NHSDigital/feature/te-ELID-466-further-cicd-enhancements
(ELI-466) Enabling Auto preprod deployments
2 parents d3ea593 + 4ef1cf7 commit 359fed8

12 files changed

+748
-65
lines changed

.act/act_tests.mk

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ACT_IMAGE = ghcr.io/nhs-england-tools/github-runner-image:20230909-321fd1e-rt
2+
PREPROD_WORKFLOW = .github/workflows/cicd-4-preprod-deploy.yaml
3+
JOB = metadata # This can be changed depending on which part of the workflow we are testing
4+
5+
# Usage: make act EVENT=.act/auto_preprod_trigger_*.json TRIGGER_TYPE=workflow_run
6+
act-preprod-deploy:
7+
@if [ -z "$(EVENT)" ]; then \
8+
echo "Usage: make act EVENT=<path-to-event-json>"; \
9+
exit 1; \
10+
fi
11+
@echo "Running act with event file: $(EVENT)"
12+
ACT=true act \
13+
-W $(PREPROD_WORKFLOW) \
14+
--job $(JOB) \
15+
--eventpath $(EVENT) \
16+
-P ubuntu-latest=$(ACT_IMAGE) \
17+
-s GITHUB_TOKEN="$$GITHUB_TOKEN" \
18+
-s GH_TOKEN="$$GITHUB_TOKEN" \
19+
--env GITHUB_REPOSITORY="$$REPO" \
20+
--env TEST_WORKFLOW_ID=190123511 \
21+
--env GITHUB_EVENT_NAME=$(TRIGGER_TYPE)
22+
23+
24+
#act-dev-deploy:
25+
# @if [ -z "$(EVENT)" ]; then \
26+
# echo "Usage: make act EVENT=<path-to-event-json>"; \
27+
# exit 1; \
28+
# fi
29+
# @echo "Running act with event file: $(EVENT)"
30+
# ACT=true act \
31+
# -W $(WORKFLOW) \
32+
# --job $(JOB) \
33+
# --eventpath $(EVENT) \
34+
# -P ubuntu-latest=$(ACT_IMAGE) \
35+
# -s GITHUB_TOKEN="$$GITHUB_TOKEN" \
36+
# -s GH_TOKEN="$$GITHUB_TOKEN" \
37+
# --env GITHUB_REPOSITORY="$$REPO" \
38+
# --env DEV_WORKFLOW_ID=143714547 \
39+
# --env GITHUB_EVENT_NAME=$(TRIGGER_TYPE)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"event_name": "workflow_run",
3+
"action": "completed",
4+
"workflow": {
5+
"name": "Test stage",
6+
"path": ".github/workflows/cicd-3-test-deploy.yaml"
7+
},
8+
"workflow_run": {
9+
"id": 18556637650,
10+
"name": "Test stage",
11+
"event": "push",
12+
"status": "completed",
13+
"conclusion": "success",
14+
"head_branch": "main",
15+
"head_sha": "758a8d751ca1885695e9ac0766fcc0007dfb2995"
16+
},
17+
"repository": {
18+
"full_name": "NHSDigital/eligibility-signposting-api",
19+
"name": "eligibility-signposting-api",
20+
"owner": {"login": "NHSDigital"}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"event_name": "workflow_run",
3+
"action": "completed",
4+
"workflow": {
5+
"name": "Test stage",
6+
"path": ".github/workflows/cicd-3-test-deploy.yaml"
7+
},
8+
"workflow_run": {
9+
"id": 18556637650,
10+
"name": "Test stage",
11+
"event": "push",
12+
"status": "completed",
13+
"conclusion": "success",
14+
"head_branch": "main",
15+
"head_sha": "60d567d18eb4916e931d4bdd4e15b9639ef1a0a0"
16+
},
17+
"repository": {
18+
"full_name": "NHSDigital/eligibility-signposting-api",
19+
"name": "eligibility-signposting-api",
20+
"owner": {"login": "NHSDigital"}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"event_name": "workflow_run",
3+
"action": "completed",
4+
"workflow": {
5+
"name": "Test stage",
6+
"path": ".github/workflows/cicd-3-test-deploy.yaml"
7+
},
8+
"workflow_run": {
9+
"id": 18556637650,
10+
"name": "Test stage",
11+
"event": "push",
12+
"status": "completed",
13+
"conclusion": "success",
14+
"head_branch": "main",
15+
"head_sha": "b2675604f38a7c89f3cfe66f8b927b39d7ddedf6"
16+
},
17+
"repository": {
18+
"full_name": "NHSDigital/eligibility-signposting-api",
19+
"name": "eligibility-signposting-api",
20+
"owner": {"login": "NHSDigital"}
21+
}
22+
}

.act/manual_preprod_trigger.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"event_name": "workflow_dispatch",
3+
"ref": "refs/heads/main",
4+
"inputs": {
5+
"ref": "dev-20251015111601",
6+
"release_type": "minor",
7+
"reason": "manual promotion from test to pre-prod"
8+
},
9+
"repository": {
10+
"full_name": "NHSDigital/eligibility-signposting-api",
11+
"name": "eligibility-signposting-api",
12+
"owner": { "login": "NHSDigital" }
13+
},
14+
"sender": {
15+
"login": "tome"
16+
}
17+
}

.github/workflows/cicd-3-test-deploy.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
workflows: ["2. CD | Deploy to Dev"]
66
types: [completed]
77

8+
concurrency:
9+
group: test-deployments
10+
cancel-in-progress: false
11+
812
permissions:
913
contents: read
1014
id-token: write
@@ -52,11 +56,6 @@ jobs:
5256
id-token: write
5357
contents: read
5458
steps:
55-
- name: "Acquire deploy lock"
56-
uses: softprops/turnstyle@v3
57-
with:
58-
poll-interval-seconds: 10
59-
6059
- name: "Checkout same commit"
6160
uses: actions/checkout@v5
6261
with:
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: "4. CD | Deploy to PreProd"
2+
3+
concurrency:
4+
group: preprod-deploy
5+
cancel-in-progress: false
6+
7+
on:
8+
workflow_run:
9+
workflows: ["3. CD | Deploy to Test"]
10+
types: [completed]
11+
workflow_dispatch:
12+
inputs:
13+
ref:
14+
description: "dev-* tag to deploy to PreProd"
15+
required: true
16+
release_type:
17+
description: "rc|patch|minor|major"
18+
required: true
19+
default: "rc"
20+
reason:
21+
description: "Why are you doing a manual deployment?"
22+
required: true
23+
default: "To roll back to a previous commit"
24+
25+
permissions:
26+
contents: read
27+
actions: read
28+
29+
jobs:
30+
metadata:
31+
name: "Resolve ref + stale guard + release type"
32+
runs-on: ubuntu-latest
33+
outputs:
34+
ref: ${{ steps.resolver.outputs.this_ref }}
35+
this_sha: ${{ steps.resolver.outputs.this_sha }}
36+
latest_sha: ${{ steps.resolver.outputs.latest_test_sha }}
37+
release_type: ${{ steps.release_type.outputs.release_type }}
38+
39+
env:
40+
TEST_WORKFLOW_ID: "190123511" # this will need updating if the workflow is recreated
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
44+
steps:
45+
- name: Checkout (full history & tags)
46+
uses: actions/checkout@v4
47+
with: { fetch-depth: 0 }
48+
49+
- name: Force HTTPS remote for act
50+
if: env.ACT == 'true'
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
shell: bash
55+
run: |
56+
set -euo pipefail
57+
echo "::add-mask::${GITHUB_TOKEN}"
58+
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"
59+
git ls-remote --tags origin >/dev/null
60+
61+
- name: Debug event
62+
if: env.ACT == 'true'
63+
run: |
64+
echo "GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME}"
65+
echo "Payload:" && cat "$GITHUB_EVENT_PATH" || true
66+
67+
- name: Resolve THIS vs LATEST TEST + stale guard (auto only)
68+
id: resolver
69+
env:
70+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
EVENT_NAME: ${{ github.event_name }}
72+
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
73+
MANUAL_REF: ${{ github.event.inputs.ref }}
74+
WORKFLOW_NAME: "3. CD | Deploy to Test"
75+
BRANCH: "main"
76+
LIMIT: "100"
77+
run: python3 scripts/workflow/pre-release_resolver.py
78+
79+
- name: Resolve release_type (labels → default rc)
80+
id: release_type
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
BRANCH: "main"
84+
AGGREGATE: "true"
85+
THIS_SHA: ${{ steps.resolver.outputs.this_sha }}
86+
LATEST_TEST_SHA: ${{ steps.resolver.outputs.latest_test_sha }}
87+
MANUAL_RELEASE_TYPE: ${{ github.event.inputs.release_type }}
88+
run: python3 scripts/workflow/release_type_resolver.py
89+
90+
deploy:
91+
name: "Call base-deploy.yml (PreProd)"
92+
needs: [metadata]
93+
uses: ./.github/workflows/base-deploy.yml
94+
with:
95+
environment: preprod
96+
ref: ${{ needs.metadata.outputs.ref }}
97+
release_type: ${{ needs.metadata.outputs.release_type }}
98+
secrets: inherit

.github/workflows/cicd-4-preprod-deploy.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)