|
6 | 6 | branches: ["main"] |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - go_test: |
10 | | - if: ${{ github.event_name == 'push' }} |
| 9 | + confirm: |
| 10 | + # check if confirmation is necessary |
| 11 | + if: github.event_name == 'pull_request_target' |
| 12 | + # request confirmation |
| 13 | + environment: e2e |
11 | 14 | runs-on: ubuntu-latest |
12 | 15 | steps: |
13 | | - |
| 16 | + - run: ":" |
| 17 | + |
| 18 | + test: |
| 19 | + # check the result of confirmation if necessary |
| 20 | + # https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-not-requiring-successful-dependent-jobs |
| 21 | + # https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#always |
| 22 | + if: ${{ !cancelled() }} |
| 23 | + needs: [confirm] |
| 24 | + |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + |
| 28 | + - name: checkout PR ${{ github.event.pull_request.number }} |
| 29 | + if: github.event_name == 'pull_request_target' |
| 30 | + |
| 31 | + with: |
| 32 | + fetch-depth: 0 # for SonarQube |
| 33 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 34 | + ref: ${{ github.event.pull_request.head.ref }} |
| 35 | + |
| 36 | + - name: checkout |
| 37 | + if: github.event_name == 'push' |
| 38 | + |
14 | 39 | with: |
15 | | - fetch-depth: 0 # for sonarcloud |
| 40 | + fetch-depth: 0 # for SonarQube |
| 41 | + |
16 | 42 | - uses: actions/setup-go@v5 |
17 | 43 | with: |
18 | 44 | go-version-file: go.mod |
| 45 | + |
19 | 46 | - run: "make verify" |
20 | 47 | - run: "make test" |
21 | | - - uses: SonarSource/[email protected] |
22 | | - if: ${{ github.event_name == 'push' }} |
| 48 | + |
| 49 | + - name: SonarQube for PR ${{ github.event.pull_request.number }} |
| 50 | + if: github.event_name == 'pull_request_target' |
| 51 | + uses: SonarSource/[email protected] |
| 52 | + with: |
| 53 | + args: > |
| 54 | + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} |
| 55 | + -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} |
23 | 56 | env: |
24 | 57 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
25 | 58 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
26 | 59 |
|
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 | | - |
34 | | - with: |
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 |
| 60 | + - name: SonarQube |
| 61 | + if: github.event_name == 'push' |
| 62 | + uses: SonarSource/[email protected] |
| 63 | + env: |
| 64 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 65 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments