Dependency Update and Visual Regression Testing #13
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: Dependency Update and Visual Regression Testing | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 6 * * 1" # Mondays 11:30 IST | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| env: | |
| PYTHON_VERSION: "3.11" | |
| NODE_VERSION: "20" | |
| UPDATE_BRANCH: "chore/dep-bumps-${{ github.run_id }}" | |
| jobs: | |
| automated-dependency-update: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| pr-number: ${{ steps.cpr.outputs.pull-request-number }} | |
| pr-branch: ${{ env.UPDATE_BRANCH }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js Environment | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: npm | |
| - name: Set up Python Environment | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| cache: "pip" | |
| - name: Update Node.js Dependencies to Latest Stable Versions | |
| run: | | |
| npx --yes npm-check-updates@latest -u --target latest | |
| npm install --save-dev @percy/cli@latest | |
| npm install | |
| - name: Update Python Dependencies to Latest Versions | |
| run: | | |
| set -e | |
| echo "=== Before update ===" | |
| cat requirements.txt | |
| # Install pip-upgrader and automatically select "all" packages | |
| pip install --upgrade pip pip-upgrader | |
| # Pipe "all" to select all packages non-interactively | |
| echo "all" | pip-upgrade --skip-package-installation | |
| echo "=== After update ===" | |
| cat requirements.txt | |
| # Verify the updated requirements can be installed | |
| python -m venv .venv | |
| source .venv/bin/activate | |
| pip install -r requirements.txt | |
| deactivate | |
| rm -rf .venv | |
| - name: Verify Percy CLI Installation | |
| run: npx percy --version | |
| - name: Create Pull Request for Dependency Updates | |
| id: cpr | |
| uses: peter-evans/create-pull-request@v6 | |
| with: | |
| branch: ${{ env.UPDATE_BRANCH }} | |
| commit-message: "chore: bump Node & Python deps to latest stable" | |
| title: "chore: bump deps to latest stable" | |
| body: | | |
| Automated dependency update: | |
| - Node.js dependencies updated via npm-check-updates to latest stable versions | |
| - Python dependencies updated to latest versions from PyPI | |
| - Ensures latest stable @percy/cli is installed | |
| - All updates verified by installation tests | |
| labels: dependencies, percy | |
| visual-regression-testing: | |
| needs: automated-dependency-update | |
| if: ${{ needs.automated-dependency-update.outputs.pr-number != '' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Pull Request Branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.automated-dependency-update.outputs.pr-branch }} | |
| - name: Set up Node.js Environment | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: npm | |
| - name: Set up Python Environment | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| cache: "pip" | |
| - name: Install Node.js Dependencies from Updated Branch | |
| run: | | |
| npm ci || npm install | |
| - name: Configure Python Virtual Environment and Install Dependencies | |
| run: | | |
| python -m venv .venv | |
| source .venv/bin/activate | |
| python -m pip install --upgrade pip setuptools wheel | |
| pip install -r requirements.txt | |
| - name: Upgrade Playwright and Install Browsers | |
| run: | | |
| source .venv/bin/activate | |
| python -m pip install --upgrade playwright | |
| python -m playwright install --with-deps | |
| - name: Execute Percy Visual Regression Tests | |
| id: percy_web | |
| env: | |
| PERCY_TOKEN: ${{ secrets.PERCY_TOKEN_WEB }} | |
| run: | | |
| set -o pipefail | |
| if [ -z "$PERCY_TOKEN" ]; then | |
| echo "Missing PERCY_TOKEN_WEB secret; cannot run Percy Web." | |
| echo "skipped=1" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| ( source .venv/bin/activate && npx percy exec -- .venv/bin/python tests/web/test.py ) 2>&1 | tee percy_web.log | |
| URL=$(grep -Eo 'https://percy.io[^ ]+' percy_web.log | tail -n1 || true) | |
| ID=$(grep -Eo 'Finalized build #[0-9]+' percy_web.log | grep -Eo '[0-9]+' | tail -n1 || true) | |
| STATUS=$? | |
| # If command returned non-zero, mark failure | |
| if [ $STATUS -ne 0 ]; then | |
| echo "success=0" >> $GITHUB_OUTPUT | |
| else | |
| # Percy may still finalize with errors; treat URL presence as success signal | |
| if [ -n "$URL" ]; then echo "success=1" >> $GITHUB_OUTPUT; else echo "success=0" >> $GITHUB_OUTPUT; fi | |
| fi | |
| echo "url=${URL}" >> $GITHUB_OUTPUT | |
| echo "id=${ID}" >> $GITHUB_OUTPUT | |
| - name: Post Visual Regression Test Results to Pull Request | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const prNumber = Number('${{ needs.automated-dependency-update.outputs.pr-number }}'); | |
| const url = '${{ steps.percy_web.outputs.url }}'; | |
| const id = '${{ steps.percy_web.outputs.id }}'; | |
| const skipped = '${{ steps.percy_web.outputs.skipped }}' === '1'; | |
| const success = '${{ steps.percy_web.outputs.success }}' === '1'; | |
| let body; | |
| if (skipped) { | |
| body = `## Percy Visual Regression Testing\nSkipped (missing \`PERCY_TOKEN_WEB\`).`; | |
| } else if (success && url) { | |
| body = `## Percy Visual Regression Testing\n✅ Build #${id} Passed\n${url}`; | |
| } else { | |
| body = `## Percy Visual Regression Testing\n❌ Build Failed (see logs in workflow artifacts).`; | |
| if (url) body += `\nFinalized build URL (may contain error details):\n${url}`; | |
| } | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body, | |
| }); | |
| - name: Upload Percy Test Logs as Artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: percy-visual-regression-logs | |
| path: percy_web.log | |
| if-no-files-found: ignore |