|
3 | 3 | push: |
4 | 4 | branches: ["main"] |
5 | 5 | pull_request_target: |
6 | | - types: ["opened", "synchronize", "reopened"] |
7 | 6 | branches: ["main"] |
8 | 7 |
|
9 | 8 | jobs: |
10 | 9 | go_test: |
| 10 | + if: ${{ github.event_name == 'push' }} |
11 | 11 | runs-on: ubuntu-latest |
12 | 12 | steps: |
13 | | - # If triggered by a push to **our** repository, we can directly checkout the code. |
14 | | - - name: Checkout branch ${{ github.ref }} |
15 | | - if: ${{ github.event_name == 'push' }} |
16 | | - |
17 | | - with: |
18 | | - # Disabling shallow clone is recommended for improving relevancy of reporting |
19 | | - fetch-depth: 0 |
20 | | - |
21 | | - # If triggered by a PR, we have to check out the PR's source |
22 | | - - name: Checkout (preview) merge commit for PR ${{ github.event.pull_request.number }} |
23 | | - if: ${{ github.event_name == 'pull_request_target' }} |
24 | | - |
| 13 | + |
25 | 14 | with: |
26 | | - # Disabling shallow clone is recommended for improving relevancy of reporting |
27 | | - fetch-depth: 0 |
28 | | - repository: ${{ github.event.pull_request.head.repo.full_name }} |
29 | | - ref: ${{ github.event.pull_request.head.ref }} |
30 | | - |
| 15 | + fetch-depth: 0 # for sonarcloud |
31 | 16 | - uses: actions/setup-go@v5 |
32 | 17 | with: |
33 | 18 | go-version-file: go.mod |
34 | | - |
35 | | - - name: Verify |
36 | | - run: "make verify" |
37 | | - |
38 | | - - name: Run tests |
39 | | - run: "make test" |
40 | | - |
41 | | - - name: SonarCloud Scan ${{ github.ref }} |
42 | | - uses: SonarSource/[email protected] |
| 19 | + - run: "make verify" |
| 20 | + - run: "make test" |
| 21 | + - uses: SonarSource/[email protected] |
43 | 22 | if: ${{ github.event_name == 'push' }} |
44 | 23 | env: |
45 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 24 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
46 | 25 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
47 | 26 |
|
48 | | - # If triggered by a PR, we have to use the PR's source |
49 | | - - name: SonarCloud Scan (preview) merge commit for PR ${{ github.event.pull_request.number }} |
50 | | - uses: SonarSource/[email protected] |
51 | | - if: ${{ github.event_name == 'pull_request_target' }} |
| 27 | + ext_pr: |
| 28 | + if: ${{ github.event_name == 'pull_request_target' }} |
| 29 | + runs-on: ubuntu-latest |
| 30 | + permissions: |
| 31 | + pull-requests: write |
| 32 | + steps: |
| 33 | + |
52 | 34 | with: |
53 | | - args: > |
54 | | - -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
55 | | - -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} |
56 | | - env: |
57 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
58 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 35 | + fetch-depth: 2 # for diff |
| 36 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 37 | + ref: ${{ github.event.pull_request.head.ref }} |
| 38 | + |
| 39 | + - name: generate comment message |
| 40 | + run: | |
| 41 | + printf '%s\n%s\n\n' '### External PR' 'Test runs on external PRs require manual approval.' >"${{ runner.temp }}/msg" |
| 42 | + git diff --name-only -z HEAD^1 HEAD | grep -Evz '\.go$|^docs/' | tr '\0' '\n' >"${{ runner.temp }}/diff" |
| 43 | + if [ -s '${{ runner.temp }}'/diff ]; then |
| 44 | + echo '**Note:** This PR changes the following non-go, non-docs files:' >>"${{ runner.temp }}/msg" |
| 45 | + cat "${{ runner.temp }}/diff" >>"${{ runner.temp }}/msg" |
| 46 | + fi |
| 47 | +
|
| 48 | + - uses: thollander/actions-comment-pull-request@v3 |
| 49 | + with: |
| 50 | + comment_tag: test |
| 51 | + mode: recreate |
| 52 | + file-path: ${{ runner.temp }}/msg |
0 commit comments