-
Notifications
You must be signed in to change notification settings - Fork 1
add workflow #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pranavz28
wants to merge
9
commits into
main
Choose a base branch
from
test-workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add workflow #5
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d90b8d
add workflow
pranavz28 4e963cd
add lock file
pranavz28 dfb2ec9
update workflow
pranavz28 0ceb003
fix browser deps
pranavz28 3eb9d35
add env before calling percy
pranavz28 6c0000e
test creation of pr
pranavz28 beb04e6
test creation of pr
pranavz28 f0443b4
Refactor dependency update workflow
pranavz28 4b8d0d2
update workflow
pranavz28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| name: Auto update deps + Percy Web | ||
|
|
||
| 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: | ||
| update-pr-and-percy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout (base) | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ env.NODE_VERSION }} | ||
| cache: npm | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
| cache: "pip" | ||
|
|
||
| - name: Install Node deps | ||
| run: | | ||
| npm ci || npm install | ||
|
|
||
| - name: Create venv & install Python deps | ||
| run: | | ||
| python -m venv .venv | ||
| source .venv/bin/activate | ||
| python -m pip install --upgrade pip | ||
| pip install -r requirements.txt | ||
|
|
||
| - name: Bump Node deps to latest stable (incl. @percy/cli) | ||
| run: | | ||
| npx --yes npm-check-updates@latest -u --target latest | ||
| npm install --save-dev @percy/cli@latest | ||
| npm install | ||
|
|
||
| - name: Bump Python deps & repin requirements.txt | ||
| run: | | ||
| set -e | ||
| source .venv/bin/activate | ||
| pip install --upgrade -r requirements.txt | ||
| pip freeze > requirements.txt | ||
|
|
||
| - name: Verify percy CLI | ||
| run: npx percy --version | ||
|
|
||
| - name: Create Pull Request (if changes) | ||
| id: cpr | ||
| uses: peter-evans/create-pull-request@v6 | ||
| with: | ||
| branch: ${{ env.UPDATE_BRANCH }} | ||
| commit-message: "chore: bump Node & Python deps (incl. @percy/cli) to latest stable" | ||
| title: "chore: bump deps to latest stable" | ||
| body: | | ||
| Automated dependency update: | ||
| - Node deps via npm-check-updates (stable) + npm install | ||
| - Python deps upgraded and re-pinned via pip freeze | ||
| - Ensures latest stable @percy/cli | ||
| labels: dependencies, percy | ||
|
|
||
| - name: Stop if no PR was created | ||
| if: ${{ steps.cpr.outputs.pull-request-number == '' }} | ||
| run: | | ||
| echo "No changes detected; no PR opened. Skipping Percy run." | ||
| id: nopr | ||
|
|
||
| # === Run Percy Web on the PR branch === | ||
| - name: Checkout PR branch | ||
| if: ${{ steps.cpr.outputs.pull-request-number != '' }} | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ env.UPDATE_BRANCH }} | ||
|
|
||
| - name: Install Node deps (PR branch) | ||
| if: ${{ steps.cpr.outputs.pull-request-number != '' }} | ||
| run: | | ||
| npm ci || npm install | ||
|
|
||
| - name: Re-create venv & install Python deps (PR branch) | ||
| if: ${{ steps.cpr.outputs.pull-request-number != '' }} | ||
| 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 (python) and install browsers + OS deps | ||
| if: ${{ steps.cpr.outputs.pull-request-number != '' }} | ||
| env: | ||
| DEBIAN_FRONTEND: noninteractive | ||
| run: | | ||
| set -e | ||
| source .venv/bin/activate | ||
| python -m pip install --upgrade playwright | ||
| python -m playwright install --with-deps | ||
|
|
||
| - name: Percy Web run | ||
| if: ${{ steps.cpr.outputs.pull-request-number != '' }} | ||
| 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: Comment on PR with Percy result | ||
| if: ${{ steps.cpr.outputs.pull-request-number != '' }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const prNumber = Number('${{ steps.cpr.outputs.pull-request-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 Web\nSkipped (missing \`PERCY_TOKEN_WEB\`).`; | ||
| } else if (success && url) { | ||
| body = `## Percy Web\n✅ Build #${id}\n${url}`; | ||
| } else { | ||
| body = `## Percy Web\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 logs | ||
| if: always() && steps.cpr.outputs.pull-request-number != '' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: percy-web-log | ||
| path: percy_web.log | ||
| if-no-files-found: ignore | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step is repeated, can we optimise this. Check if we can use cache here? Something like
uses: actions/cache@v4, This will decrease the run time almost by 1-2 minute.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a condition to check if the requirements exists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a pull request exists, still this is redundant right ???