Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 85 additions & 90 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,104 +2,99 @@
#
# SPDX-License-Identifier: Apache-2.0

name: SonarCloud Analysis
name: SonarCloud Build and Analysis

on:
workflow_run:
workflows: [SonarCloud Build]
types: [completed]
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
sonar-check:
sonarqube:
name: Sonar build and analysis
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
timeout-minutes: 15
timeout-minutes: 30
permissions:
contents: read
actions: read
pull-requests: read

steps:
- name: echo event
run: cat $GITHUB_EVENT_PATH
- name: Download PR number artifact
if: github.event.workflow_run.event == 'pull_request'
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
with:
workflow: SonarCloud Build
run_id: ${{ github.event.workflow_run.id }}
name: PR_NUMBER
- name: Read PR_NUMBER.txt
if: github.event.workflow_run.event == 'pull_request'
id: pr_number
uses: juliangruber/read-file-action@271ff311a4947af354c6abcd696a306553b9ec18 # v1
with:
path: ./PR_NUMBER.txt
- name: Request GitHub API for PR data
if: github.event.workflow_run.event == 'pull_request'
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
id: get_pr_data
with:
route: GET /repos/{full_name}/pulls/{number}
number: ${{ steps.pr_number.outputs.content }}
full_name: ${{ github.event.repository.full_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
- name: Download build artifacts
uses: dawidd6/action-download-artifact@b6e2e70617bc3265edd6dab6c906732b2f1ae151 # v21
with:
workflow: SonarCloud Build
run_id: ${{ github.event.workflow_run.id }}
name: build-artifacts
- name: Cache SonarCloud packages
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0

- name: Cache SonarCloud packages
uses: actions/cache@2c8a9bd7457de244a408f35966fab2fb45fda9c8 # v6.0.0
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Set up JDK 17
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
with:
distribution: 'zulu'
java-version: '17'
cache: 'maven'

- name: Set Docker API version
# Workaround for Docker 29.x incompatibility with Testcontainers/EmbeddedPostgres.
# See: https://github.com/testcontainers/testcontainers-java/issues/11212
# This forces the Docker Java client to use API version 1.44, which is compatible with current Testcontainers/EmbeddedPostgres.
run: |
echo "api.version=1.44" > $HOME/.docker-java.properties

- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'

- name: Request GitHub API for PR data
if: github.event_name == 'pull_request'
uses: octokit/request-action@b91aabaa861c777dcdb14e2387e30eddf04619ae # v3.0.0
id: get_pr_data
with:
route: GET /repos/{full_name}/pulls/{number}
number: ${{ github.event.pull_request.number }}
full_name: ${{ github.event.repository.full_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set Common Sonar Variables
id: sonar_env
run: |
echo "sonar_opts=-Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=com-pas_compas-scl-data-service -Dsonar.organization=com-pas" >> "$GITHUB_OUTPUT"

- name: Build and analyze (Pull Request)
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
mvn -B -s custom_maven_settings.xml -Psonar \
$SONAR_OPTS \
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \
-Dsonar.scm.revision="$HEAD_SHA" \
verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

- name: Set up JDK 17
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
with:
distribution: 'zulu'
java-version: '17'
- name: Set Common Sonar Variables
id: sonar_env
run: |
echo "sonar_opts=-Dsonar.host.url=https://sonarcloud.io -Dsonar.projectKey=com-pas_compas-scl-data-service -Dsonar.organization=com-pas" >> "$GITHUB_OUTPUT"
- name: Create custom Maven Settings.xml
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
with:
output_file: custom_maven_settings.xml
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
- name: Build and analyze (Pull Request)
if: ${{ github.event.workflow_run.event == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
./mvnw -B -s custom_maven_settings.xml -Psonar \
$SONAR_OPTS \
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \
-Dsonar.scm.revision="$HEAD_SHA" \
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
- name: Build and analyze (Push)
if: ${{ github.event.workflow_run.event == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
./mvnw -B -s custom_maven_settings.xml -Psonar \
$SONAR_OPTS \
-Dsonar.scm.revision="$HEAD_SHA" \
-Dsonar.branch.name="$HEAD_BRANCH" \
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
- name: Build and analyze (Push)
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_OPTS: ${{ steps.sonar_env.outputs.sonar_opts }}
HEAD_BRANCH: ${{ github.ref_name }}
run: |
mvn -B -s custom_maven_settings.xml -Psonar \
$SONAR_OPTS \
-Dsonar.branch.name="$HEAD_BRANCH" \
verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
84 changes: 0 additions & 84 deletions .github/workflows/sonarcloud-build.yml

This file was deleted.

Loading