Skip to content

Commit

Permalink
Add PR review comment command (#1960)
Browse files Browse the repository at this point in the history
* Add PR review comment command

* Add to README.md

* Update .github/workflows/README.md

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>

* Update .github/workflows/test.yml

---------

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
  • Loading branch information
2 people authored and xrmx committed Mar 20, 2024
1 parent 5dba4f2 commit bda718f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Once a PR has been opened then there are two different ways you can trigger buil

1. Commit based
1. UI based, any Elasticians can force a build through the GitHub UI
1. PR review comment-based, any Elastic employees can force a full matrix test run through a PR review comment with the following syntax: `/test matrix`.

#### Branches

Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/matrix-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: matrix-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 matrix')
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
pull-requests: write
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
}
test:
needs:
- command-validation
uses: ./.github/workflows/test.yml
with:
full-matrix: true
ref: ${{ github.event.pull_request.head.sha }}
23 changes: 19 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
name: test # The name must be the same as in test-docs.yml

on:
workflow_call: ~
workflow_call:
inputs:
full-matrix:
description: "Run the full matrix"
required: true
type: boolean
ref:
description: "The git ref of elastic/apm-agent-python to run test workflow from."
required: false
type: string
pull_request:
paths-ignore:
- "**/*.md"
Expand Down Expand Up @@ -32,7 +41,9 @@ jobs:
data: ${{ steps.split.outputs.data }}
chunks: ${{ steps.split.outputs.chunks }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- id: generate
uses: elastic/apm-pipeline-library/.github/actions/version-framework@current
with:
Expand Down Expand Up @@ -113,7 +124,9 @@ jobs:
FRAMEWORK: ${{ matrix.framework }}
ASYNCIO: ${{ matrix.asyncio }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version }}
Expand Down Expand Up @@ -168,7 +181,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}

- uses: actions/setup-python@v4
with:
Expand Down

0 comments on commit bda718f

Please sign in to comment.