After reading the documentation of the Events that trigger workflows, I wonder if it's possible to run a workflow with a given label name, like RFR or WIP.
I know we can run a workflow when the pull request is labeled, but there is nothing more for a specifc label name :
on:
pull_request:
types: [labeled]
Has anyone done this before ?
Label Actions is a GitHub bot that performs certain actions when issues, pull requests or discussions are labeled or unlabeled.
Secrets can be stored within GitHub at three different levels: the organization, a single repository, or a repository environment. The level at which the secret should be stored depends on its scope and intended use.
You can achieve running a workflow on labeling a Pull Request using a conditional expression like
if: ${{ github.event.label.name == 'label_name' }}
So if you have your GitHub action config as below
name: CI
on:
pull_request:
types: [ labeled ]
jobs:
build:
if: ${{ github.event.label.name == 'bug' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo Hello, world!
It would trigger the workflow whenever a PR is labeled and run the job only if the label is bug
and would skip if the label is anything else. You can also use github.event.action == 'labeled'
as an extra check but that is not required if you have only types: [ labeled ]
for the pull_request
as shown in the config above.
Note: Just for your information, the github event has the following info (removed the irrelevant data for brevity) regarding the label in case of labelling a PR
"event": {
"action": "labeled",
"label": {
"color": "d73a4a",
"default": true,
"description": "Something isn't working",
"id": 1519136641,
"name": "bug",
"node_id": "abcd",
"url": "https://api.github.com/repos/owner/repo/labels/bug"
}
}
GitHub actions documentation regarding conditional expressions is here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With