diff --git a/.github/workflows/baseline-visual-regression.yml b/.github/workflows/baseline-visual-regression.yml new file mode 100644 index 0000000000..eab8e917b4 --- /dev/null +++ b/.github/workflows/baseline-visual-regression.yml @@ -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 + + # Install dependencies + - name: Install dependencies + run: | + npm install + npm install husky --no-save + 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}') + 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 \ No newline at end of file diff --git a/.github/workflows/pr-visual-regression.yml b/.github/workflows/pr-visual-regression.yml new file mode 100644 index 0000000000..7974825146 --- /dev/null +++ b/.github/workflows/pr-visual-regression.yml @@ -0,0 +1,66 @@ +# 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 + + # Install dependencies + - name: Install dependencies + run: | + npm install + npm install husky --no-save + 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: | + 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 + 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: | + if [ -z "$PERCY_TOKEN" ]; then + echo "Error: PERCY_TOKEN secret is not set in repository settings." + exit 1 + fi + npm run snapshots --stories "$stories" + working-directory: ./packages/skin \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d916202a2a..2f13e172d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38231,7 +38231,8 @@ "version": "19.5.1", "license": "MIT", "devDependencies": { - "@marko/run-adapter-static": "^1.0.2" + "@marko/run-adapter-static": "^1.0.2", + "husky": "^9.1.7" } } } diff --git a/packages/skin/package.json b/packages/skin/package.json index 30cda98234..8bebf1d5fb 100644 --- a/packages/skin/package.json +++ b/packages/skin/package.json @@ -83,7 +83,8 @@ "extends @ebay/browserslist-config" ], "devDependencies": { - "@marko/run-adapter-static": "^1.0.2" + "@marko/run-adapter-static": "^1.0.2", + "husky": "^9.1.7" }, "publishConfig": { "registry": "https://registry.npmjs.org"