Skip to content

Commit 7006aec

Browse files
committed
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/ This partially reverts commit db85b48.
1 parent 01911ec commit 7006aec

File tree

2 files changed

+28
-45
lines changed

2 files changed

+28
-45
lines changed

.github/workflows/code-qa-sonarcloud.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
branches: ["main"]
55
pull_request:
66
types: ["opened", "synchronize", "reopened"]
7+
pull_request_target:
8+
types: ["opened", "synchronize", "reopened"]
9+
branches: ["main"]
710

811
jobs:
912
verify:
@@ -18,9 +21,33 @@ jobs:
1821
go_test:
1922
runs-on: ubuntu-latest
2023
steps:
21-
- uses: actions/[email protected]
24+
# If triggered by a push to **our** repository, we can directly checkout the code.
25+
- name: Checkout branch ${{ github.ref }}
26+
if: ${{ github.event_name == 'push' }}
27+
uses: actions/[email protected]
28+
with:
29+
# Disabling shallow clone is recommended for improving relevancy of reporting
30+
fetch-depth: 0
31+
32+
# If triggered by a PR, we have to check out the PR's source
33+
- name: Checkout (preview) merge commit for PR ${{ github.event.pull_request.number }}
34+
if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
35+
uses: actions/[email protected]
36+
with:
37+
# Disabling shallow clone is recommended for improving relevancy of reporting
38+
fetch-depth: 0
39+
repository: ${{ github.event.pull_request.head.repo.full_name }}
40+
ref: ${{ github.event.pull_request.head.ref }}
41+
2242
- uses: actions/setup-go@v4
2343
with:
2444
go-version-file: go.mod
45+
2546
- name: Run tests
2647
run: "make test"
48+
49+
- name: SonarCloud Scan
50+
uses: SonarSource/[email protected]
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
53+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)