tav-command #428
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v6 | |
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@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- id: transform | |
name: Transform comment to the supported matrix | |
uses: actions/github-script@v6 | |
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) { | |
if (mod.minVersion && nv >= mod.minVersion) { | |
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@v3 | |
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: '' |