Skip to content

Commit ebbe15c

Browse files
committed
Revert "temporarily changed the workflow to be on push"
This reverts commit db5207f.
1 parent 0737279 commit ebbe15c

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

.github/workflows/visual-regression.yml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ name: Visual Regression
3131
# - secrets.EXPLORER_TEAM_AWS_ACCESS_KEY_ID
3232
# - secrets.EXPLORER_TEAM_AWS_SECRET_ACCESS_KEY
3333

34-
# TEMPORARY: triggered on push instead of /visual-tests comment for workflow debugging.
35-
# Revert the `on:` block, the gate step, and the PR-resolution step (use issue.number again)
36-
# before merging.
3734
on:
38-
push:
35+
issue_comment:
36+
types: [created]
3937

4038
permissions:
4139
contents: write
@@ -48,6 +46,9 @@ concurrency:
4846
jobs:
4947
resolve:
5048
name: Resolve trigger
49+
if: |
50+
github.event.issue.pull_request &&
51+
startsWith(github.event.comment.body, '/visual-tests')
5152
runs-on: ubuntu-latest
5253
outputs:
5354
authorized: ${{ steps.gate.outputs.authorized }}
@@ -59,28 +60,43 @@ jobs:
5960
head_ref: ${{ steps.pr.outputs.head_ref }}
6061

6162
steps:
62-
- name: Gate (push trigger — always authorized)
63+
- name: Gate by author association
6364
id: gate
64-
run: echo "authorized=true" >> "$GITHUB_OUTPUT"
65+
env:
66+
ASSOC: ${{ github.event.comment.author_association }}
67+
run: |
68+
set -euo pipefail
69+
case "$ASSOC" in
70+
OWNER|MEMBER|COLLABORATOR)
71+
echo "authorized=true" >> "$GITHUB_OUTPUT"
72+
;;
73+
*)
74+
echo "::notice::Ignoring /visual-tests from $ASSOC ${{ github.event.comment.user.login }} — write access required."
75+
echo "authorized=false" >> "$GITHUB_OUTPUT"
76+
;;
77+
esac
78+
79+
- name: React to the trigger comment
80+
if: steps.gate.outputs.authorized == 'true'
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: |
84+
gh api -X POST \
85+
"repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
86+
-f content=eyes >/dev/null
6587
6688
- name: Resolve PR head + build URL
6789
id: pr
6890
if: steps.gate.outputs.authorized == 'true'
6991
env:
7092
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
PUSHED_REF: ${{ github.ref_name }}
72-
PUSHED_SHA: ${{ github.sha }}
93+
PR_NUMBER: ${{ github.event.issue.number }}
7394
PUBLIC_URL_PREFIX: ${{ vars.EXPLORER_TEAM_S3_BUCKET_PUBLIC_URL }}
7495
run: |
7596
set -euo pipefail
7697
77-
# Find an open PR whose head matches the pushed branch.
78-
PR_JSON=$(gh api "repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${PUSHED_REF}&state=open&per_page=1" --jq '.[0]')
79-
if [ -z "$PR_JSON" ] || [ "$PR_JSON" = "null" ]; then
80-
echo "::error::No open PR found for branch '${PUSHED_REF}'. Push trigger requires an open PR to derive the build URL."
81-
exit 1
82-
fi
83-
PR_NUMBER=$(echo "$PR_JSON" | jq -r '.number')
98+
# 1. Fetch PR head — issue_comment events don't carry it in the payload.
99+
PR_JSON=$(gh api "repos/${{ github.repository }}/pulls/${PR_NUMBER}")
84100
HEAD_SHA=$(echo "$PR_JSON" | jq -r '.head.sha')
85101
HEAD_REF=$(echo "$PR_JSON" | jq -r '.head.ref')
86102
SHORT_SHA="${HEAD_SHA:0:7}"

0 commit comments

Comments
 (0)