Skip to content

Commit 215e303

Browse files
authored
Updated integration tests workflow (#535)
1 parent 43511b6 commit 215e303

File tree

1 file changed

+43
-10
lines changed

1 file changed

+43
-10
lines changed

.github/workflows/update-integration-tests.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
name: Update Playwright Snapshots
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
number:
7-
description: 'PR number'
8-
required: true
94
issue_comment:
105
types: [created, edited]
116

@@ -15,22 +10,60 @@ permissions:
1510

1611
jobs:
1712
update-snapshots:
18-
if: ${{ github.event.inputs || (github.event.issue.pull_request && contains(github.event.comment.body, 'please update playwright snapshots')) }}
13+
if: >
14+
(
15+
github.event.issue.author_association == 'OWNER' ||
16+
github.event.issue.author_association == 'COLLABORATOR' ||
17+
github.event.issue.author_association == 'MEMBER'
18+
) && github.event.issue.pull_request && contains(github.event.comment.body, 'please update snapshots')
1919
runs-on: ubuntu-latest
2020

2121
steps:
22+
- name: React to the triggering comment
23+
run: |
24+
gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions --raw-field 'content=+1'
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
2228
- name: Checkout
23-
uses: actions/checkout@v3
29+
uses: actions/checkout@v4
2430
with:
2531
token: ${{ secrets.GITHUB_TOKEN }}
2632

27-
- name: Configure git to use https
28-
run: git config --global hub.protocol https
33+
- name: Get PR Info
34+
id: pr
35+
env:
36+
PR_NUMBER: ${{ github.event.issue.number }}
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
GH_REPO: ${{ github.repository }}
39+
COMMENT_AT: ${{ github.event.comment.created_at }}
40+
run: |
41+
pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})"
42+
head_sha="$(echo "$pr" | jq -r .head.sha)"
43+
pushed_at="$(echo "$pr" | jq -r .pushed_at)"
44+
45+
if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
46+
echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)"
47+
exit 1
48+
fi
49+
50+
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
2951
3052
- name: Checkout the branch from the PR that triggered the job
31-
run: gh pr checkout ${{ github.event.inputs.number || github.event.issue.number }}
3253
env:
3354
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: gh pr checkout ${{ github.event.issue.number }}
56+
57+
- name: Validate the fetched branch HEAD revision
58+
env:
59+
EXPECTED_SHA: ${{ steps.pr.outputs.head_sha }}
60+
run: |
61+
actual_sha="$(git rev-parse HEAD)"
62+
63+
if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then
64+
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)"
65+
exit 1
66+
fi
3467
3568
- name: Base Setup
3669
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

0 commit comments

Comments
 (0)