Skip to content

Commit 2162ff5

Browse files
merge with main
2 parents f6c2d06 + 4489592 commit 2162ff5

37 files changed

Lines changed: 7965 additions & 9668 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- [ ] I have added tests to cover my changes
2626
- [ ] I have updated the documentation accordingly
2727
- [ ] This PR is a result of pair or mob programming
28+
- [ ] If I have used the 'skip-trivy-package' label I have done so responsibly and in the knowledge that this is being fixed as part of a separate ticket/PR.
2829

2930
---
3031

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Acceptance tests
2+
description: "Run 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+
targetAccountGroup:
14+
description: Name of the account group under test
15+
default: nhs-notify-template-management-dev
16+
required: true
17+
18+
targetComponent:
19+
description: Name of the component under test
20+
required: true
21+
22+
runs:
23+
using: "composite"
24+
25+
steps:
26+
- name: Fetch terraform output
27+
uses: actions/download-artifact@v5
28+
with:
29+
name: terraform-output-${{ inputs.targetComponent }}
30+
31+
- name: Get Node version
32+
id: nodejs_version
33+
shell: bash
34+
run: |
35+
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
36+
37+
- name: "Repo setup"
38+
uses: ./.github/actions/node-install
39+
with:
40+
node-version: ${{ steps.nodejs_version.outputs.nodejs_version }}
41+
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
42+
43+
- name: "Set PR NUMBER"
44+
shell: bash
45+
run: |
46+
echo "PR_NUMBER=${{ inputs.targetEnvironment }}" >> $GITHUB_ENV
47+
48+
- name: Run test - ${{ inputs.testType }}
49+
shell: bash
50+
run: |
51+
make test-${{ inputs.testType }}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: "Build OAS Spec"
2+
description: "Build OAS Spec"
3+
4+
inputs:
5+
version:
6+
description: "Version number"
7+
required: true
8+
apimEnv:
9+
description: "APIM environment"
10+
required: true
11+
buildSandbox:
12+
description: "Whether to build the sandbox OAS spec"
13+
required: false
14+
default: false
15+
nodejs_version:
16+
description: "Node.js version, set by the CI/CD pipeline workflow"
17+
required: true
18+
NODE_AUTH_TOKEN:
19+
description: "Token for access to github package registry"
20+
required: true
21+
22+
runs:
23+
using: composite
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ inputs.nodejs_version }}
31+
registry-url: 'https://npm.pkg.github.com'
32+
33+
- name: "Cache node_modules"
34+
uses: actions/cache@v4
35+
with:
36+
path: |
37+
**/node_modules
38+
key: ${{ runner.os }}-node-${{ inputs.nodejs_version }}-${{ hashFiles('**/package-lock.json') }}
39+
restore-keys: |
40+
${{ runner.os }}-node-${{ inputs.nodejs_version }}-
41+
42+
- name: Npm install
43+
working-directory: .
44+
env:
45+
NODE_AUTH_TOKEN: ${{ inputs.NODE_AUTH_TOKEN }}
46+
run: npm ci
47+
shell: bash
48+
49+
- name: Build ${{ inputs.apimEnv }} oas
50+
working-directory: .
51+
env:
52+
APIM_ENV: ${{ inputs.apimEnv }}
53+
shell: bash
54+
run: |
55+
if [ ${{ env.APIM_ENV }} == "internal-dev-sandbox" ] && [ ${{ inputs.buildSandbox }} == true ]
56+
then
57+
echo "Building sandbox OAS spec"
58+
make build-json-oas-spec APIM_ENV=sandbox
59+
else
60+
echo "Building env specific OAS spec"
61+
make build-yml-oas-spec APIM_ENV=${{ env.APIM_ENV }}
62+
fi
63+
64+
- name: Upload API OAS specification artifact
65+
uses: actions/upload-artifact@v4
66+
with:
67+
path: "build"
68+
name: api-oas-specification-${{ inputs.apimEnv }}${{ inputs.version != '' && format('-{0}', inputs.version) || '' }}

