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
0 commit comments