Skip to content

Commit 6edcdc8

Browse files
authored
simplify sonar workflow to only analyse master branch (#1601)
1 parent d076903 commit 6edcdc8

File tree

2 files changed

+11
-84
lines changed

2 files changed

+11
-84
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,3 @@ jobs:
176176
labels: ${{ steps.meta.outputs.labels }}
177177
secret-envs: |
178178
"dv-key=DEVELOCITY_ACCESS_KEY"
179-
180-
save-pr-number:
181-
permissions:
182-
contents: none
183-
runs-on: ubuntu-latest
184-
if: github.event_name == 'pull_request'
185-
steps:
186-
- name: Save PR number to file
187-
run: echo ${{ github.event.number }} > PR_NUMBER.txt
188-
189-
- name: Archive PR number
190-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
191-
with:
192-
name: PR_NUMBER
193-
path: PR_NUMBER.txt

.github/workflows/sonar.yml

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,43 @@
11
name: Sonar
22
on:
3-
workflow_run:
4-
workflows: [CI]
5-
types: [completed]
3+
push:
4+
branches:
5+
- master
66
jobs:
77
sonar:
88
name: Sonar
99
permissions:
10-
pull-requests: read
10+
contents: read
1111
runs-on: ubuntu-latest
12-
if: github.repository == 'eclipse/openvsx' && github.event.workflow_run.conclusion == 'success'
12+
if: github.repository == 'eclipse/openvsx'
1313
steps:
14-
- name: Create artifacts directory
15-
run: mkdir -p ${{ runner.temp }}/artifacts
16-
- name: Download PR number artifact
17-
if: github.event.workflow_run.event == 'pull_request'
18-
uses: dawidd6/action-download-artifact@0bd50d53a6d7fb5cb921e607957e9cc12b4ce392 # v12
19-
with:
20-
workflow: CI
21-
run_id: ${{ github.event.workflow_run.id }}
22-
path: ${{ runner.temp }}/artifacts
23-
name: PR_NUMBER
24-
- name: Read PR_NUMBER.txt
25-
if: github.event.workflow_run.event == 'pull_request'
26-
id: pr_number
27-
uses: juliangruber/read-file-action@b549046febe0fe86f8cb4f93c24e284433f9ab58 # v1.1.7
28-
with:
29-
path: ${{ runner.temp }}/artifacts/PR_NUMBER.txt
30-
- name: Request GitHub API for PR data
31-
if: github.event.workflow_run.event == 'pull_request'
32-
uses: octokit/request-action@05a2312de9f8207044c4c9e41fe19703986acc13 # v2.x
33-
id: get_pr_data
34-
with:
35-
route: GET /repos/{full_name}/pulls/{number}
36-
number: ${{ steps.pr_number.outputs.content }}
37-
full_name: ${{ github.event.repository.full_name }}
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
- name: Checkout head branch
14+
- name: Checkout
4115
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
4216
with:
43-
repository: ${{ github.event.workflow_run.head_repository.full_name }}
44-
ref: ${{ github.event.workflow_run.head_branch }}
4517
persist-credentials: false
4618
fetch-depth: 0
47-
- name: Checkout head branch of pull_request
48-
if: github.event.workflow_run.event == 'pull_request'
49-
env:
50-
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
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 $HEAD_BRANCH
56-
git clean -ffdx && git reset --hard HEAD
5719
- name: Cache SonarCloud packages
5820
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
5921
with:
6022
path: ~/.sonar/cache
6123
key: ${{ runner.os }}-sonar
6224
restore-keys: ${{ runner.os }}-sonar
63-
- name: Cache Gradle packages
64-
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
65-
with:
66-
path: ~/.gradle/caches
67-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
68-
restore-keys: ${{ runner.os }}-gradle
6925
- name: Set up JDK
7026
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
7127
with:
7228
distribution: 'temurin'
7329
java-version: 25
30+
- name: Setup Gradle
31+
uses: gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884 # v5
32+
with:
33+
dependency-graph: generate-and-submit
7434
- name: Generate JaCoCo test report
7535
run: server/gradlew --no-daemon -p server jacocoTestReport
7636
- name: Make server libraries directory
7737
run: mkdir server/libraries
7838
- name: Copy server libraries
7939
run: find ~/.gradle/caches -type f -name '*.jar' -exec cp {} server/libraries \;
80-
- name: SonarCloud Scan on PR
81-
if: github.event.workflow_run.event == 'pull_request'
82-
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
83-
env:
84-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
86-
with:
87-
args: >
88-
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
89-
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }}
90-
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }}
91-
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
92-
- name: SonarCloud Scan on push
93-
if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name
40+
- name: SonarCloud Scan
9441
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
9542
env:
96-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9743
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
98-
with:
99-
args: >
100-
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
101-
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}

0 commit comments

Comments
 (0)