.github/actions/build-proxies/action.yml

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
releaseVersion:
99
description: "Release, tag, branch, or commit ID to be used for deployment"
1010
required: true
11+
isRelease:
12+
description: "True if releaseVersion is a release tag (if set, downloads from release assets instead of workflow artifacts)"
13+
required: false
14+
default: false
1115
environment:
1216
description: "Deployment environment"
1317
required: true
@@ -25,39 +29,33 @@ inputs:
2529
description: "Name of the Component to deploy"
2630
required: true
2731
default: 'api'
28-
nodejs_version:
29-
description: "Node.js version, set by the CI/CD pipeline workflow"
30-
required: true
31-
NODE_AUTH_TOKEN:
32-
description: "Token for access to github package registry"
33-
required: true
3432

3533
runs:
3634
using: composite
3735

3836
steps:
39-
- name: Checkout
40-
uses: actions/checkout@v4
41-
- uses: actions/setup-node@v4
37+
- name: Download OAS Spec artifact from workflow
38+
if: ${{ inputs.isRelease == 'false' }}
39+
uses: actions/download-artifact@v4
4240
with:
43-
node-version: ${{ inputs.nodejs_version }}
44-
registry-url: 'https://npm.pkg.github.com'
45-
46-
- name: "Cache node_modules"
47-
uses: actions/cache@v4
48-
with:
49-
path: |
50-
**/node_modules
51-
key: ${{ runner.os }}-node-${{ inputs.nodejs_version }}-${{ hashFiles('**/package-lock.json') }}
52-
restore-keys: |
53-
${{ runner.os }}-node-${{ inputs.nodejs_version }}-
41+
name: api-oas-specification-${{ inputs.apimEnv }}${{ inputs.version != '' && format('-{0}', inputs.version) || '' }}
42+
path: ./build
5443

55-
- name: Npm install
56-
working-directory: .
57-
env:
58-
NODE_AUTH_TOKEN: ${{ inputs.NODE_AUTH_TOKEN }}
59-
run: npm ci
44+
- name: Download OAS Spec artifact from release
45+
if: ${{ inputs.isRelease == 'true' }}
6046
shell: bash
47+
run: |
48+
mkdir ./build
49+
ASSET_PATTERN="api-oas-specification-${{ inputs.apimEnv }}-*.zip"
50+
gh release download "${{ inputs.releaseVersion }}" \
51+
--pattern "$ASSET_PATTERN" \
52+
--dir ./build
53+
# Unzip the downloaded file (there should be exactly one match)
54+
ASSET_FILE=$(ls ./build/api-oas-specification-${{ inputs.apimEnv }}-*.zip)
55+
unzip "$ASSET_FILE" -d ./build
56+
rm "$ASSET_FILE"
57+
env:
58+
GH_TOKEN: ${{ github.token }}
6159

6260
- name: Setup Proxy Name and target
6361
shell: bash
@@ -87,21 +85,10 @@ runs:
8785
echo "MTLS_NAME=notify-supplier-mtls-pr$PR_NUMBER" >> $GITHUB_ENV
8886
fi
8987
90-
- name: Build ${{ inputs.apimEnv }} oas
91-
working-directory: .
92-
env:
93-
APIM_ENV: ${{ inputs.apimEnv }}
88+
- name: Set APIM_ENV
9489
shell: bash
9590
run: |
96-
if [ ${{ env.APIM_ENV }} == "internal-dev-sandbox" ] && [ ${{ inputs.buildSandbox }} == true ]
97-
then
98-
echo "Building sandbox OAS spec"
99-
make build-json-oas-spec APIM_ENV=sandbox
100-
else
101-
echo "Building env specific OAS spec"
102-
make build-json-oas-spec APIM_ENV=${{ env.APIM_ENV }}
103-
fi
104-
91+
APIM_ENV="${{ inputs.apimEnv }}"
10592
if [[ $APIM_ENV == *-pr ]]; then
10693
echo "Removing pr suffix from APIM_ENV after building OAS and calling proxygen"
10794
APIM_ENV=$(echo "$APIM_ENV" | sed 's/-pr$//')

