|
| 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: '' |
0 commit comments