@@ -9,7 +9,16 @@ permissions:
99
1010jobs :
1111 update-snapshots :
12- if : ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'update playwright snapshots') }}
12+ if : >
13+ (
14+ github.event.issue.author_association == 'OWNER' ||
15+ github.event.issue.author_association == 'COLLABORATOR' ||
16+ github.event.issue.author_association == 'MEMBER'
17+ ) && github.event.issue.pull_request && (
18+ contains(github.event.comment.body, 'please update playwright snapshots') ||
19+ contains(github.event.comment.body, 'please update galata snapshots') ||
20+ contains(github.event.comment.body, 'please update snapshots')
21+ )
1322 runs-on : ubuntu-latest
1423 permissions :
1524 # Required by actions/update-snapshots
@@ -30,14 +39,43 @@ jobs:
3039 env :
3140 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3241
33- - name : Checkout the branch from the PR that triggered the job
42+ - name : Configure git to use https
43+ run : git config --global hub.protocol https
44+
45+ - name : Get PR Info
46+ id : pr
47+ env :
48+ PR_NUMBER : ${{ github.event.issue.number }}
49+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
50+ GH_REPO : ${{ github.repository }}
51+ COMMENT_AT : ${{ github.event.comment.created_at }}
3452 run : |
35- # PR branch remote must be checked out using https URL
36- git config --global hub.protocol https
53+ pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})"
54+ head_sha="$(echo "$pr" | jq -r .head.sha)"
55+ pushed_at="$(echo "$pr" | jq -r .pushed_at)"
56+
57+ if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
58+ echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)"
59+ exit 1
60+ fi
61+
62+ echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
3763
38- gh pr checkout ${{ github.event.issue.number }}
64+ - name : Checkout the branch from the PR that triggered the job
3965 env :
4066 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67+ run : gh pr checkout ${{ github.event.issue.number }}
68+
69+ - name : Validate the fetched branch HEAD revision
70+ env :
71+ EXPECTED_SHA : ${{ steps.pr.outputs.head_sha }}
72+ run : |
73+ actual_sha="$(git rev-parse HEAD)"
74+
75+ if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then
76+ echo "The HEAD of the checked out branch ($actual_sha) differs from the HEAD commit available at the time when trigger comment was submitted ($EXPECTED_SHA)"
77+ exit 1
78+ fi
4179
4280 - name : Base Setup
4381 uses : jupyterlab/maintainer-tools/.github/actions/base-setup@v1
0 commit comments