Skip to content

Commit

Permalink
Moving code analysis to coresponded jobs
Browse files Browse the repository at this point in the history
RISDEV-0000
  • Loading branch information
Nadav-B committed Jun 14, 2024
1 parent e833169 commit 0390778
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
secrets:
SLACK_WEBHOOK_URL:
required: false
SONAR_TOKEN:
required: true
GITHUB_TOKEN:
required: true

jobs:
scan-backend-changes:
Expand Down Expand Up @@ -77,3 +81,46 @@ jobs:
if: ${{ failure() && github.ref == 'refs/heads/main' }}
with:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

analyze-backend:
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: Set up JDK
uses: actions/setup-java@2e74cbce18569d23ca8b812590dbb83f13ac7c5a
with:
java-version: "17.0"
distribution: "temurin"
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
- name: Scan with SonarQube
uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b
with:
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: sonar --info
build-root-directory: ./backend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Check SonarQube Quality Gate
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: sonarsource/sonarqube-quality-gate-action@72f24ebf1f81eda168a979ce14b8203273b7c3ad
with:
scanMetadataReportFile: backend/build/sonar/report-task.txt
timeout-minutes: 3 # Force to fail step after specific time
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 }}
43 changes: 43 additions & 0 deletions .github/workflows/frontend-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ on:
secrets:
SLACK_WEBHOOK_URL:
required: false
SONAR_TOKEN:
required: true
GITHUB_TOKEN:
required: true

jobs:
scan-frontend-changes:
Expand Down Expand Up @@ -88,3 +92,42 @@ jobs:
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 }}
92 changes: 5 additions & 87 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ jobs:
with:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

backend-tests:
uses: ./.github/workflows/backend-tests.yml
backend-checks:
uses: ./.github/workflows/backend-checks.yml
secrets: inherit

backend-build-image-and-scan:
Expand Down Expand Up @@ -304,94 +304,12 @@ jobs:
with:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

analyze-backend:
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: Set up JDK
uses: actions/setup-java@2e74cbce18569d23ca8b812590dbb83f13ac7c5a
with:
java-version: "17.0"
distribution: "temurin"
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
- name: Scan with SonarQube
uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b
with:
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: sonar --info
build-root-directory: ./backend
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Check SonarQube Quality Gate
# Third-party action, pin to commit SHA!
# See https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions
uses: sonarsource/sonarqube-quality-gate-action@72f24ebf1f81eda168a979ce14b8203273b7c3ad
with:
scanMetadataReportFile: backend/build/sonar/report-task.txt
timeout-minutes: 3 # Force to fail step after specific time
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 }}

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 }}

push-backend-image-to-registry:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'dev-env') || contains(github.event.labeled.labels.*.name, 'dev-env') }}
needs:
- backend-build
- backend-tests
- backend-checks
- backend-build-image-and-scan
- audit-licenses-backend
permissions:
Expand Down Expand Up @@ -684,8 +602,8 @@ jobs:
- push-backend-image-to-registry
- e2e-tests
- check-latest-deploy-tag
- analyze-backend
- analyze-frontend
- backend-checks
- frontend-checks
permissions:
id-token: write # Enable OIDC for gitsign
steps:
Expand Down

0 comments on commit 0390778

Please sign in to comment.