-
Notifications
You must be signed in to change notification settings - Fork 225
150 lines (135 loc) · 4.98 KB
/
tav-command.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: tav-command
on:
pull_request_review:
types: [submitted]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
permissions:
contents: read
jobs:
command-validation:
if: startsWith(github.event.review.body, '/test tav')
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
pull-requests: write
outputs:
permutations: ${{ steps.transform.outputs.permutations }}
steps:
- name: Is comment allowed?
uses: actions/github-script@v7
with:
script: |
const actorPermission = (await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo,
username: context.actor
})).data.permission
const isPermitted = ['write', 'admin'].includes(actorPermission)
if (!isPermitted) {
const errorMessage = 'Only users with write permission to the repository can run GitHub commands'
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: errorMessage,
})
core.setFailed(errorMessage)
return;
}
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- id: transform
name: Transform comment to the supported matrix
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
let modules, versions
try {
const matrix = JSON.parse(fs.readFileSync('./.ci/tav.json'));
versions = matrix.versions
modules = matrix.modules
} catch (err) {
core.setFailed(`Error loading './.ci/tav.json': ${err}`)
return
}
const getPermutations = (mods, vers) => {
const permutations = []
for (const mod of mods) {
for (const nv of vers) {
const nvMajor = Number(nv.split('.')[0]);
if (mod.minMajorVersion && nvMajor >= mod.minMajorVersion) {
permutations.push(`${mod.name} ${nv}`)
}
}
}
return permutations
}
const comment = context.payload.review.body
if (comment === '/test tav') {
const permutations = getPermutations(modules, versions)
if (permutations.length > 256) {
core.setFailed(`Matrix size (${permutations.length}) is bigger than the limit (256)`)
} else {
core.setOutput('permutations', permutations)
}
return
}
const regex = /\/test tav ([^\s]+)(\s*)([^\s]*)/
const match = comment.match(regex)
if (!match) {
core.setFailed(`Incorrect comment, please use /test tav(\\s(module1,...,moduleN)?(\\s)?(node1,...,nodeN)?)?'`)
return
}
const resolvedModules = []
const resolvedVersions = []
let inputNames, inputVersions
if (match[1]) {
if (match[1] === 'all') {
resolvedModules.push(...modules)
} else {
inputNames = match[1].split(',')
for (const name of inputNames) {
const mod = modules.find((m) => m.name === name)
if (mod) {
resolvedModules.push(mod)
} else {
core.setFailed(`Incorrect module name ${name}, please review it`)
return
}
}
}
}
if (match[3]) {
inputVersions = match[3].split(',').map(Number)
if (inputVersions.some((v) => isNaN(v))) {
core.setFailed(`Incorrect versions list ${match[3]}, please review it`)
return
}
resolvedVersions.push(...inputVersions)
} else {
resolvedVersions.push(...versions)
}
const permutations = getPermutations(resolvedModules, resolvedVersions)
if (permutations.length > 256) {
core.setFailed(`Matrix size (${permutations.length}) is bigger than the limit (256)`)
return
}
core.setOutput('permutations', permutations)
test-tav:
needs: command-validation
runs-on: ubuntu-latest
timeout-minutes: 40
strategy:
max-parallel: 15
fail-fast: false
matrix:
module_and_node: ${{ fromJSON(needs.command-validation.outputs.permutations) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: .ci/scripts/test.sh -b "release" -t ${{ matrix.module_and_node }}
env:
ELASTIC_APM_CONTEXT_MANAGER: ''