content: Base query building
#153
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Visual Regression Screenshots | |
| on: | |
| workflow_dispatch: # manual trigger | |
| issue_comment: | |
| types: [created] | |
| env: | |
| AUTHOR_NAME: 'imodeljs-admin' | |
| AUTHOR_EMAIL: 'imodeljs-admin@users.noreply.github.com' | |
| COMMIT_MESSAGE: | | |
| test: update visual regression screenshots | |
| Co-authored-by: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> | |
| jobs: | |
| update-screenshots: | |
| runs-on: ubuntu-24.04 | |
| # run on manual trigger, or when a trusted user adds /update-screenshots comment to a PR | |
| if: >- | |
| (github.event_name == 'workflow_dispatch' && github.ref_name != github.event.repository.default_branch) || | |
| (github.event_name == 'issue_comment' && | |
| github.event.issue.pull_request && | |
| github.event.comment.body == '/update-screenshots' && | |
| (github.event.comment.author_association == 'OWNER' || | |
| github.event.comment.author_association == 'MEMBER' || | |
| github.event.comment.author_association == 'COLLABORATOR')) | |
| # one at a time per branch | |
| concurrency: | |
| group: visual-regression-screenshots@${{ github.event.issue.number || github.ref_name }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write # needs to push changes | |
| pull-requests: read # needed to resolve PR head ref via github-script | |
| steps: | |
| - name: Get PR head ref | |
| if: github.event_name == 'issue_comment' | |
| id: pr | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 | |
| with: | |
| script: | | |
| const pr = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number, | |
| }); | |
| const headRepo = pr.data.head.repo.full_name; | |
| const baseRepo = pr.data.base.repo.full_name; | |
| if (headRepo !== baseRepo) { | |
| core.setFailed(`Fork PRs are not supported (head: ${headRepo}, base: ${baseRepo})`); | |
| return; | |
| } | |
| core.setOutput('ref', pr.data.head.ref); | |
| - name: Checkout selected branch | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | |
| with: | |
| ref: ${{ steps.pr.outputs.ref || github.ref_name }} | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "${{ env.AUTHOR_NAME }}" | |
| git config --global user.email "${{ env.AUTHOR_EMAIL }}" | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 | |
| - name: Use Node.js 24 | |
| uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e | |
| with: | |
| node-version: 24.15.0 | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Install browsers | |
| run: pnpm lage install-browsers | |
| - name: Update Visual Regression Screenshots | |
| run: pnpm lage test:components:update | |
| # check what changed | |
| - name: Check for changes | |
| id: check_changes | |
| run: | | |
| CHANGED_FILES=$(git status --porcelain | awk '{print $2}') | |
| if [ "${CHANGED_FILES:+x}" ]; then | |
| echo "changes=true" >> $GITHUB_OUTPUT | |
| echo "Changes detected" | |
| # save the list for the summary | |
| echo "changed_files<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGED_FILES" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| echo "changed_count=$(echo "$CHANGED_FILES" | wc -l)" >> $GITHUB_OUTPUT | |
| else | |
| echo "changes=false" >> $GITHUB_OUTPUT | |
| echo "No changes detected" | |
| fi | |
| # commit if there are changes | |
| - name: Commit changes | |
| if: steps.check_changes.outputs.changes == 'true' | |
| run: | | |
| git add -A | |
| git commit -m "${{ env.COMMIT_MESSAGE }}" | |
| - name: Push changes | |
| if: steps.check_changes.outputs.changes == 'true' | |
| run: git push origin HEAD:${{ steps.pr.outputs.ref || github.ref_name }} | |
| # pretty summary for humans | |
| - name: Summary | |
| run: | | |
| if [[ "${{ steps.check_changes.outputs.changes }}" == "true" ]]; then | |
| echo "### 📸 Visual Regression Screenshots Updated" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Successfully updated **${{ steps.check_changes.outputs.changed_count }}** screenshot(s) on \`${{ steps.pr.outputs.ref || github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "#### Changed Files:" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "${{ steps.check_changes.outputs.changed_files }}" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "✅ The updated screenshots have been committed and pushed. Your visual regression baseline is now up to date!" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "### ℹ️ No Screenshot Updates Required" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "The visual regression test command ran successfully but no screenshots needed updating." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "All screenshots are already up to date! 🎉" >> $GITHUB_STEP_SUMMARY | |
| fi |