Skip to content

Merge pull request #696 from com-pas/fix/sonar-analysis-workflow #2210

Merge pull request #696 from com-pas/fix/sonar-analysis-workflow

Merge pull request #696 from com-pas/fix/sonar-analysis-workflow #2210

# SPDX-FileCopyrightText: 2022 Alliander N.V.
#
# SPDX-License-Identifier: Apache-2.0
name: SonarCloud Build
on:
push:
branches:
- '**'
pull_request:
branches:
- 'main'
- 'develop'
jobs:
precheck-build:
name: Pre Check Build
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: 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: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./mvnw -B -s custom_maven_settings.xml -Psonar clean verify
- name: Upload build artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: build-artifacts
path: |
service/src/
app/src/
api/src/
repository/src/
repository-postgresql/src/
service/target/
app/target/
api/target/
repository/target/
repository-postgresql/target/
retention-days: 1
- name: Save PR number to file
if: ${{ github.event_name == 'pull_request' }}
run: echo ${{ github.event.pull_request.number }} > PR_NUMBER.txt
- name: Archive PR number
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: PR_NUMBER
path: PR_NUMBER.txt