Skip to content

Commit db85b48

Browse files
ci: run sonarcloud via pull_request_target (#43)
`on.pull_request` executes the workflow out of a forked repository. This means the `SONAR_TOKEN` secret will not be available and therefore the workflow will fail. By changing it to `on.pull_request_target`, the workflow definition (and code) from the trusted original repository is run and the secret will be available. see https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/ Co-authored-by: Mohamed Chiheb Ben Jemaa <[email protected]>
1 parent 8f39b1a commit db85b48

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Code QA - SonarCloud
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request_target:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
branches:
13+
- main
14+
paths-ignore:
15+
- '.github/**'
16+
17+
jobs:
18+
sonarcloud:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
# If triggered by a push to **our** repository, we can directly checkout the code.
23+
- name: Checkout branch ${{ github.ref }}
24+
if: ${{ github.event_name == 'push' }}
25+
uses: actions/[email protected]
26+
with:
27+
# Disabling shallow clone is recommended for improving relevancy of reporting
28+
fetch-depth: 0
29+
30+
# If triggered by a PR, we have to check out the PR's source
31+
- name: Checkout (preview) merge commit for PR ${{ github.event.pull_request.number }}
32+
if: ${{ github.event_name == 'pull_request_target' }}
33+
uses: actions/[email protected]
34+
with:
35+
# Disabling shallow clone is recommended for improving relevancy of reporting
36+
fetch-depth: 0
37+
repository: ${{ github.event.pull_request.head.repo.full_name }}
38+
ref: ${{ github.event.pull_request.head.ref }}
39+
40+
- name: SonarCloud Scan
41+
uses: SonarSource/[email protected]
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
44+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/test.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,3 @@ jobs:
2424
go-version-file: go.mod
2525
- name: Run tests
2626
run: "make test"
27-
28-
- name: SonarCloud Scan
29-
uses: SonarSource/[email protected]
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
32-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)