-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: splitting SC workflow into two
- one for building and generating PR data - one for running sonarcloud analysis Signed-off-by: Juan Muñoz <juan.munoz@alliander.com>
- Loading branch information
1 parent
a078aa8
commit cd11701
Showing
2 changed files
with
173 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# SPDX-FileCopyrightText: 2022 Alliander N.V. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: SonarCloud Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
pull_request: | ||
branches: | ||
- 'main' | ||
- 'develop' | ||
pull_request_target: | ||
branches: | ||
- 'main' | ||
- 'develop' | ||
|
||
jobs: | ||
precheck-build: | ||
name: Pre Check Build | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
|
||
if: ${{ (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.sonar/cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
- name: Cache Maven packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.m2 | ||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-m2 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '17' | ||
|
||
- name: Create custom Maven Settings.xml | ||
uses: whelk-io/maven-settings-xml-action@v21 | ||
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_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
./mvnw -B -s custom_maven_settings.xml clean verify | ||
- name: Build and analyze (Push) | ||
if: ${{ github.event_name == 'push' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
./mvnw -B -s custom_maven_settings.xml clean verify | ||
- name: Save PR number to file | ||
if: github.event_name == 'pull_request' | ||
run: echo ${{ github.event.number }} > PR_NUMBER.txt | ||
- name: Archive PR number | ||
if: github.event_name == 'pull_request' | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: PR_NUMBER | ||
path: PR_NUMBER.txt |