.github/actions/build-sdk/action.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ runs:
5555
run: |
5656
make build VERSION="${{ inputs.version }}"
5757
58-
- name: Upload API OAS specification artifact
59-
uses: actions/upload-artifact@v4
60-
with:
61-
path: "build"
62-
name: api-oas-specification-${{ inputs.version }}
63-
6458
- name: Upload html artifact
6559
uses: actions/upload-artifact@v4
6660
with:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Trivy IaC Scan"
2+
description: "Scan Terraform IaC using Trivy"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: "Trivy Terraform IaC Scan"
7+
shell: bash
8+
run: |
9+
components_exit_code=0
10+
modules_exit_code=0
11+
12+
./scripts/terraform/trivy-scan.sh --mode iac ./infrastructure/terraform/components || components_exit_code=$?
13+
./scripts/terraform/trivy-scan.sh --mode iac ./infrastructure/terraform/modules || modules_exit_code=$?
14+
15+
if [ $components_exit_code -ne 0 ] || [ $modules_exit_code -ne 0 ]; then
16+
echo "Trivy misconfigurations detected."
17+
exit 1
18+
fi
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: "Trivy Package Scan"
2+
description: "Scan project packages using Trivy"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: "Trivy Package Scan"
7+
shell: bash
8+
run: |
9+
exit_code=0
10+
11+
./scripts/terraform/trivy-scan.sh --mode package . || exit_code=$?
12+
13+
if [ $exit_code -ne 0 ]; then
14+
echo "Trivy has detected package vulnerablilites. Please refer to https://nhsd-confluence.digital.nhs.uk/spaces/RIS/pages/1257636917/PLAT-KOP-012+-+Trivy+Pipeline+Vulnerability+Scanning+Exemption"
15+
exit 1
16+
fi

.github/actions/trivy/action.yaml

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

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
is_version_prerelease: ${{ steps.variables.outputs.is_version_prerelease }}
2929
does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }}
3030
pr_number: ${{ steps.pr_exists.outputs.pr_number }}
31+
skip_trivy_package: ${{ steps.skip_trivy.outputs.skip_trivy_package }}
3132
steps:
3233
- name: "Checkout code"
3334
uses: actions/checkout@v5
@@ -66,6 +67,26 @@ jobs:
6667
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
6768
echo "pr_number=" >> $GITHUB_OUTPUT
6869
fi
70+
- name: "Determine if Trivy package scan should be skipped"
71+
id: skip_trivy
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }}
75+
run: |
76+
if [[ -z "$PR_NUMBER" ]]; then
77+
echo "No pull request detected; Trivy package scan will run."
78+
echo "skip_trivy_package=false" >> $GITHUB_OUTPUT
79+
exit 0
80+
fi
81+
82+
labels=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
83+
echo "Labels on PR #$PR_NUMBER: $labels"
84+
85+
if echo "$labels" | grep -Fxq 'skip-trivy-package'; then
86+
echo "skip_trivy_package=true" >> $GITHUB_OUTPUT
87+
else
88+
echo "skip_trivy_package=false" >> $GITHUB_OUTPUT
89+
fi
6990
- name: "List variables"
7091
run: |
7192
export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}"
@@ -89,6 +110,7 @@ jobs:
89110
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
90111
nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}"
91112
python_version: "${{ needs.metadata.outputs.python_version }}"
113+
skip_trivy_package: ${{ needs.metadata.outputs.skip_trivy_package == 'true' }}
92114
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
93115
version: "${{ needs.metadata.outputs.version }}"
94116
secrets: inherit

.github/workflows/manual-proxy-environment-deploy.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ jobs:
7777
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
7878
echo "APIM_ENV=$APIM_ENV" >> $GITHUB_ENV
7979
80+
- name: "Build OAS spec"
81+
uses: ./.github/actions/build-oas-spec
82+
with:
83+
apimEnv: "${{ env.APIM_ENV }}"
84+
buildSandbox: ${{ inputs.build_sandbox }}
85+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
8087
- name: "Build proxies"
8188
env:
8289
PROXYGEN_API_NAME: nhs-notify-supplier
@@ -90,4 +97,3 @@ jobs:
9097
runId: "${{ github.run_id }}"
9198
buildSandbox: ${{ inputs.build_sandbox }}
9299
releaseVersion: ${{ github.ref_name }}
93-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)