Skip to content

Commit

Permalink
Merge pull request #323 from DEFRA/sonar-config
Browse files Browse the repository at this point in the history
Run Sonar via GitHub Actions
  • Loading branch information
colinrotherham authored Oct 1, 2024
2 parents eb8d0c9 + fcc524c commit 26f7f81
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
80 changes: 42 additions & 38 deletions .github/workflows/check-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -149,7 +119,9 @@ jobs:

task:
- description: Unit tests
name: test-unit
run: npm run test
cache: coverage

steps:
- name: Checkout
Expand All @@ -174,5 +146,37 @@ 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 }}

analysis:
name: Analysis
runs-on: ubuntu-latest
needs: [build, tasks]

steps:
- name: Check out code
uses: actions/checkout@v4
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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
17 changes: 17 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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.javascript.lcov.reportPaths=coverage/lcov.info
sonar.sourceEncoding=UTF-8

sonar.sources=src
sonar.exclusions=**/*.test.*
sonar.tests=src,test
sonar.test.inclusions=**/*.test.*
sonar.cpd.exclusions=**/*.test.*

0 comments on commit 26f7f81

Please sign in to comment.