@@ -4,12 +4,78 @@ run-name: ${{ github.actor }} Checking Calypso Slack Channel Status
44on :
55 merge_group :
66 pull_request :
7+ # Include labeled/unlabeled so adding or removing "Ignore Red Slack"
8+ # re-triggers the check with the current label set.
9+ types : [opened, synchronize, reopened, labeled, unlabeled]
10+
11+ permissions :
12+ contents : read
13+ pull-requests : read
714
815jobs :
916 check-channel-status :
1017 runs-on : ubuntu-latest
1118 steps :
12- - run : |
19+ - name : Should this check be bypassed?
20+ id : bypass
21+ env :
22+ EVENT_NAME : ${{ github.event_name }}
23+ PR_NUMBER : ${{ github.event.pull_request.number }}
24+ MERGE_HEAD_REF : ${{ github.event.merge_group.head_ref }}
25+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
26+ GH_REPO : ${{ github.repository }}
27+ run : |
28+ set -euo pipefail
29+
30+ # A PR bypasses the red-channel gate if it is a revert or is
31+ # explicitly labelled "Ignore Red Slack". Title and labels are read
32+ # live via `gh pr view` (not the event payload) so re-running the
33+ # check picks up a label added after the run was first triggered.
34+ is_revert_or_labeled() {
35+ local pr="$1" data title labels
36+ data=$(gh pr view "$pr" --json title,labels)
37+ title=$(printf '%s' "$data" | jq -r '.title')
38+ labels=$(printf '%s' "$data" | jq -c '[.labels[].name]')
39+ echo "PR #$pr: $title (labels: $labels)"
40+ case "$title" in
41+ "Revert "*) return 0 ;;
42+ esac
43+ printf '%s' "$labels" | jq -e 'any(.[]?; . == "Ignore Red Slack")' >/dev/null 2>&1
44+ }
45+
46+ bypass=false
47+
48+ if [ "$EVENT_NAME" = "pull_request" ]; then
49+ if is_revert_or_labeled "$PR_NUMBER"; then
50+ bypass=true
51+ fi
52+ elif [ "$EVENT_NAME" = "merge_group" ]; then
53+ # The merge-queue ref looks like
54+ # refs/heads/gh-readonly-queue/trunk/pr-123-<sha>, so pull the
55+ # merged PR number(s) out of it and inspect each one. Only bypass
56+ # when every PR in the group qualifies.
57+ pr_numbers=$(printf '%s' "$MERGE_HEAD_REF" | grep -oE 'pr-[0-9]+' | grep -oE '[0-9]+' || true)
58+ if [ -n "$pr_numbers" ]; then
59+ bypass=true
60+ for pr in $pr_numbers; do
61+ if ! is_revert_or_labeled "$pr"; then
62+ bypass=false
63+ break
64+ fi
65+ done
66+ fi
67+ fi
68+
69+ echo "Bypass channel check: $bypass"
70+ echo "bypass=$bypass" >> "$GITHUB_OUTPUT"
71+
72+ - name : Pass for reverts / "Ignore Red Slack" PRs
73+ if : steps.bypass.outputs.bypass == 'true'
74+ run : echo "Revert or \"Ignore Red Slack\" PR — skipping the red-channel gate."
75+
76+ - name : Check channel status
77+ if : steps.bypass.outputs.bypass != 'true'
78+ run : |
1379 STATUS=$(curl -s https://public-api.wordpress.com/wpcom/v2/calypso-slack-channel-status --header "Authorization: ${{ secrets.CALYPSO_CHANNEL_STATUS_API_SECRET }}" | xargs)
1480 if [ "$STATUS" = "GREEN" ]; then
1581 echo "Calypso Slack channel is green."
0 commit comments