Skip to content

Commit dc5762f

Browse files
authored
action: support github commands for the tav modules (#3246)
1 parent 5a91f6a commit dc5762f

File tree

3 files changed

+124
-13
lines changed

3 files changed

+124
-13
lines changed

.ci/generate-github-tav-matrix.sh

-5
This file was deleted.

.github/workflows/tav-command.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: tav-command
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
command-validation:
16+
if: startsWith(github.event.review.body, '/test tav')
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 5
19+
permissions:
20+
pull-requests: write
21+
outputs:
22+
versions: ${{ steps.transform.outputs.versions }}
23+
modules: ${{ steps.transform.outputs.modules }}
24+
steps:
25+
- name: Is comment allowed?
26+
uses: actions/github-script@v6
27+
with:
28+
script: |
29+
const actorPermission = (await github.rest.repos.getCollaboratorPermissionLevel({
30+
...context.repo,
31+
username: context.actor
32+
})).data.permission
33+
const isPermitted = ['write', 'admin'].includes(actorPermission)
34+
if (!isPermitted) {
35+
const errorMessage = 'Only users with write permission to the repository can run GitHub commands'
36+
await github.rest.issues.createComment({
37+
...context.repo,
38+
issue_number: context.issue.number,
39+
body: errorMessage,
40+
})
41+
core.setFailed(errorMessage)
42+
return;
43+
}
44+
45+
- uses: actions/checkout@v3
46+
with:
47+
ref: ${{ github.event.pull_request.head.sha }}
48+
49+
- id: transform
50+
name: Transform comment to the supported matrix
51+
uses: actions/github-script@v6
52+
with:
53+
script: |
54+
const fs = require('fs')
55+
56+
let modules, versions
57+
try {
58+
const matrix = JSON.parse(fs.readFileSync('./.ci/tav.json'))
59+
versions = matrix.versions
60+
modules = matrix.modules
61+
} catch (err) {
62+
core.setFailed(`Error loading './.ci/tav.json': ${err}`)
63+
return
64+
}
65+
const comment = context.payload.review.body
66+
if (comment !== '/test tav') {
67+
const regex = /\/test tav ([^\s]+)(\s*)([^\s]*)/
68+
const match = comment.match(regex)
69+
if (!match) {
70+
core.setFailed(`Incorrect comment, please use /test tav(\\s(module1,...,moduleN)?(\\s)?(node1,...,nodeN)?)?'`)
71+
return
72+
}
73+
if (match[1]) {
74+
if (match[1] !== 'all') {
75+
modules = match[1].split(',')
76+
}
77+
}
78+
if (match[3]) {
79+
versions = match[3].split(',')
80+
}
81+
}
82+
core.setOutput('modules', modules)
83+
core.setOutput('versions', versions)
84+
85+
test-tav:
86+
needs: command-validation
87+
runs-on: ubuntu-latest
88+
timeout-minutes: 40
89+
strategy:
90+
max-parallel: 15
91+
fail-fast: false
92+
matrix:
93+
node: ${{ fromJSON(needs.command-validation.outputs.versions) }}
94+
module: ${{ fromJSON(needs.command-validation.outputs.modules) }}
95+
steps:
96+
97+
- uses: actions/checkout@v3
98+
with:
99+
ref: ${{ github.event.pull_request.head.sha }}
100+
101+
- run: .ci/scripts/test.sh -b "release" -t "${{ matrix.module }}" "${{ matrix.node }}"
102+
env:
103+
ELASTIC_APM_CONTEXT_MANAGER: ''

.github/workflows/tav.yml

+21-8
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,34 @@ jobs:
2424
runs-on: ubuntu-latest
2525
timeout-minutes: 5
2626
outputs:
27-
versions: ${{ steps.generate-matrix.outputs.versions }}
28-
modules: ${{ steps.generate-matrix.outputs.modules }}
27+
versions: ${{ steps.transform.outputs.versions }}
28+
modules: ${{ steps.transform.outputs.modules }}
2929
steps:
30-
- uses: actions/checkout@v3
31-
## TODO: use elastic/apm-pipeline-library/.github/actions/version-framework
32-
## as soon as https://github.com/elastic/apm-pipeline-library/issues/2171 is done.
33-
- id: generate-matrix
34-
run: .ci/generate-github-tav-matrix.sh
30+
31+
- uses: actions/checkout@v3
32+
33+
- id: transform
34+
name: Load matrix from tav.json
35+
uses: actions/github-script@v6
36+
with:
37+
script: |
38+
const fs = require('fs')
39+
let matrix
40+
try {
41+
matrix = JSON.parse(fs.readFileSync('./.ci/tav.json'))
42+
} catch (err) {
43+
core.setFailed(`Error loading './.ci/tav.json': ${err}`)
44+
return
45+
}
46+
core.setOutput('modules', matrix.modules)
47+
core.setOutput('versions', matrix.versions)
3548
3649
test-tav:
3750
needs: prepare-matrix
3851
runs-on: ubuntu-latest
3952
timeout-minutes: 40
4053
strategy:
41-
max-parallel: 30
54+
max-parallel: 15
4255
fail-fast: false
4356
matrix:
4457
# A job matrix limit is 256. We do some grouping of TAV modules to

0 commit comments

Comments
 (0)