Skip to content

Commit 8d9cbf5

Browse files
committed
workflows: test improvements
1 parent b6b4a56 commit 8d9cbf5

File tree

6 files changed

+148
-101
lines changed

6 files changed

+148
-101
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/run-tests.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Run tests
2+
on:
3+
workflow_call:
4+
inputs:
5+
event_name:
6+
required: true
7+
type: string
8+
pr:
9+
required: false
10+
type: number
11+
repo:
12+
required: false
13+
type: string
14+
ref:
15+
required: false
16+
type: string
17+
secrets:
18+
GITHUB_TOKEN:
19+
required: true
20+
SONAR_TOKEN:
21+
required: true
22+
23+
jobs:
24+
go_test:
25+
runs-on: ubuntu-latest
26+
steps:
27+
28+
- name: checkout PR ${{ inputs.pr }}
29+
if: ${{ inputs.event_name == 'pull_request_target' }}
30+
uses: actions/[email protected]
31+
with:
32+
fetch-depth: 0 # for SonarQube
33+
repository: ${{ inputs.repo }}
34+
ref: ${{ inputs.ref }}
35+
36+
- name: checkout
37+
- uses: actions/[email protected]
38+
if: ${{ inputs.event_name == 'push' }}
39+
with:
40+
fetch-depth: 0 # for SonarQube
41+
42+
- uses: actions/setup-go@v5
43+
with:
44+
go-version-file: go.mod
45+
46+
- run: "make verify"
47+
- run: "make test"
48+
49+
- name: SonarQube for PR ${{ inputs.pr }}
50+
if: ${{ inputs.event_name == 'pull_request_target' }}
51+
uses: SonarSource/[email protected]
52+
with:
53+
args: >
54+
-Dsonar.pullrequest.key=${{ inputs.pr }}
55+
-Dsonar.scm.revision=${{ inputs.sha }}
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
59+
60+
- name: SonarQube
61+
if: ${{ inputs.event_name == 'push' }}
62+
uses: SonarSource/[email protected]
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/test-comment.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Test 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+
- name: PR comment with file
14+
uses: thollander/actions-comment-pull-request@v3
15+
with:
16+
message: |
17+
### Tests
18+
Please note that running unit and e2e tests requires manual approval from a team member.
19+
20+
### e2e tests
21+
We use labels to control which e2e tests contexts are run:
22+
23+
| Label | Behaviour |
24+
|--|--|
25+
| none | Run `Generic` tests only |
26+
| https://github.com/ionos-cloud/cluster-api-provider-proxmox/labels/e2e%2Fnone | Do not run any e2e tests |
27+
| https://github.com/ionos-cloud/cluster-api-provider-proxmox/labels/e2e%2Fflatcar | Add `Flatcar` tests |
28+
29+
ℹ️ Ask a team member to add the requested labels if you don't have enough permissions.
30+
comment_tag: test-comment
31+
mode: "recreate"

.github/workflows/test-external.yml

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

.github/workflows/test.yml

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

88
jobs:
9-
go_test:
10-
if: ${{ github.event_name == 'push' }}
11-
runs-on: ubuntu-latest
12-
steps:
13-
- uses: actions/[email protected]
14-
with:
15-
fetch-depth: 0 # for sonarcloud
16-
- uses: actions/setup-go@v5
17-
with:
18-
go-version-file: go.mod
19-
- run: "make verify"
20-
- run: "make test"
21-
- uses: SonarSource/[email protected]
22-
if: ${{ github.event_name == 'push' }}
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
269

27-
ext_pr:
10+
pr-test:
2811
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
12+
environment: e2e # request confirmation
13+
uses: ./.github/workflows/run-tests.yml
14+
with:
15+
inputs:
16+
event_name: ${{ github.event_name }}
17+
pr: ${{ inputs.event.pull_request.number }}
18+
repo: ${{ github.event.pull_request.head.repo.full_name }}
19+
ref: ${{ github.event.pull_request.head.ref }}
20+
sha: ${{ github.event.pull_request.head.sha }}
21+
secrets:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4724

48-
- uses: thollander/actions-comment-pull-request@v3
49-
with:
50-
comment_tag: test
51-
mode: recreate
52-
file-path: ${{ runner.temp }}/msg
25+
main-test:
26+
if: ${{ github.event_name == 'push' }}
27+
uses: ./.github/workflows/run-tests.yml
28+
with:
29+
inputs:
30+
event_name: ${{ github.event_name }}
31+
secrets:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

0 commit comments

Comments
 (0)