Skip to content

Commit ba990e1

Browse files
authored
Experimental: Test GitHub Actions locally (nhs-england-tools#114)
## Description This PR introduces the `nektos/act` project to run GitHub Actions workflows on a developer's local machine, providing a fast, cost-effective and resource-efficient way to test changes to actions and debug before pushing to GitHub. It emulates the GitHub Actions runner environment using Docker containers, allowing for an identical testing conditions. ## Context <img width="2056" alt="image" src="https://github.com/nhs-england-tools/repository-template/assets/499338/ed06f59f-aa9c-4557-abf2-8b1298813d5f"> ### Testing ``` # clone the repo and switch to the `Test_GitHub_Actions_locally` branch, then run: $ make runner-act workflow="stage-1-commit" job="cloc-repository" ``` ## Type of changes - [ ] Refactoring (non-breaking change) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist - [x] I am familiar with the [contributing guidelines](../docs/CONTRIBUTING.md) - [x] I have followed the code style of the project - [x] I have added tests to cover my changes - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 0b030b6 commit ba990e1

18 files changed

+153
-22
lines changed

.github/actions/cloc-repository/action.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ runs:
3131
shell: bash
3232
run: zip cloc-report.json.zip cloc-report.json
3333
- name: "Upload CLOC report as an artefact"
34+
if: ${{ !env.ACT }}
3435
uses: actions/upload-artifact@v3
3536
with:
3637
name: cloc-report.json.zip

.github/actions/scan-dependencies/action.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ runs:
3131
shell: bash
3232
run: zip sbom-repository-report.json.zip sbom-repository-report.json
3333
- name: "Upload SBOM report as an artefact"
34+
if: ${{ !env.ACT }}
3435
uses: actions/upload-artifact@v3
3536
with:
3637
name: sbom-repository-report.json.zip
@@ -45,6 +46,7 @@ runs:
4546
shell: bash
4647
run: zip vulnerabilities-repository-report.json.zip vulnerabilities-repository-report.json
4748
- name: "Upload vulnerabilities report as an artefact"
49+
if: ${{ !env.ACT }}
4850
uses: actions/upload-artifact@v3
4951
with:
5052
name: vulnerabilities-repository-report.json.zip

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111

1212
jobs:
1313
metadata:
14+
name: "Set CI/CD metadata"
1415
runs-on: ubuntu-latest
1516
timeout-minutes: 1
1617
outputs:
@@ -66,6 +67,7 @@ jobs:
6667
export DOES_PULL_REQUEST_EXIST="${{ steps.pr_exists.outputs.does_pull_request_exist }}"
6768
make list-variables
6869
commit-stage: # Recommended maximum execution time is 2 minutes
70+
name: "Commit stage"
6971
needs: [metadata]
7072
uses: ./.github/workflows/stage-1-commit.yaml
7173
with:
@@ -78,6 +80,7 @@ jobs:
7880
version: "${{ needs.metadata.outputs.version }}"
7981
secrets: inherit
8082
test-stage: # Recommended maximum execution time is 5 minutes
83+
name: "Test stage"
8184
needs: [metadata, commit-stage]
8285
uses: ./.github/workflows/stage-2-test.yaml
8386
with:
@@ -90,6 +93,7 @@ jobs:
9093
version: "${{ needs.metadata.outputs.version }}"
9194
secrets: inherit
9295
build-stage: # Recommended maximum execution time is 3 minutes
96+
name: "Build stage"
9397
needs: [metadata, test-stage]
9498
uses: ./.github/workflows/stage-3-build.yaml
9599
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened'))
@@ -103,6 +107,7 @@ jobs:
103107
version: "${{ needs.metadata.outputs.version }}"
104108
secrets: inherit
105109
acceptance-stage: # Recommended maximum execution time is 10 minutes
110+
name: "Acceptance stage"
106111
needs: [metadata, build-stage]
107112
uses: ./.github/workflows/stage-4-acceptance.yaml
108113
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened'))

.github/workflows/cicd-2-publish.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
metadata:
11+
name: "Set CI/CD metadata"
1112
runs-on: ubuntu-latest
1213
if: github.event.pull_request.merged == true
1314
timeout-minutes: 1
@@ -45,6 +46,7 @@ jobs:
4546
export VERSION="${{ steps.variables.outputs.version }}"
4647
make list-variables
4748
publish:
49+
name: "Publish packages"
4850
runs-on: ubuntu-latest
4951
needs: [metadata]
5052
if: github.event.pull_request.merged == true
@@ -78,13 +80,14 @@ jobs:
7880
# asset_name: repository-template-${{ needs.metadata.outputs.version }}.tar.gz
7981
# asset_content_type: "application/gzip"
8082
success:
83+
name: "Success notification"
8184
runs-on: ubuntu-latest
8285
needs: [publish]
8386
steps:
8487
- name: "Check prerequisites for notification"
8588
id: check
8689
run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT
87-
- name: "Notify on build completion"
90+
- name: "Notify on publishing packages"
8891
if: steps.check.outputs.secret_exist == 'true'
8992
uses: nhs-england-tools/[email protected]
9093
with:

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
metadata:
13+
name: "Set CI/CD metadata"
1314
runs-on: ubuntu-latest
1415
timeout-minutes: 1
1516
outputs:
@@ -49,6 +50,7 @@ jobs:
4950
export TAG="${{ steps.variables.outputs.tag }}"
5051
make list-variables
5152
deploy:
53+
name: "Deploy to an environment"
5254
runs-on: ubuntu-latest
5355
needs: [metadata]
5456
timeout-minutes: 10
@@ -57,13 +59,14 @@ jobs:
5759
uses: actions/checkout@v4
5860
# TODO: More jobs or/and steps here
5961
# success:
62+
# name: "Success notification"
6063
# runs-on: ubuntu-latest
6164
# needs: [deploy]
6265
# steps:
6366
# - name: "Check prerequisites for notification"
6467
# id: check
6568
# run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT
66-
# - name: "Notify on build completion"
69+
# - name: "Notify on deployment to an environment"
6770
# if: steps.check.outputs.secret_exist == 'true'
6871
# uses: nhs-england-tools/[email protected]
6972
# with:

.github/workflows/stage-1-commit.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ on:
3434

3535
jobs:
3636
scan-secrets:
37+
name: "Scan secrets"
3738
runs-on: ubuntu-latest
3839
timeout-minutes: 2
39-
name: "Scan secrets"
4040
steps:
4141
- name: "Checkout code"
4242
uses: actions/checkout@v4
@@ -45,9 +45,9 @@ jobs:
4545
- name: "Scan secrets"
4646
uses: ./.github/actions/scan-secrets
4747
check-file-format:
48+
name: "Check file format"
4849
runs-on: ubuntu-latest
4950
timeout-minutes: 2
50-
name: "Check file format"
5151
steps:
5252
- name: "Checkout code"
5353
uses: actions/checkout@v4
@@ -56,9 +56,9 @@ jobs:
5656
- name: "Check file format"
5757
uses: ./.github/actions/check-file-format
5858
check-markdown-format:
59+
name: "Check markdown format"
5960
runs-on: ubuntu-latest
6061
timeout-minutes: 2
61-
name: "Check markdown format"
6262
steps:
6363
- name: "Checkout code"
6464
uses: actions/checkout@v4
@@ -67,21 +67,21 @@ jobs:
6767
- name: "Check markdown format"
6868
uses: ./.github/actions/check-markdown-format
6969
lint-terraform:
70+
name: "Lint Terraform"
7071
runs-on: ubuntu-latest
7172
timeout-minutes: 2
72-
name: "Lint Terraform"
7373
steps:
7474
- name: "Checkout code"
7575
uses: actions/checkout@v4
7676
- name: "Lint Terraform"
7777
uses: ./.github/actions/lint-terraform
7878
cloc-repository:
79+
name: "Count lines of code"
7980
runs-on: ubuntu-latest
8081
permissions:
8182
id-token: write
8283
contents: read
8384
timeout-minutes: 2
84-
name: "Count lines of code"
8585
steps:
8686
- name: "Checkout code"
8787
uses: actions/checkout@v4
@@ -95,12 +95,12 @@ jobs:
9595
idp_aws_report_upload_role_name: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ROLE_NAME }}"
9696
idp_aws_report_upload_bucket_endpoint: "${{ secrets.IDP_AWS_REPORT_UPLOAD_BUCKET_ENDPOINT }}"
9797
scan-dependencies:
98+
name: "Scan dependencies"
9899
runs-on: ubuntu-latest
99100
permissions:
100101
id-token: write
101102
contents: read
102103
timeout-minutes: 2
103-
name: "Scan dependencies"
104104
steps:
105105
- name: "Checkout code"
106106
uses: actions/checkout@v4

