-
Notifications
You must be signed in to change notification settings - Fork 32
chore(percy): added automated targeted Percy build on PRs and releases #152
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
Changes from 4 commits
05791d7
a427f77
4132876
ca262d1
ba01d7a
93a6d54
f53ac16
f6a76a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # This workflow runs Percy visual regression tests after a PR tagged with "package: skin" | ||
| # is merged into the main branch. It extracts the list of stories from the PR body | ||
| # and runs snapshots for those stories to update the visual regression baselines. | ||
|
|
||
| name: Percy Merged Visual Regression Baselines | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| post-merge-snapshots: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # Set up Node.js | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| # Install dependencies | ||
| - name: Install dependencies | ||
| run: npm install | ||
| working-directory: ./packages/skin | ||
|
|
||
| # Extract target stories from PR body | ||
| - name: Extract target stories | ||
| id: extract_stories | ||
| env: | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| run: | | ||
| # Use the PR_BODY environment variable securely | ||
| if [[ "$PR_BODY" == *"package: skin"* ]]; then | ||
| STORIES=$(echo "$PR_BODY" | awk '/Percy Stories/{getline; print}') | ||
| if [ -z "$STORIES" ]; then | ||
| echo "No Percy Stories found in PR body." | ||
| exit 0 | ||
| fi | ||
| echo "stories=$STORIES" >> $GITHUB_ENV | ||
| else | ||
| echo "No relevant PR found for package: skin." | ||
| exit 0 | ||
| fi | ||
| working-directory: ./packages/skin | ||
|
|
||
| # Debug: Print extracted stories | ||
| - name: Debug extracted stories | ||
| run: | | ||
| STORIES=$(echo "$PR_BODY" | awk '/Percy Stories/{getline; print}') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| echo "Extracted stories: $STORIES" | ||
| working-directory: ./packages/skin | ||
|
|
||
| # Run Percy for the extracted stories | ||
| - name: Run Percy visual tests | ||
| env: | ||
| PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} | ||
| run: | | ||
| if [ -z "$stories" ]; then | ||
| echo "No target stories found. Skipping Percy tests." | ||
| exit 0 | ||
| fi | ||
| echo "Running Percy for stories: $stories" | ||
| npm run snapshots "$stories" | ||
| working-directory: ./packages/skin | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # This workflow runs Percy visual regression tests for pull requests. It extracts the list of stories | ||
| # from the PR body and runs snapshots for those stories to validate visual changes before merging. | ||
| # If Percy detects visual differences, the workflow fails to block merging. | ||
|
|
||
| name: Percy PR Visual Regression Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - synchronize | ||
| - reopened | ||
| - edited | ||
| - labeled | ||
|
|
||
| jobs: | ||
| visual-regression: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # Checkout the repository | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| # Set up Node.js | ||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 22 | ||
ArtBlue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Install dependencies | ||
| - name: Install dependencies | ||
| run: npm install | ||
| working-directory: ./packages/skin | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe all the dev depdencies are in the root. Might want to move that to the root.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about that before going in this direction. What benefits would that have vs. this option? I'm fine doing that, but it's a fairly large change... trying to make sure the benefits outweigh the cost.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Im just worried that some dev deps might not be added
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think this CI issue is due to no dev deps being installed. Should probably remove working-directory
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it just missing |
||
|
|
||
| # Extract target stories from PR body | ||
| - name: Extract target stories | ||
| id: extract_stories | ||
| env: | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| run: | | ||
| STORIES=$(echo "$PR_BODY" | awk '/Percy Stories/{getline; print}') | ||
| if [ -z "$STORIES" ]; then | ||
| echo "No Percy Stories found in PR body." | ||
| exit 0 | ||
| fi | ||
| echo "stories=$STORIES" >> $GITHUB_ENV | ||
agliga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| working-directory: ./packages/skin | ||
|
|
||
| # Debug: Print extracted stories | ||
| - name: Debug extracted stories | ||
| run: echo "Extracted stories: $stories" | ||
| working-directory: ./packages/skin | ||
|
|
||
| # Run Percy for the extracted stories | ||
| - name: Run Percy visual tests | ||
| env: | ||
| PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} | ||
| run: npm run snapshots --stories "$stories" | ||
| working-directory: ./packages/skin | ||
ArtBlue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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.
Is this section needed for the baesline? I assume when a PR merges it just gets a new baseline story right?
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.
I think there may be some confusion around how Percy works and the current process.
Doing baselines is currently a manual process. I've been running full baseline builds from master after releases to create new baselines. If Percy had the ability to automatically create new baselines by itself when we did releases, we would have definitely been doing that all of this time or at least thought about it. AFAIK, Percy has no awareness of repositories. It doesn't check for merges itself and run builds; don't think it's capable of doing that.
With our recent trunk based development, without automating this targeted build on releases, we would have to do that manually and since our releases are going to be smaller and more frequent, full builds on each release are going to be too much. Bottom line is we'd have to do this same thing manually - targeted Percy runs on each release.
This change basically automates that process. This runs targeted baseline builds to create baselines only on the components touched for the PR, which are only the ones that were touched by the PR. This streamlines visual regression with very little effort.
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.
So here's my issue with the way this is
If I create a PR, merge it, and it runs, then it updates baselines for that PR. If that PR is missing those lines OR they are incorrect, it will only update a certain set of baselines.
The other issue is if we merge two PRs at the same time, only the latest one will run and update only those.
IMO, I think we should maybe run this once a day and update all snapshots. If that seems to be too much we can either run it once a week, or have a way to trigger it github manually when we want to update.
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 this happens, then something terribly wrong has happened with the PR itself, because the whole point of the visual regression is to ensure we're covering all the changes to the appropriate stories. If those are not mentioned in the PR, that's already a failure at the first level. This simply creates baselines for the very first stories that were included, which is what should happen. That's typically all we care about. IMO, it's not a big deal to ensure the PR has the correct stories mentioned in the body.
When would we merge two PRs at virtually the same time? If we have to concern ourselves with this possibility, then no automation will ever work.
I don't this is a realistic or practical solution. The whole point is to automate visual regression as a whole. It's not practical to have someone run automation every single day. Also, if we did that, we would deplete the quota we have extremely quickly.
Once a week is better and may not deplete our quota completely. However, if there is more than one change at all touching components that are common in changesets during a single week, the diffs are going to be compared against obsolete baselines. This won't work IMO.