-
Notifications
You must be signed in to change notification settings - Fork 167
72 lines (65 loc) · 3.28 KB
/
pr-percy-snapshots.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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 }}