Skip to content

Commit 4f9df05

Browse files
authored
CCM-14502 Make Proxy build optional for dynamic envs (#415)
* Refactor environment calculation * Conditionally deploy proxy * Run E2E tests if proxy deployed * Simplification following peer review * Disable E2E tests * Fix vulnerabilities
1 parent 30d3ac3 commit 4f9df05

7 files changed

Lines changed: 604 additions & 542 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: E2E tests
2+
description: "Run end-to-end tests for this repo"
3+
4+
runs:
5+
using: "composite"
6+
7+
steps:
8+
- name: Install poetry and e2e test dependencies
9+
shell: bash
10+
run: |
11+
pipx install poetry
12+
cd tests/e2e-tests && poetry install
13+
14+
- name: Run e2e tests
15+
shell: bash
16+
run: |
17+
echo "$INTERNAL_DEV_TEST_PEM" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
18+
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
19+
export PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
20+
export API_ENVIRONMENT=internal-dev
21+
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
22+
make .internal-dev-test

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }}
3030
pr_number: ${{ steps.pr_exists.outputs.pr_number }}
3131
skip_trivy_package: ${{ steps.skip_trivy.outputs.skip_trivy_package }}
32+
deploy_proxy: ${{ steps.deploy_proxy.outputs.deploy_proxy }}
3233
steps:
3334
- name: "Checkout code"
3435
uses: actions/checkout@v5
@@ -87,6 +88,26 @@ jobs:
8788
else
8889
echo "skip_trivy_package=false" >> $GITHUB_OUTPUT
8990
fi
91+
- name: "Determine if proxy should be deployed"
92+
id: deploy_proxy
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }}
96+
run: |
97+
if [[ -z "$PR_NUMBER" ]]; then
98+
echo "No pull request detected; proxy deployment will run."
99+
echo "deploy_proxy=true" >> $GITHUB_OUTPUT
100+
exit 0
101+
fi
102+
103+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
104+
echo "Labels on PR #$PR_NUMBER: $labels"
105+
106+
if echo "$labels" | grep -Fxq 'deploy-proxy'; then
107+
echo "deploy_proxy=true" >> $GITHUB_OUTPUT
108+
else
109+
echo "deploy_proxy=false" >> $GITHUB_OUTPUT
110+
fi
90111
- name: "List variables"
91112
run: |
92113
export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}"
@@ -141,6 +162,7 @@ jobs:
141162
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
142163
version: "${{ needs.metadata.outputs.version }}"
143164
pr_number: "${{ needs.metadata.outputs.pr_number }}"
165+
deploy_proxy: "${{ needs.metadata.outputs.deploy_proxy }}"
144166
secrets: inherit
145167
acceptance-stage: # Recommended maximum execution time is 10 minutes
146168
name: "Acceptance stage"
@@ -156,6 +178,7 @@ jobs:
156178
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
157179
version: "${{ needs.metadata.outputs.version }}"
158180
pr_number: ${{ needs.metadata.outputs.pr_number }}
181+
proxy_deployed: "${{ needs.metadata.outputs.deploy_proxy }}"
159182
secrets: inherit
160183
publish-stage: # Recommended maximum execution time is 10 minutes
161184
name: "Publish stage"

.github/workflows/stage-3-build.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ on:
3535
description: "PR Number if it exists"
3636
required: false
3737
type: string
38+
deploy_proxy:
39+
description: "True if the APIM proxy should be deployed"
40+
required: true
41+
type: string
3842

3943
permissions:
4044
id-token: write # This is required for requesting the JWT
@@ -133,9 +137,13 @@ jobs:
133137
pr-create-dynamic-environment:
134138
name: Create Dynamic Environment
135139
runs-on: ubuntu-latest
136-
if: inputs.pr_number != ''
140+
outputs:
141+
environment_name: ${{ steps.set-environment.outputs.environment_name }}
137142
steps:
138143
- uses: actions/checkout@v5
144+
- name: Set environment name
145+
id: set-environment
146+
run: echo "environment_name=${{ inputs.pr_number != '' && format('pr{0}', inputs.pr_number) || 'main' }}" >> $GITHUB_OUTPUT
139147
- name: Trigger dynamic environment creation
140148
env:
141149
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
@@ -148,7 +156,7 @@ jobs:
148156
--infraRepoName "$(echo ${{ github.repository }} | cut -d'/' -f2)" \
149157
--releaseVersion ${{ github.head_ref || github.ref_name }} \
150158
--targetWorkflow "dispatch-deploy-dynamic-env.yaml" \
151-
--targetEnvironment "pr${PR_NUMBER}" \
159+
--targetEnvironment "${{ steps.set-environment.outputs.environment_name }}" \
152160
--targetComponent "api" \
153161
--targetAccountGroup "nhs-notify-supplier-api-dev" \
154162
--terraformAction "apply" \
@@ -157,12 +165,11 @@ jobs:
157165
artefact-proxies:
158166
name: "Build proxies"
159167
runs-on: ubuntu-latest
160-
if: inputs.pr_number != ''
168+
if: inputs.deploy_proxy == 'true'
161169
needs: [artefact-oas-spec-sandbox, pr-create-dynamic-environment]
162170
timeout-minutes: 10
163171
env:
164172
PROXYGEN_API_NAME: nhs-notify-supplier
165-
PR_NUMBER: ${{ inputs.pr_number }}
166173
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
167174
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
168175
steps:
@@ -172,7 +179,7 @@ jobs:
172179
uses: ./.github/actions/build-proxies
173180
with:
174181
version: "${{ inputs.version }}"
175-
environment: ${{ inputs.pr_number != '' && format('pr{0}', inputs.pr_number) || 'main' }}
182+
environment: ${{ needs.pr-create-dynamic-environment.outputs.environment_name }}
176183
apimEnv: "internal-dev-sandbox"
177184
runId: "${{ github.run_id }}"
178185
buildSandbox: true

.github/workflows/stage-4-acceptance.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ on:
3434
pr_number:
3535
required: true
3636
type: string
37+
proxy_deployed:
38+
description: "True if the APIM proxy was deployed"
39+
required: true
40+
type: string
3741

3842
permissions:
3943
id-token: write
@@ -77,3 +81,20 @@ jobs:
7781
--targetEnvironment "$ENVIRONMENT" \
7882
--targetAccountGroup "nhs-notify-supplier-api-dev" \
7983
--targetComponent "api"
84+
85+
run-e2e-tests:
86+
name: Run End-to-End Tests
87+
runs-on: ubuntu-latest
88+
if: inputs.proxy_deployed == 'true'
89+
steps:
90+
- uses: actions/checkout@v5.0.0
91+
92+
- name: "Run e2e tests"
93+
#uses: ./.github/actions/e2e-tests
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
NON_PROD_API_KEY: ${{ secrets.NON_PROD_API_KEY }}
97+
INTERNAL_DEV_TEST_PEM: ${{ secrets.INTERNAL_DEV_TEST_PEM }}
98+
shell: bash
99+
run: |
100+
echo "E2E tests are currently disabled. See CCM-14778"

0 commit comments

Comments
 (0)