Skip to content

Commit 05791d7

Browse files
committed
chore(percy): added automated targeted Percy build on PRs and releases
1 parent cb289e0 commit 05791d7

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This workflow runs Percy visual regression tests after a PR tagged with "package: skin"
2+
# is merged into the main branch. It extracts the list of stories from the PR body
3+
# and runs snapshots for those stories to update the visual regression baselines.
4+
5+
name: Percy Merged Visual Regression Baselines
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
post-merge-snapshots:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
# Checkout the repository
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
# Set up Node.js
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: 16
26+
27+
# Install dependencies
28+
- name: Install dependencies
29+
run: npm install
30+
working-directory: ./packages/skin
31+
32+
# Extract target stories from PR body
33+
- name: Extract target stories
34+
id: extract_stories
35+
run: |
36+
# Get the last merged PR details
37+
PR_BODY=$(gh pr view $(git log -1 --pretty=format:"%s" | grep -oP '#\d+') --json body -q '.body')
38+
if [[ $PR_BODY == *"package: skin"* ]]; then
39+
STORIES=$(echo "$PR_BODY" | awk '/Percy Stories/{getline; print}')
40+
if [ -z "$STORIES" ]; then
41+
echo "No Percy Stories found in PR body."
42+
exit 0
43+
fi
44+
echo "stories=$STORIES" >> $GITHUB_ENV
45+
else
46+
echo "No relevant PR found for package: skin."
47+
exit 0
48+
fi
49+
working-directory: ./packages/skin
50+
51+
# Debug: Print extracted stories
52+
- name: Debug extracted stories
53+
run: echo "Extracted stories: $stories"
54+
working-directory: ./packages/skin
55+
56+
# Run Percy for the extracted stories
57+
- name: Run Percy visual tests
58+
env:
59+
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
60+
run: |
61+
if [ -z "$stories" ]; then
62+
echo "No target stories found. Skipping Percy tests."
63+
exit 0
64+
fi
65+
echo "Running Percy for stories: $stories"
66+
npm run snapshots "$stories"
67+
working-directory: ./packages/skin
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This workflow runs Percy visual regression tests for pull requests. It extracts the list of stories
2+
# from the PR body and runs snapshots for those stories to validate visual changes before merging.
3+
# If Percy detects visual differences, the workflow fails to block merging.
4+
5+
name: Percy PR Visual Regression Tests
6+
7+
on:
8+
pull_request:
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
- edited
14+
- labeled
15+
16+
jobs:
17+
visual-regression:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
# Checkout the repository
22+
- name: Checkout code
23+
uses: actions/checkout@v3
24+
25+
# Set up Node.js
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 16
30+
31+
# Install dependencies
32+
- name: Install dependencies
33+
run: npm install
34+
working-directory: ./packages/skin
35+
36+
# Extract target stories from PR body
37+
- name: Extract target stories
38+
id: extract_stories
39+
run: |
40+
STORIES=$(echo "${{ github.event.pull_request.body }}" | awk '/Percy Stories/{getline; print}')
41+
if [ -z "$STORIES" ]; then
42+
echo "No Percy Stories found in PR body."
43+
exit 0
44+
fi
45+
echo "stories=$STORIES" >> $GITHUB_ENV
46+
working-directory: ./packages/skin
47+
48+
# Debug: Print extracted stories
49+
- name: Debug extracted stories
50+
run: echo "Extracted stories: $stories"
51+
working-directory: ./packages/skin
52+
53+
# Run Percy for the extracted stories
54+
- name: Run Percy visual tests
55+
env:
56+
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
57+
run: npm run snapshots --stories "$stories"
58+
working-directory: ./packages/skin

0 commit comments

Comments
 (0)