Skip to content

Commit f481068

Browse files
authored
github/workflows: test improvements (#436)
1 parent f08e004 commit f481068

File tree

4 files changed

+75
-92
lines changed

4 files changed

+75
-92
lines changed

.github/workflows/comment.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Comment
2+
3+
on:
4+
pull_request_target:
5+
types: ["opened"]
6+
branches: ["main"]
7+
8+
jobs:
9+
comment:
10+
runs-on: ubuntu-latest
11+
permissions: write-all
12+
steps:
13+
- uses: thollander/actions-comment-pull-request@v3
14+
with:
15+
message: |
16+
### Tests
17+
Please note that running unit and e2e tests requires manual approval from a team member.
18+
19+
### e2e tests
20+
We use labels to control which e2e tests contexts are run:
21+
22+
| Label | Behaviour |
23+
|--|--|
24+
| none | Run `Generic` tests only |
25+
| https://github.com/ionos-cloud/cluster-api-provider-proxmox/labels/e2e%2Fnone | Do not run any e2e tests |
26+
| https://github.com/ionos-cloud/cluster-api-provider-proxmox/labels/e2e%2Fflatcar | Add `Flatcar` tests |
27+
28+
ℹ️ Ask a team member to add the requested labels if you don't have enough permissions.
29+
comment_tag: comment
30+
mode: "recreate"

.github/workflows/e2e-comment.yml

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

.github/workflows/test-external.yml

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

.github/workflows/test.yml

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,60 @@ on:
66
branches: ["main"]
77

88
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
1114
runs-on: ubuntu-latest
1215
steps:
13-
- uses: actions/[email protected]
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+
uses: actions/[email protected]
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+
uses: actions/[email protected]
1439
with:
15-
fetch-depth: 0 # for sonarcloud
40+
fetch-depth: 0 # for SonarQube
41+
1642
- uses: actions/setup-go@v5
1743
with:
1844
go-version-file: go.mod
45+
1946
- run: "make verify"
2047
- 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 }}
2356
env:
2457
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2558
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
2659

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-
- uses: actions/[email protected]
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

Comments
 (0)