|
| 1 | +name: Update Playwright Snapshots |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created, edited] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + update-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.comment.author_association == 'OWNER' || |
| 19 | + github.event.comment.author_association == 'COLLABORATOR' || |
| 20 | + github.event.comment.author_association == 'MEMBER' |
| 21 | + ) && github.event.issue.pull_request && contains(github.event.comment.body, 'please update snapshots') |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: React to the triggering comment |
| 26 | + run: | |
| 27 | + gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions --raw-field 'content=+1' |
| 28 | + env: |
| 29 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Get PR Info |
| 37 | + id: pr |
| 38 | + env: |
| 39 | + PR_NUMBER: ${{ github.event.issue.number }} |
| 40 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + GH_REPO: ${{ github.repository }} |
| 42 | + COMMENT_AT: ${{ github.event.comment.created_at }} |
| 43 | + run: | |
| 44 | + pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})" |
| 45 | + head_sha="$(echo "$pr" | jq -r .head.sha)" |
| 46 | + pushed_at="$(echo "$pr" | jq -r .pushed_at)" |
| 47 | +
|
| 48 | + if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then |
| 49 | + echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + echo "head_sha=$head_sha" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Checkout the branch from the PR that triggered the job |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + run: gh pr checkout ${{ github.event.issue.number }} |
| 59 | + |
| 60 | + - name: Validate the fetched branch HEAD revision |
| 61 | + env: |
| 62 | + EXPECTED_SHA: ${{ steps.pr.outputs.head_sha }} |
| 63 | + run: | |
| 64 | + actual_sha="$(git rev-parse HEAD)" |
| 65 | +
|
| 66 | + if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then |
| 67 | + 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)" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Base Setup |
| 72 | + uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 |
| 73 | + |
| 74 | + - name: Install dependencies |
| 75 | + run: python -m pip install -U "jupyterlab>=4.0.0,<5" |
| 76 | + |
| 77 | + - name: Install extension |
| 78 | + run: | |
| 79 | + set -eux |
| 80 | + jlpm |
| 81 | + python -m pip install . |
| 82 | +
|
| 83 | + - uses: jupyterlab/maintainer-tools/.github/actions/update-snapshots@v1 |
| 84 | + with: |
| 85 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + # Playwright knows how to start JupyterLab server |
| 87 | + start_server_script: 'null' |
| 88 | + test_folder: ui-tests |
| 89 | + npm_client: jlpm |
0 commit comments