Skip to content

Commit 34f9263

Browse files
authored
Merge pull request #297 from com-pas/develop
Merge develop into main
2 parents 1fa7bc8 + f93a527 commit 34f9263

File tree

12 files changed

+647
-288
lines changed

12 files changed

+647
-288
lines changed

.github/workflows/sonarcloud-analysis.yml

Lines changed: 92 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,102 @@
44

55
name: SonarCloud Analysis
66

7-
on: push
7+
on:
8+
workflow_run:
9+
workflows: [SonarCloud Build]
10+
types: [completed]
811

912
jobs:
10-
build:
11-
name: Build
13+
sonarcloud:
14+
name: SonarCloud
1215
runs-on: ubuntu-latest
16+
if: github.event.workflow_run.conclusion == 'success'
1317
timeout-minutes: 15
14-
15-
if: ${{ (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
1618
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v3
19-
with:
20-
fetch-depth: 0
21-
22-
- name: Cache SonarCloud packages
23-
uses: actions/cache@v3
24-
with:
25-
path: ~/.sonar/cache
26-
key: ${{ runner.os }}-sonar
27-
restore-keys: ${{ runner.os }}-sonar
28-
29-
- name: Set up JDK 17
30-
uses: actions/setup-java@v3
31-
with:
32-
distribution: 'zulu'
33-
java-version: '17'
34-
cache: 'maven'
19+
- name: echo event
20+
run: cat $GITHUB_EVENT_PATH
21+
- name: Download PR number artifact
22+
if: github.event.workflow_run.event == 'pull_request'
23+
uses: dawidd6/action-download-artifact@v2
24+
with:
25+
workflow: SonarCloud Build
26+
run_id: ${{ github.event.workflow_run.id }}
27+
name: PR_NUMBER
28+
- name: Read PR_NUMBER.txt
29+
if: github.event.workflow_run.event == 'pull_request'
30+
id: pr_number
31+
uses: juliangruber/read-file-action@v1
32+
with:
33+
path: ./PR_NUMBER.txt
34+
- name: Request GitHub API for PR data
35+
if: github.event.workflow_run.event == 'pull_request'
36+
uses: octokit/[email protected]
37+
id: get_pr_data
38+
with:
39+
route: GET /repos/{full_name}/pulls/{number}
40+
number: ${{ steps.pr_number.outputs.content }}
41+
full_name: ${{ github.event.repository.full_name }}
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
- uses: actions/checkout@v3
45+
with:
46+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
47+
ref: ${{ github.event.workflow_run.head_branch }}
48+
fetch-depth: 0
49+
- name: Checkout base branch
50+
if: github.event.workflow_run.event == 'pull_request'
51+
run: |
52+
git remote add upstream ${{ github.event.repository.clone_url }}
53+
git fetch upstream
54+
git checkout -B ${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} upstream/${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
55+
git checkout ${{ github.event.workflow_run.head_branch }}
56+
git clean -ffdx && git reset --hard HEAD
57+
- name: Cache SonarCloud packages
58+
uses: actions/cache@v3
59+
with:
60+
path: ~/.sonar/cache
61+
key: ${{ runner.os }}-sonar
62+
restore-keys: ${{ runner.os }}-sonar
3563

36-
- name: Set Common Sonar Variables
37-
id: sonar_env
38-
run: |
39-
echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
40-
-Dsonar.projectKey=com-pas_compas-sct \
41-
-Dsonar.organization=com-pas )"
42-
- name: Create custom Maven Settings.xml
43-
uses: whelk-io/maven-settings-xml-action@v21
44-
with:
45-
output_file: custom_maven_settings.xml
46-
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
64+
- name: Set up JDK 17
65+
uses: actions/setup-java@v3
66+
with:
67+
distribution: 'zulu'
68+
java-version: '17'
69+
cache: 'maven'
4770

48-
- name: Build and analyze (Pull Request)
49-
if: ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
50-
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
53-
run: |
54-
mvn -B -s custom_maven_settings.xml \
55-
${{ steps.sonar_env.outputs.sonar_opts }} \
56-
-Dsonar.pullrequest.branch=${{ github.ref_name }} \
57-
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
58-
-Dsonar.pullrequest.base=${{ github.base_ref }} \
59-
-Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
60-
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
61-
- name: Build and analyze (Push)
62-
if: ${{ github.event_name == 'push' }}
63-
env:
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
66-
run: |
67-
mvn -B -s custom_maven_settings.xml \
68-
${{ steps.sonar_env.outputs.sonar_opts }} \
69-
-Dsonar.branch.name=${{ github.ref_name }} \
70-
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
71+
- name: Set Common Sonar Variables
72+
id: sonar_env
73+
run: |
74+
echo "##[set-output name=sonar_opts;]$(echo -Dsonar.host.url=https://sonarcloud.io \
75+
-Dsonar.projectKey=com-pas_compas-sct \
76+
-Dsonar.organization=com-pas )"
77+
- name: Create custom Maven Settings.xml
78+
uses: whelk-io/maven-settings-xml-action@v21
79+
with:
80+
output_file: custom_maven_settings.xml
81+
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
82+
- name: Build and analyze (Pull Request)
83+
if: ${{ github.event.workflow_run.event == 'pull_request' || (github.event.workflow_run.actor == 'dependabot[bot]' && github.event.workflow_run.event == 'pull_request_target') }}
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
87+
run: |
88+
mvn -B -s custom_maven_settings.xml \
89+
${{ steps.sonar_env.outputs.sonar_opts }} \
90+
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }} \
91+
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }} \
92+
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }} \
93+
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
94+
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
95+
- name: Build and analyze (Push)
96+
if: ${{ github.event.workflow_run.event == 'push' }}
97+
env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
100+
run: |
101+
mvn -B -s custom_maven_settings.xml \
102+
${{ steps.sonar_env.outputs.sonar_opts }} \
103+
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
104+
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }} \
105+
clean verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# SPDX-FileCopyrightText: 2022 RTE FRANCE
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: SonarCloud Build
6+
7+
on: push
8+
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
if: ${{ (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Cache SonarCloud packages
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.sonar/cache
26+
key: ${{ runner.os }}-sonar
27+
restore-keys: ${{ runner.os }}-sonar
28+
29+
- name: Set up JDK 17
30+
uses: actions/setup-java@v3
31+
with:
32+
distribution: 'zulu'
33+
java-version: '17'
34+
cache: 'maven'
35+
36+
- name: Create custom Maven Settings.xml
37+
uses: whelk-io/maven-settings-xml-action@v21
38+
with:
39+
output_file: custom_maven_settings.xml
40+
servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]'
41+
- name: Build and analyze (Pull Request)
42+
if: ${{ github.event_name == 'pull_request' || (github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target') }}
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
run: |
46+
mvn -B -s custom_maven_settings.xml clean verify
47+
- name: Build and analyze (Push)
48+
if: ${{ github.event_name == 'push' }}
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
mvn -B -s custom_maven_settings.xml clean verify
53+
- name: Save PR number to file
54+
if: github.event_name == 'pull_request'
55+
run: echo ${{ github.event.number }} > PR_NUMBER.txt
56+
- name: Archive PR number
57+
if: github.event_name == 'pull_request'
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: PR_NUMBER
61+
path: PR_NUMBER.txt
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2021 RTE FRANCE
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
config.stopBubbling = true
5+
lombok.addLombokGeneratedAnnotation = true

0 commit comments

Comments
 (0)