Skip to content

fix: Add role "switch" to toggle component #3139

fix: Add role "switch" to toggle component

fix: Add role "switch" to toggle component #3139

Workflow file for this run

name: Deploy and visual regression
on:
pull_request:
branches:
- main
# Cancel superseded runs for the same ref to free shared runner capacity.
# Only cancel PR runs; other events keep their runs.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
id-token: write
actions: read
contents: read
statuses: read # Needed to check if the visual regression test result has been overridden
deployments: write
jobs:
# Quick build: compiles source and bundles dev pages without running tests.
# Produces the artifact consumed by deploy, allowing it to start
# before the full build+test job finishes.
quick-build:
name: quick-build (${{format('React {0}', matrix.react)}})
# skip this job for external contributions
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
strategy:
matrix:
react: [16, 18]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm i
- name: Quick build
run: npm run quick-build
env:
NODE_ENV: production
REACT_VERSION: ${{ matrix.react }}
INCLUDE_ONE_THEME: 'true'
- name: Bundle dev pages
run: node_modules/.bin/webpack --config pages/webpack.config.integ.cjs --output-path pages/lib/static-default
env:
NODE_ENV: production
REACT_VERSION: ${{ matrix.react }}
- name: Upload dev pages artifact
uses: actions/upload-artifact@v4
with:
name: dev-pages-react${{ matrix.react }}
path: pages/lib/static-default
# Make the integration test utils available to the visual regression tests
- name: Upload test utils selectors artifact
if: matrix.react == 18
uses: actions/upload-artifact@v4
with:
name: test-utils-selectors
path: lib/components
deploy:
needs: quick-build
name: deploy (${{format('React {0}', matrix.react)}})
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
strategy:
matrix:
react: [16, 18]
uses: cloudscape-design/actions/.github/workflows/deploy.yml@main
secrets: inherit
with:
artifact-name: dev-pages-react${{ matrix.react }}
# Pages to be served locally as mainline reference for visual regression tests
build-baseline:
name: Build baseline pages
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- name: Create baseline worktree from origin/main
run: git worktree add /tmp/baseline origin/main
- name: Install baseline dependencies
run: npm i
working-directory: /tmp/baseline
- name: Build baseline pages
run: npx gulp quick-build
working-directory: /tmp/baseline
env:
NODE_ENV: production
REACT_VERSION: 18
INCLUDE_ONE_THEME: 'true'
- name: Bundle baseline pages
run: node_modules/.bin/webpack --config pages/webpack.config.integ.cjs --output-path "${GITHUB_WORKSPACE}/pages/lib/static-visual-baseline"
working-directory: /tmp/baseline
env:
NODE_ENV: production
REACT_VERSION: 18
- name: Upload baseline artifact
uses: actions/upload-artifact@v4
with:
name: visual-baseline-pages
path: pages/lib/static-visual-baseline
retention-days: 1
visual:
name: Visual regression
needs: [deploy, build-baseline]
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
uses: ./.github/workflows/visual-regression.yml
secrets: inherit
with:
test-utils-artifact-name: test-utils-selectors
baseline-artifact-name: visual-baseline-pages
caller-run-id: ${{ github.run_id }}
commit-sha: ${{ github.event.pull_request.head.sha }}
# Required status check for branch protection. Runs for every PR so the context
# is always reported.
#
# It passes when any of these hold:
# - the PR is from a fork (visual regression cannot run, so it is skipped);
# - the visual job succeeded;
# - the commit has a maintainer override status.
#
# The override is checked directly here (not only via the visual job result) so
# that after an override this job can be re-run on its own to turn the check
# green, without rebuilding or redeploying the (unchanged) pages.
visual-regression-result:
name: Visual regression result
needs: [visual]
if: always()
runs-on: ubuntu-latest
steps:
- name: Evaluate result
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
SHA: ${{ github.event.pull_request.head.sha }}
IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
VISUAL_RESULT: ${{ needs.visual.result }}
run: |
if [ "$IS_FORK" = "true" ]; then
echo "::notice::Fork pull request: visual regression does not run. Marking as passed."
exit 0
fi
if [ "$VISUAL_RESULT" = "success" ]; then
echo "Visual regression passed."
exit 0
fi
if [ "$VISUAL_RESULT" = "skipped" ] || [ "$VISUAL_RESULT" = "cancelled" ]; then
echo "::error::Visual regression did not run (result: ${VISUAL_RESULT})."
exit 1
fi
OVERRIDDEN=$(gh api \
"repos/${REPO}/commits/${SHA}/status" \
--jq 'any(.statuses[]; .context == "visual-regression-override" and .state == "success")' 2>/dev/null || echo "false")
if [ "$OVERRIDDEN" = "true" ]; then
echo "::notice::Visual regression was overridden for this commit by a maintainer. Marking as passed."
exit 0
fi
echo "::error::Visual regression did not pass (result: ${VISUAL_RESULT}). If the differences are intentional, comment '/override-visual-regression <justification>' on the PR."
exit 1