Skip to content

Commit d57aba9

Browse files
committed
Split actions
1 parent b26cdf5 commit d57aba9

3 files changed

Lines changed: 120 additions & 91 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Acceptance tests - component
2+
description: "Run component acceptance tests for this repo"
3+
4+
inputs:
5+
testType:
6+
description: Type of test to run
7+
required: true
8+
9+
targetEnvironment:
10+
description: Name of the environment under test
11+
required: true
12+
13+
targetComponent:
14+
description: Name of the component under test
15+
required: true
16+
17+
runs:
18+
using: "composite"
19+
20+
steps:
21+
22+
- name: Fetch terraform output
23+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
24+
with:
25+
name: terraform-output-${{ inputs.targetComponent }}
26+
27+
- name: Get Node version
28+
id: nodejs_version
29+
shell: bash
30+
run: |
31+
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
32+
33+
- name: Repo setup
34+
uses: ./.github/actions/node-install
35+
with:
36+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
37+
38+
- name: Run test - ${{ inputs.testType }}
39+
shell: bash
40+
env:
41+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
42+
run: |
43+
make test-${{ inputs.testType }}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Acceptance tests - e2e
2+
description: "Run e2e acceptance tests for this repo"
3+
4+
inputs:
5+
targetEnvironment:
6+
description: Name of the environment under test
7+
required: true
8+
9+
runs:
10+
using: "composite"
11+
12+
steps:
13+
14+
- name: Determine if proxy has been deployed
15+
id: check_proxy_deployed
16+
env:
17+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
18+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
19+
shell: bash
20+
run: |
21+
if [[ -z "$PR_NUMBER" ]]; then
22+
echo "No pull request detected; proxy was deployed."
23+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
24+
exit 0
25+
fi
26+
27+
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
28+
29+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
30+
echo "Labels on PR #$PR_NUMBER: $labels"
31+
32+
if echo "$labels" | grep -Fxq 'deploy-proxy'; then
33+
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "proxy_deployed=false" >> $GITHUB_OUTPUT
36+
fi
37+
38+
- name: Install poetry and e2e test dependencies
39+
if: ${{ steps.check_proxy_deployed.outputs.proxy_deployed == 'true' }}
40+
shell: bash
41+
run: |
42+
pipx install poetry
43+
cd tests/e2e-tests && poetry install
44+
45+
- name: Run tests
46+
if: ${{ steps.check_proxy_deployed.outputs.proxy_deployed == 'true' }}
47+
shell: bash
48+
env:
49+
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
50+
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
51+
run: |
52+
PR_NUMBER=""
53+
echo "$SUPPLIER_API_PRIVATE_KEY" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
54+
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
55+
BASE_PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
56+
57+
export API_ENVIRONMENT=internal-dev
58+
if [[ -z "$PR_NUMBER" ]]; then
59+
export PROXY_NAME="${BASE_PROXY_NAME}"
60+
export NON_PROD_API_KEY="${APIM_API_KEY}"
61+
else
62+
export PROXY_NAME="${BASE_PROXY_NAME}-PR-${PR_NUMBER}"
63+
export NON_PROD_API_KEY="${APIM_PR_API_KEY}"
64+
fi
65+
66+
export STATUS_ENDPOINT_API_KEY="${APIM_STATUS_API_KEY}"
67+
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
68+
make .internal-dev-test

.github/actions/acceptance-tests/action.yml

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -23,99 +23,17 @@ runs:
2323
using: "composite"
2424

2525
steps:
26-
- name: Fetch terraform output
27-
if: ${{ inputs.testType != 'e2e' }}
28-
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
29-
with:
30-
name: terraform-output-${{ inputs.targetComponent }}
3126

