Skip to content

Commit f36835a

Browse files
committed
Change how Sonar is invoked
Change both the main and PR GHAs to deal differently with Sonar. Sonar can be run separately for main. For PR's Sonar should only run if the PR comes from a non-forked branch. Furthermore, by separating the build from sonar, we ensure the build is still done at all times #enhancement/gha-sonar
1 parent 26d73cb commit f36835a

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,18 @@ jobs:
4040
restore-keys: |
4141
${{ runner.os }}-maven
4242
43-
- name: Maven operation with Sonar
43+
- name: Regular Build
44+
run: |
45+
./mvnw -B -U clean verify
46+
47+
- name: Sonar Analysis
4448
if: matrix.sonar-enabled
4549
run: |
46-
mvn -B -U -Pcoverage \
47-
clean verify \
48-
sonar:sonar \
50+
./mvnw -B -Pcoverage sonar:sonar \
4951
-Dsonar.projectKey=AxonFramework_extension-kotlin \
5052
-Dsonar.organization=axonframework \
5153
-Dsonar.host.url=https://sonarcloud.io \
5254
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
53-
env:
54-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55-
56-
- name: Maven operation without Sonar
57-
if: matrix.sonar-enabled != true
58-
run: |
59-
mvn -B -U clean verify
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6255
6356
- name: Deploy to Sonatype
6457
if: success()

.github/workflows/pullrequest.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
sonar-enabled: false
1515
- java-version: 11
1616
sonar-enabled: true
17+
fail-fast: false
1718

1819
steps:
1920
- name: Checkout code
@@ -36,22 +37,15 @@ jobs:
3637
restore-keys: |
3738
${{ runner.os }}-maven
3839
39-
- name: Maven operation with Sonar
40-
if: matrix.sonar-enabled
40+
- name: Regular Build
4141
run: |
42-
mvn -B -U -Pcoverage \
43-
clean verify \
44-
sonar:sonar \
42+
./mvnw -B -U clean verify
43+
44+
- name: Sonar Analysis
45+
if: ${{ success() && matrix.sonar-enabled && github.event.pull_request.head.repo.full_name == github.repository }}
46+
run: |
47+
./mvnw -B -Pcoverage sonar:sonar \
4548
-Dsonar.projectKey=AxonFramework_extension-kotlin \
4649
-Dsonar.organization=axonframework \
4750
-Dsonar.host.url=https://sonarcloud.io \
4851
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
49-
env:
50-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51-
52-
- name: Maven operation without Sonar
53-
if: matrix.sonar-enabled != true
54-
run: |
55-
mvn -B -U clean verify
56-
env:
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)