.github/workflows/stage-2-test.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ on:
3434

3535
jobs:
3636
test-unit:
37+
name: "Unit tests"
3738
runs-on: ubuntu-latest
3839
timeout-minutes: 5
3940
steps:
@@ -46,6 +47,7 @@ jobs:
4647
run: |
4748
echo "Nothing to save"
4849
test-lint:
50+
name: "Linting"
4951
runs-on: ubuntu-latest
5052
timeout-minutes: 5
5153
steps:
@@ -58,6 +60,7 @@ jobs:
5860
run: |
5961
echo "Nothing to save"
6062
test-coverage:
63+
name: "Test coverage"
6164
needs: [test-unit]
6265
runs-on: ubuntu-latest
6366
timeout-minutes: 5
@@ -71,13 +74,13 @@ jobs:
7174
run: |
7275
echo "Nothing to save"
7376
perform-static-analysis:
77+
name: "Perform static analysis"
7478
needs: [test-unit]
7579
runs-on: ubuntu-latest
7680
permissions:
7781
id-token: write
7882
contents: read
7983
timeout-minutes: 5
80-
name: "Perform static analysis"
8184
steps:
8285
- name: "Checkout code"
8386
uses: actions/checkout@v4

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ on:
3434

3535
jobs:
3636
artefact-1:
37+
name: "Artefact 1"
3738
runs-on: ubuntu-latest
3839
timeout-minutes: 3
3940
steps:
@@ -50,6 +51,7 @@ jobs:
5051
echo "Uploading artefact 1 ..."
5152
# TODO: Use either action/cache or action/upload-artifact
5253
artefact-2:
54+
name: "Artefact 2"
5355
runs-on: ubuntu-latest
5456
timeout-minutes: 3
5557
steps:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ on:
3434

