Percy screenshots #2717
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow listens for completion of the `pr-percy-prepare` workflows, picks up their outputs, and performs Percy testing. | |
name: "Percy screenshots" | |
on: | |
workflow_run: | |
workflows: | |
- "Percy (pushed)" | |
- "Percy (labeled)" | |
types: | |
- completed | |
jobs: | |
upload: | |
name: Build project with proposed changes & take Percy snapshots | |
if: github.event.workflow_run.conclusion=='success' | |
runs-on: ubuntu-latest | |
outputs: | |
pr_head_sha: ${{ steps.get_pr_data.outputs.sha }} | |
pr_number: ${{ steps.get_pr_data.outputs.pr_number }} | |
percy_build_link: ${{ steps.percy_snapshot.outputs.build_link }} | |
percy_org_id: ${{ steps.percy_snapshot.outputs.org_id }} | |
percy_build_id: ${{ steps.percy_snapshot.outputs.build_id }} | |
steps: | |
# Checkout `main` branch of Vanilla | |
- name: Checkout SCM | |
uses: actions/checkout@v4 | |
- name: Remove SCM directories that will be replaced by artifact files | |
run: rm -rf templates/docs/examples/ templates/_macros/ tokens/ sd.config.json scss/ | |
- name: Download artifact from prepare workflow | |
uses: actions/download-artifact@v4 | |
with: | |
name: "percy-testing-web-artifact" | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
repository: ${{ github.event.workflow_run.repository.full_name }} | |
run-id: ${{ github.event.workflow_run.id }} | |
# Downloading the artifact in the previous step also extracts its contents into `./`. | |
# However, there are some files in the artifact that are not in the same place as Vanilla expects them to be. | |
# This step moves those files to the correct place. | |
- name: Move artifact files into place to replace SCM | |
run: | | |
# ensure the examples & macros dirs exist for backwards compatibility in case they aren't in the PR artifact | |
mkdir -p examples | |
mkdir -p macros | |
mkdir -p tokens | |
# artifact directory contains `scss/`, `examples/`, `macros/`, 'tokens/', 'sd.config.json', `pr_num.txt`, and `pr_head_sha.txt`. | |
# `/examples` and `macros/` must be moved to `templates/`. | |
mv examples/ templates/docs/. | |
mv macros/ templates/_macros | |
# The `pr_num.txt` and `pr_head_sha.txt` files are used to pass the PR number and head SHA from the PR to this workflow. | |
# This is required as the `workflow_run` context of this workflow has no access to the context of the PR that triggered the `pr-percy-prepare` workflow. | |
- name: Get PR data | |
if: github.event.workflow_run.event=='pull_request' | |
id: get_pr_data | |
run: | | |
echo "sha=$(cat pr_head_sha.txt)" >> $GITHUB_OUTPUT | |
echo "pr_number=$(cat pr_num.txt)" >> $GITHUB_OUTPUT | |
# Debugging step to show the full contents of the filesystem just before the Percy snapshot step | |
tree | |
# Composite action uses the filesystem we have prepared for it with this workflow | |
- name: Build, run, and test Vanilla | |
id: percy_snapshot | |
uses: "./.github/actions/percy-snapshot" | |
with: | |
branch_name: "pull/${{ steps.get_pr_data.outputs.pr_number }}" | |
pr_number: ${{ steps.get_pr_data.outputs.pr_number }} | |
commitsh: ${{ steps.get_pr_data.outputs.sha }} | |
percy_token_write: ${{ secrets.PERCY_TOKEN_WRITE }} |