File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ # Check if the ci:per-commit label is present.
3+ #
4+ # For pull_request events, checks labels from the event payload.
5+ # For push events, looks up the originating PR via the GitHub API.
6+ #
7+ # Usage:
8+ # check-ci-per-commit-label.sh <event_name> <repository> <sha> [labels_json]
9+ #
10+ # Arguments:
11+ # event_name - "pull_request" or "push"
12+ # repository - e.g. "owner/repo"
13+ # sha - commit SHA
14+ # labels_json - JSON array of label names (required for pull_request)
15+ #
16+ # Output:
17+ # Prints has_label=true or has_label=false (for GITHUB_OUTPUT)
18+ set -euo pipefail
19+
20+ event_name=" ${1:? Usage: check-ci-per-commit-label.sh <event_name> <repository> <sha> [labels_json]} "
21+ repository=" ${2:? Missing repository} "
22+ sha=" ${3:? Missing sha} "
23+ labels_json=" ${4:- } "
24+
25+ HAS_LABEL=" false"
26+
27+ if [ " $event_name " = " pull_request" ]; then
28+ if echo " $labels_json " | grep -q " ci:per-commit" ; then
29+ HAS_LABEL=" true"
30+ fi
31+ else
32+ PRS=$( gh api \
33+ " repos/${repository} /commits/${sha} /pulls" \
34+ --jq ' .[].number' )
35+ for pr in $PRS ; do
36+ LABELS=$( gh api \
37+ " repos/${repository} /pulls/${pr} " \
38+ --jq ' .labels[].name' )
39+ if echo " $LABELS " | grep -q " ^ci:per-commit$" ; then
40+ HAS_LABEL=" true"
41+ break
42+ fi
43+ done
44+ fi
45+
46+ echo " has_label=${HAS_LABEL} "
Original file line number Diff line number Diff line change @@ -16,32 +16,18 @@ jobs:
1616 outputs :
1717 has_label : ${{ steps.check.outputs.has_label }}
1818 steps :
19+ - uses : actions/checkout@v6
1920 - name : Check for label
2021 id : check
2122 env :
2223 GH_TOKEN : ${{ github.token }}
2324 run : |
24- HAS_LABEL="false"
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
28- HAS_LABEL="true"
29- fi
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
44- echo "has_label=${HAS_LABEL}" >> "$GITHUB_OUTPUT"
25+ .github/scripts/check-ci-per-commit-label.sh \
26+ "${{ github.event_name }}" \
27+ "${{ github.repository }}" \
28+ "${{ github.sha }}" \
29+ '${{ toJSON(github.event.pull_request.labels.*.name) }}' \
30+ >> "$GITHUB_OUTPUT"
4531
4632 ci :
4733 name : CI
You can’t perform that action at this time.
0 commit comments