32-
- name: Get Node version
27+
- name: Run component tests
3328
if: ${{ inputs.testType != 'e2e' }}
34-
id: nodejs_version
35-
shell: bash
36-
run: |
37-
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
38-
39-
- name: "Repo setup"
40-
uses: ./.github/actions/node-install
29+
uses: ./.github/actions/acceptance-tests-component
4130
with:
42-
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
43-
44-
- name: "Set PR NUMBER"
45-
if: ${{ inputs.testType == 'e2e' }}
46-
id: set_pr_number
47-
shell: bash
48-
run: |
49-
env="${{ inputs.targetEnvironment }}"
50-
if [[ "$env" == main ]]; then
51-
echo "pr_number=" >> $GITHUB_OUTPUT
52-
elif [[ "$env" == pr* ]]; then
53-
echo "pr_number=${env#pr}" >> $GITHUB_OUTPUT
54-
else
55-
echo "pr_number=$env" >> $GITHUB_OUTPUT
56-
fi
57-
58-
- name: Install poetry and e2e test dependencies
59-
if: ${{ inputs.testType == 'e2e' }}
60-
shell: bash
61-
run: |
62-
pipx install poetry
63-
cd tests/e2e-tests && poetry install
31+
testType: ${{ inputs.testType }}
32+
targetEnvironment: ${{ inputs.targetEnvironment }}
33+
targetComponent: ${{ inputs.targetComponent }}
6434

65-
- name: "Determine if proxy has been deployed"
35+
- name: Run e2e tests
6636
if: ${{ inputs.testType == 'e2e' }}
67-
id: check_proxy_deployed
68-
env:
69-
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
70-
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
71-
shell: bash
72-
run: |
73-
if [[ -z "$PR_NUMBER" ]]; then
74-
echo "No pull request detected; proxy was deployed."
75-
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
76-
exit 0
77-
fi
78-
79-
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
80-
81-
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
82-
echo "Labels on PR #$PR_NUMBER: $labels"
83-
84-
if echo "$labels" | grep -Fxq 'deploy-proxy'; then
85-
echo "proxy_deployed=true" >> $GITHUB_OUTPUT
86-
else
87-
echo "proxy_deployed=false" >> $GITHUB_OUTPUT
88-
fi
89-
90-
- name: Run test - ${{ inputs.testType }}
91-
if: ${{ inputs.testType != 'e2e'}}
92-
shell: bash
93-
env:
94-
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
95-
run: |
96-
make test-${{ inputs.testType }}
97-
98-
- name: Run test - e2e
99-
if: ${{ inputs.testType == 'e2e' && steps.check_proxy_deployed.outputs.proxy_deployed == 'true'}}
100-
shell: bash
101-
env:
102-
TARGET_ENVIRONMENT: ${{ inputs.targetEnvironment }}
103-
PR_NUMBER: ${{ steps.set_pr_number.outputs.pr_number }}
104-
run: |
105-
PR_NUMBER=""
106-
echo "$SUPPLIER_API_PRIVATE_KEY" > "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
107-
chmod 600 "${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
108-
BASE_PROXY_NAME=nhs-notify-supplier--internal-dev--nhs-notify-supplier
109-
110-
export API_ENVIRONMENT=internal-dev
111-
if [[ -z "$PR_NUMBER" ]]; then
112-
export PROXY_NAME="${BASE_PROXY_NAME}"
113-
export NON_PROD_API_KEY="${APIM_API_KEY}"
114-
else
115-
export PROXY_NAME="${BASE_PROXY_NAME}-PR-${PR_NUMBER}"
116-
export NON_PROD_API_KEY="${APIM_PR_API_KEY}"
117-
fi
118-
119-
export STATUS_ENDPOINT_API_KEY="${APIM_STATUS_API_KEY}"
120-
export NON_PROD_PRIVATE_KEY="${GITHUB_WORKSPACE}/internal-dev-test-1.pem"
121-
make .internal-dev-test
37+
uses: ./.github/actions/acceptance-tests-e2e
38+
with:
39+
targetEnvironment: ${{ inputs.targetEnvironment }}

0 commit comments

Comments
 (0)