You could use a slash command style "ChatOps" solution. The action slash-command-dispatch can help you trigger workflows with slash commands (e.g. /build
) from issue and pull request comments.
Here is a basic example for a build
slash command in pull request comments. REPO_ACCESS_TOKEN
is a repo
scoped Personal Access Token
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v2
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
commands: build
issue-type: pull-request
The command can be processed in this workflow.
name: Build Command
on:
repository_dispatch:
types: [build-command]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the pull request branch
- uses: actions/checkout@v2
with:
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}
path: ${{ github.event.repository.name }}
token: ${{ secrets.REPO_ACCESS_TOKEN }}
If you pass arguments to the slash command they will be passed with the payload. For example, the branch name.
/build ref=their-feature-branch
Then in the workflow you can checkout the branch passed via argument ref
.
- uses: actions/checkout@v2
with:
repository: backend-repo
ref: ${{ github.event.client_payload.slash_command.args.named.ref }}
path: backend-repo
token: ${{ secrets.REPO_ACCESS_TOKEN }}
This is just a very brief look at what you could do with slash-command-dispatch action. Please check out the repository for full details.