Skip to content

feat: Add file groups #3543

feat: Add file groups

feat: Add file groups #3543

# SPDX-FileCopyrightText: 2022 Alliander N.V.
#
# SPDX-License-Identifier: Apache-2.0
name: SonarCloud Build and Analysis
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarqube:
name: Sonar build and analysis
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
actions: read
pull-requests: read
steps:
- 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: 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