3535
jobs:
3636
environment-set-up:
37+
name: "Environment set up"
3738
runs-on: ubuntu-latest
3839
timeout-minutes: 5
3940
steps:
@@ -49,6 +50,7 @@ jobs:
4950
run: |
5051
echo "Deploying application..."
5152
test-contract:
53+
name: "Contract test"
5254
runs-on: ubuntu-latest
5355
needs: environment-set-up
5456
timeout-minutes: 10
@@ -62,6 +64,7 @@ jobs:
6264
run: |
6365
echo "Nothing to save"
6466
test-security:
67+
name: "Security test"
6568
runs-on: ubuntu-latest
6669
needs: environment-set-up
6770
timeout-minutes: 10
@@ -75,6 +78,7 @@ jobs:
7578
run: |
7679
echo "Nothing to save"
7780
test-ui:
81+
name: "UI test"
7882
runs-on: ubuntu-latest
7983
needs: environment-set-up
8084
timeout-minutes: 10
@@ -88,6 +92,7 @@ jobs:
8892
run: |
8993
echo "Nothing to save"
9094
test-ui-performance:
95+
name: "UI performance test"
9196
runs-on: ubuntu-latest
9297
needs: environment-set-up
9398
timeout-minutes: 10
@@ -101,6 +106,7 @@ jobs:
101106
run: |
102107
echo "Nothing to save"
103108
test-integration:
109+
name: "Integration test"
104110
runs-on: ubuntu-latest
105111
needs: environment-set-up
106112
timeout-minutes: 10
@@ -114,6 +120,7 @@ jobs:
114120
run: |
115121
echo "Nothing to save"
116122
test-accessibility:
123+
name: "Accessibility test"
117124
runs-on: ubuntu-latest
118125
needs: environment-set-up
119126
timeout-minutes: 10
@@ -127,6 +134,7 @@ jobs:
127134
run: |
128135
echo "Nothing to save"
129136
test-load:
137+
name: "Load test"
130138
runs-on: ubuntu-latest
131139
needs: environment-set-up
132140
timeout-minutes: 10
@@ -140,6 +148,7 @@ jobs:
140148
run: |
141149
echo "Nothing to save"
142150
environment-tear-down:
151+
name: "Environment tear down"
143152
runs-on: ubuntu-latest
144153
needs:
145154
[

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# WARNING: Please, DO NOT edit this section of the file! It is maintained in the repository template.
22

33
.scannerwork
4-
*cloc-report*.json
4+
*cloc*report*.json
55
*sbom*report*.json
66
*vulnerabilities*report*.json
7+
*report*json.zip
78
.version
89

910
*.code-workspace

0 commit comments

Comments
 (0)