Skip to content

Moving code analysis to coresponded jobs #1

Moving code analysis to coresponded jobs

Moving code analysis to coresponded jobs #1

Workflow file for this run

on:
workflow_call:
secrets:
SLACK_WEBHOOK_URL:
required: false
SONAR_TOKEN:
required: true
GITHUB_TOKEN:

Check failure on line 8 in .github/workflows/backend-checks.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/backend-checks.yml

Invalid workflow file

secret name `GITHUB_TOKEN` within `workflow_call` can not be used since it would collide with system reserved name
required: true
jobs:
scan-backend-changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
backend-unit-tests:
needs: scan-backend-changes
if: ${{ needs.scan-backend-changes.outputs.backend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get Gradle version
working-directory: ./backend
run: |
echo "GRADLE_VERSION=$(sed -n 's/.*gradle-\([0-9]*\(\.[0-9]*\)*\)-.*/\1/p' ./gradle/wrapper/gradle-wrapper.properties)" >> $GITHUB_ENV
- name: Set up JDK
uses: actions/setup-java@2e74cbce18569d23ca8b812590dbb83f13ac7c5a
with:
java-version: "17.0"
distribution: "temurin"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b
with:
gradle-version: ${{ env.GRADLE_VERSION}}
- name: Run backend tests
working-directory: ./backend
run: ./gradlew test -x integrationTest
- 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 }}
backend-integration-tests:
needs: scan-backend-changes
if: ${{ needs.scan-backend-changes.outputs.backend == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get Gradle version
working-directory: ./backend
run: |
echo "GRADLE_VERSION=$(sed -n 's/.*gradle-\([0-9]*\(\.[0-9]*\)*\)-.*/\1/p' ./gradle/wrapper/gradle-wrapper.properties)" >> $GITHUB_ENV
- name: Set up JDK
uses: actions/setup-java@2e74cbce18569d23ca8b812590dbb83f13ac7c5a
with:
java-version: "17.0"
distribution: "temurin"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@d9336dac04dea2507a617466bc058a3def92b18b
with:
gradle-version: ${{ env.GRADLE_VERSION }}
- name: Run backend tests
working-directory: ./backend
run: ./gradlew integrationTest -x test
- 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-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 }}