From a6390919883022b1c6e26f03c8fc7da273529692 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 1 Oct 2024 13:25:45 +0100 Subject: [PATCH 1/5] Add Sonar project config --- sonar-project.properties | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sonar-project.properties diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..ece5b6f --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,16 @@ +sonar.projectKey=DEFRA_forms-manager +sonar.projectName=forms-manager +sonar.organization=defra + +sonar.links.homepage=https://github.com/DEFRA/forms-manager/blob/main/README.md +sonar.links.ci=https://github.com/DEFRA/forms-manager/actions +sonar.links.scm=https://github.com/DEFRA/forms-manager +sonar.links.issue=https://github.com/DEFRA/forms-manager/issues + +sonar.sourceEncoding=UTF-8 + +sonar.sources=src +sonar.exclusions=**/*.test.* +sonar.tests=src,test +sonar.test.inclusions=**/*.test.* +sonar.cpd.exclusions=**/*.test.* From 9b5376d5e1b90e857b317d50d27de73748bdc1f5 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 1 Oct 2024 13:29:33 +0100 Subject: [PATCH 2/5] Add Sonar to GitHub Actions --- .github/workflows/check-pull-request.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/check-pull-request.yml b/.github/workflows/check-pull-request.yml index 697fc15..af628a3 100644 --- a/.github/workflows/check-pull-request.yml +++ b/.github/workflows/check-pull-request.yml @@ -176,3 +176,20 @@ jobs: - name: Run task run: ${{ matrix.task.run }} + + analysis: + name: Analysis + runs-on: ubuntu-latest + needs: [install, build, tasks] + + steps: + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@v3.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From 71a47c1f4be8ca6617548b61a7b334df41878241 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 1 Oct 2024 16:42:11 +0100 Subject: [PATCH 3/5] Cache and restore code coverage --- .github/workflows/check-pull-request.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/check-pull-request.yml b/.github/workflows/check-pull-request.yml index af628a3..f7aa611 100644 --- a/.github/workflows/check-pull-request.yml +++ b/.github/workflows/check-pull-request.yml @@ -149,7 +149,9 @@ jobs: task: - description: Unit tests + name: test-unit run: npm run test + cache: coverage steps: - name: Checkout @@ -174,6 +176,14 @@ jobs: with: node-version-file: .nvmrc + - name: Cache task + if: ${{ matrix.task.cache }} + uses: actions/cache@v4 + with: + enableCrossOsArchive: true + key: ${{ matrix.task.name }}-${{ runner.os }} + path: ${{ matrix.task.cache }} + - name: Run task run: ${{ matrix.task.run }} @@ -188,6 +198,13 @@ jobs: with: fetch-depth: 0 + - name: Restore unit test coverage + uses: actions/cache/restore@v4 + with: + enableCrossOsArchive: true + key: test-unit-${{ runner.os }} + path: coverage + - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@v3.0.0 env: From 807b9b98fc748fa8d359e21684b6d51f28662196 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 1 Oct 2024 13:31:11 +0100 Subject: [PATCH 4/5] Add test coverage analysis --- sonar-project.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/sonar-project.properties b/sonar-project.properties index ece5b6f..6328e11 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -7,6 +7,7 @@ sonar.links.ci=https://github.com/DEFRA/forms-manager/actions sonar.links.scm=https://github.com/DEFRA/forms-manager sonar.links.issue=https://github.com/DEFRA/forms-manager/issues +sonar.javascript.lcov.reportPaths=coverage/lcov.info sonar.sourceEncoding=UTF-8 sonar.sources=src From fcc524cc67abcee526ed0dc7a7ba82b67684b6b5 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 1 Oct 2024 13:32:24 +0100 Subject: [PATCH 5/5] Consolidate install and build steps --- .github/workflows/check-pull-request.yml | 48 +++++------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/.github/workflows/check-pull-request.yml b/.github/workflows/check-pull-request.yml index f7aa611..61cbbb7 100644 --- a/.github/workflows/check-pull-request.yml +++ b/.github/workflows/check-pull-request.yml @@ -14,8 +14,8 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: - install: - name: Install + build: + name: Build runs-on: ${{ matrix.runner }} strategy: @@ -37,40 +37,6 @@ jobs: key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }} path: node_modules - - name: Setup Node.js - if: steps.npm-install-cache.outputs.cache-hit != 'true' - uses: actions/setup-node@v4 - with: - cache: 'npm' - node-version-file: .nvmrc - - - name: Install dependencies - if: steps.npm-install-cache.outputs.cache-hit != 'true' - run: npm ci - - build: - name: Build - runs-on: ${{ matrix.runner }} - needs: [install] - - strategy: - fail-fast: false - - matrix: - runner: - - ubuntu-latest - - steps: - - name: Check out code - uses: actions/checkout@v4 - - - name: Restore dependencies - uses: actions/cache/restore@v4 - with: - enableCrossOsArchive: true - key: npm-install-${{ runner.os }}-${{ hashFiles('package-lock.json') }} - path: node_modules - - name: Cache build uses: actions/cache@v4 with: @@ -83,13 +49,17 @@ jobs: with: node-version-file: .nvmrc + - name: Install dependencies + if: steps.npm-install-cache.outputs.cache-hit != 'true' + run: npm ci + - name: Run build run: npm run build lint: name: ${{ matrix.task.description }} (${{ matrix.runner }}) runs-on: ${{ matrix.runner }} - needs: [install] + needs: [build] env: # Authorise GitHub API requests for EditorConfig checker binary @@ -138,7 +108,7 @@ jobs: tasks: name: ${{ matrix.task.description }} (${{ matrix.runner }}) runs-on: ${{ matrix.runner }} - needs: [install, build] + needs: [build] strategy: fail-fast: false @@ -190,7 +160,7 @@ jobs: analysis: name: Analysis runs-on: ubuntu-latest - needs: [install, build, tasks] + needs: [build, tasks] steps: - name: Check out code