Moving code analysis to coresponded jobs #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | ||
workflow_call: | ||
secrets: | ||
SLACK_WEBHOOK_URL: | ||
required: false | ||
SONAR_TOKEN: | ||
required: true | ||
GITHUB_TOKEN: | ||
required: true | ||
jobs: | ||
scan-frontend-changes: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
frontend: ${{ steps.filter.outputs.frontend }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dorny/paths-filter@v3 | ||
id: filter | ||
with: | ||
filters: | | ||
frontend: | ||
- 'frontend/**' | ||
frontend-tests: | ||
needs: scan-frontend-changes | ||
if: ${{ needs.scan-frontend-changes.outputs.frontend == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ./frontend/package.json | ||
cache: npm | ||
cache-dependency-path: ./frontend/package-lock.json | ||
- name: Cache node_modules | ||
uses: actions/cache@v4 | ||
id: node-modules-cache | ||
with: | ||
path: | | ||
./frontend/node_modules | ||
key: modules-${{ hashFiles('./frontend/package-lock.json') }} | ||
- name: Install dependencies | ||
if: steps.node-modules-cache.outputs.cache-hit != 'true' | ||
run: | | ||
npm ci | ||
working-directory: ./frontend | ||
- name: Run tests | ||
run: | | ||
npm test | ||
working-directory: ./frontend | ||
- name: Send status to Slack | ||
# Third-party action, pin to commit SHA! | ||
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions | ||
uses: digitalservicebund/notify-on-failure-gha@814d0c4b2ad6a3443e89c991f8657b10126510bf # v1.5.0 | ||
if: ${{ failure() && github.ref == 'refs/heads/main' }} | ||
with: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
frontend-style: | ||
needs: scan-frontend-changes | ||
if: ${{ needs.scan-frontend-changes.outputs.frontend == 'true' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ./frontend/package.json | ||
cache: npm | ||
cache-dependency-path: ./frontend/package-lock.json | ||
- name: Cache node_modules | ||
uses: actions/cache@v4 | ||
id: node-modules-cache | ||
with: | ||
path: | | ||
./frontend/node_modules | ||
key: modules-${{ hashFiles('./frontend/package-lock.json') }} | ||
- name: Install dependencies | ||
if: steps.node-modules-cache.outputs.cache-hit != 'true' | ||
run: | | ||
npm ci | ||
working-directory: ./frontend | ||
- name: Check style | ||
run: npm run style:check | ||
working-directory: ./frontend | ||
- name: Send status to Slack | ||
# Third-party action, pin to commit SHA! | ||
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions | ||
uses: digitalservicebund/notify-on-failure-gha@814d0c4b2ad6a3443e89c991f8657b10126510bf # v1.5.0 | ||
if: ${{ failure() && github.ref == 'refs/heads/main' }} | ||
with: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
analyze-frontend: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: ./frontend/package.json | ||
cache: npm | ||
cache-dependency-path: ./frontend/package-lock.json | ||
- name: Install SonarScanner | ||
uses: digitalservicebund/setup-sonarscanner@3ade23691f865c02dce6b46452947a0e7944196e # v1.0.0 | ||
- name: Scan with SonarQube | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
run: | | ||
npm install | ||
npm run coverage | ||
sonar-scanner | ||
working-directory: ./frontend | ||
- name: Check SonarQube Quality Gate | ||
uses: sonarsource/sonarqube-quality-gate-action@72f24ebf1f81eda168a979ce14b8203273b7c3ad | ||
with: | ||
scanMetadataReportFile: frontend/.scannerwork/report-task.txt | ||
timeout-minutes: 3 | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
- name: Send status to Slack | ||
# Third-party action, pin to commit SHA! | ||
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions | ||
uses: digitalservicebund/notify-on-failure-gha@814d0c4b2ad6a3443e89c991f8657b10126510bf # v1.5.0 | ||
if: ${{ failure() }} | ||
with: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |