Skip to content

Commit 91efaee

Browse files
committed
CI: trigger per-commit workflow on PRs with ci:per-commit label
1 parent 4c870ed commit 91efaee

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

.github/workflows/ci-per-commit.yaml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
push:
55
branches:
66
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, labeled]
9+
branches:
10+
- main
711

812
jobs:
913
check-label:
@@ -12,24 +16,31 @@ jobs:
1216
outputs:
1317
has_label: ${{ steps.check.outputs.has_label }}
1418
steps:
15-
- name: Find associated PR and check label
19+
- name: Check for label
1620
id: check
1721
env:
1822
GH_TOKEN: ${{ github.token }}
1923
run: |
20-
PRS=$(gh api \
21-
"repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \
22-
--jq '.[].number')
2324
HAS_LABEL="false"
24-
for pr in $PRS; do
25-
LABELS=$(gh api \
26-
"repos/${{ github.repository }}/pulls/${pr}" \
27-
--jq '.labels[].name')
28-
if echo "$LABELS" | grep -q "^ci:per-commit$"; then
25+
if [ "${{ github.event_name }}" = "pull_request" ]; then
26+
LABELS='${{ toJSON(github.event.pull_request.labels.*.name) }}'
27+
if echo "$LABELS" | grep -q "ci:per-commit"; then
2928
HAS_LABEL="true"
30-
break
3129
fi
32-
done
30+
else
31+
PRS=$(gh api \
32+
"repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \
33+
--jq '.[].number')
34+
for pr in $PRS; do
35+
LABELS=$(gh api \
36+
"repos/${{ github.repository }}/pulls/${pr}" \
37+
--jq '.labels[].name')
38+
if echo "$LABELS" | grep -q "^ci:per-commit$"; then
39+
HAS_LABEL="true"
40+
break
41+
fi
42+
done
43+
fi
3344
echo "has_label=${HAS_LABEL}" >> "$GITHUB_OUTPUT"
3445
3546
ci:

0 commit comments

Comments
 (0)