|
15 | 15 | description: Whether to run unit tests using `test:unit` npm script |
16 | 16 | type: string |
17 | 17 | default: true |
| 18 | + SONARQUBE_CONTINUE_ON_ERROR: |
| 19 | + description: Whether to continue running the workflow if SonarQube quality gate fails |
| 20 | + type: string |
| 21 | + default: false |
18 | 22 | WORKING_DIRECTORY: |
19 | 23 | description: Path to working directory in repo |
20 | 24 | required: true |
|
27 | 31 | description: Whether to run pact tests using `test:pact:ci` npm script |
28 | 32 | type: string |
29 | 33 | default: false |
| 34 | + secrets: |
| 35 | + SONAR_TOKEN: |
| 36 | + description: The token used for secure access to the SonarQube platform |
| 37 | + required: false |
30 | 38 |
|
31 | 39 | jobs: |
32 | 40 | run-test-suite: |
33 | | - name: Run test suite and upload coverage artifact |
| 41 | + name: Run test suite and SonarQube |
34 | 42 | runs-on: ubuntu-24.04 |
35 | 43 | defaults: |
36 | 44 | run: |
37 | 45 | shell: bash |
38 | 46 | working-directory: ${{ inputs.WORKING_DIRECTORY }} |
| 47 | + env: |
| 48 | + CONTINUE_ON_ERROR: ${{ inputs.SONARQUBE_CONTINUE_ON_ERROR }} |
39 | 49 | steps: |
40 | | - - name: Check out repository code |
| 50 | + - name: Checkout Repository |
41 | 51 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
42 | 52 | with: |
| 53 | + fetch-depth: 0 |
43 | 54 | submodules: true |
44 | 55 |
|
45 | | - - name: Setup nodeJS |
| 56 | + - name: Setup NodeJS |
46 | 57 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
47 | 58 | with: |
48 | 59 | cache: npm |
49 | 60 | cache-dependency-path: ${{ inputs.WORKING_DIRECTORY }}/package-lock.json |
50 | 61 | node-version-file: ${{ inputs.WORKING_DIRECTORY }}/.nvmrc |
51 | 62 |
|
52 | | - - name: Configure authentication for private packages in .npmrc |
53 | | - if: inputs.PRIVATE_PACKAGES_REQUIRED == 'true' |
| 63 | + - name: Configure Authentication for Private Packages in .npmrc |
| 64 | + if: inputs.GENERATE_OPEN_PROXY_API_SPEC == 'true' |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
54 | 67 | run: | |
55 | 68 | echo "engine-strict=true" > .npmrc |
56 | 69 | echo "@govuk-one-login:registry=https://npm.pkg.github.com/" >> .npmrc |
57 | 70 | echo "//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" >> .npmrc |
58 | | - env: |
59 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
60 | 71 |
|
61 | | - - name: Install dependencies |
| 72 | + - name: Install Dependencies |
62 | 73 | run: npm clean-install |
63 | 74 |
|
64 | | - - name: Run unit tests |
| 75 | + - name: Run Unit Tests |
65 | 76 | if: inputs.RUN_UNIT_TESTS == 'true' |
66 | 77 | run: npm run test:unit |
67 | 78 |
|
68 | | - - name: Upload unit test coverage artifact for SonarQube scan |
69 | | - if: inputs.RUN_SONARQUBE == 'true' |
70 | | - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
71 | | - with: |
72 | | - name: test-coverage |
73 | | - path: ${{ inputs.WORKING_DIRECTORY }}/coverage/ |
74 | | - retention-days: 1 |
75 | | - |
76 | | - - name: Run infra tests |
| 79 | + - name: Run Infra Tests |
77 | 80 | if: inputs.RUN_INFRA_TESTS == 'true' |
78 | 81 | run: npm run test:infra |
79 | 82 |
|
80 | | - - name: Run pact tests |
| 83 | + - name: Run Pact Tests |
81 | 84 | if: inputs.RUN_PACT_TESTS == 'true' |
82 | 85 | continue-on-error: true # Pact tests are currently failing - remove step once fixed |
83 | 86 | env: |
|
87 | 90 | PACT_BROKER_SOURCE_SECRET: ${{ secrets.PACT_BROKER_SOURCE_SECRET }} |
88 | 91 | PUBLISH_PACT_VERIFICATION_RESULTS: "false" |
89 | 92 | run: npm run test:pact:ci |
| 93 | + |
| 94 | + - name: Run SonarQube Scan |
| 95 | + if: inputs.RUN_SONARQUBE == 'true' |
| 96 | + uses: sonarsource/sonarqube-scan-action@8c71dc039c2dd71d3821e89a2b58ecc7fee6ced9 #v5.3.0 |
| 97 | + env: |
| 98 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 100 | + with: |
| 101 | + projectBaseDir: ${{ inputs.WORKING_DIRECTORY }} |
| 102 | + |
| 103 | + - name: Run SonarQube Quality Gate Check |
| 104 | + if: inputs.RUN_SONARQUBE == 'true' |
| 105 | + uses: Sonarsource/sonarqube-quality-gate-action@8406f4f1edaffef38e9fb9c53eb292fc1d7684fa #master |
| 106 | + continue-on-error: ${{ fromJSON(env.CONTINUE_ON_ERROR) }} |
| 107 | + timeout-minutes: 5 |
| 108 | + env: |
| 109 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 110 | + with: |
| 111 | + scanMetadataReportFile: ${{ inputs.WORKING_DIRECTORY }}/.scannerwork/report-task.txt |
0 commit comments