Skip to content

PR Comment Trigger #111

PR Comment Trigger

PR Comment Trigger #111

name: PR Comment Trigger
on:
issue_comment:
types: [created]
jobs:
comment-check:
runs-on: ubuntu-latest
steps:
- name: Check if comment triggers E2E tests
if: ${{ (github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'CONTRIBUTOR' ) &&
github.event.issue.pull_request &&
contains(github.event.comment.body, '/test') }}
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.issue.number;
const repo = context.repo.repo;
const owner = context.repo.owner;
// Extract the tagname from the comment
const commentBody = context.payload.comment.body.trim();
const tagMatch = commentBody.match(/^\/test\s+(\S+)/);
if (!tagMatch) {
throw new Error('Comment must be in the format: /test tagname');
}
const tagname = tagMatch[1];
await github.rest.actions.createWorkflowDispatch({
owner: owner,
repo: repo,
workflow_id: 'e2e.yaml',
ref: context.ref,
inputs: {
pr_number: prNumber.toString(),
tag: tagname,
}
}).catch(error => error).then(response => {
core.debug(response);
if (response.status !== 204) {
core.setFailed(`create workflow_dispatch received status code ${response.status}`);
}
});