-
Notifications
You must be signed in to change notification settings - Fork 48
95 lines (91 loc) · 3.41 KB
/
testing-needed.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: testing-needed
on:
pull_request_target:
types:
- synchronize
- opened
- reopened
- labeled
- unlabeled
jobs:
verify-change:
runs-on: ubuntu-latest
outputs:
label_names: ${{ steps.update-label.outputs.label_names }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
# The pull_request_target event runs in the context of the PR's BASE.
# We need to checkout the PR's HEAD to be able to check the diff.
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check diff
id: check-diff
run: |
loc=$(git diff --shortstat HEAD ${{ github.sha }} | awk '{print $4+$6}')
echo "Lines of change: $loc"
echo "lines_of_change=$loc" >> $GITHUB_OUTPUT
- name: Update label
id: update-label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# TODO: Add testing-needed-e2e-full label once the internal pipeline
# supports running e2e-full tests with the VM-Operator build from PR.
script: |
if (${{ steps.check-diff.outputs.lines_of_change > 99 }}) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['testing-needed-e2e-fast']
})
} else {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'testing-needed-e2e-fast'
})
} catch (e) {
if (e.status !== 404) {
throw e
}
}
}
const labels = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const label_names = labels.data.map(label => label.name)
core.info('Current label names: ' + label_names)
core.setOutput('label_names', label_names)
check-label:
strategy:
matrix:
# the types of tests that are expressed as labels, ex. for the test
# type "e2e-fast", the labels would be testing-needed-e2e-fast and
# testing-done-e2e-fast
test-type:
- e2e-fast
- e2e-full
runs-on: ubuntu-latest
needs: verify-change
steps:
- name: do-not-merge
env:
LABEL_NAMES: ${{ needs.verify-change.outputs.label_names }}
# This step will run if one of the labels is present and the related
# label indicating testing is done is not present, ex. the label
# testing-needed-e2e-fast is present without also testing-done-e2e-fast.
# Additionally, it should never run if testing-done-e2e-full is present.
if: |
contains(env.LABEL_NAMES, format('testing-needed-{0}', matrix.test-type)) &&
!contains(env.LABEL_NAMES, format('testing-done-{0}', matrix.test-type)) &&
!contains(env.LABEL_NAMES, 'testing-done-e2e-full')
run: |
echo "Pull request is labeled as 'testing-needed-${{ matrix.test-type }}'"
exit 1