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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…