-
Notifications
You must be signed in to change notification settings - Fork 365
101 lines (80 loc) · 3.36 KB
/
screenshots.yml
File metadata and controls
101 lines (80 loc) · 3.36 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Percy screenshots
on:
workflow_call:
workflow_dispatch:
permissions:
contents: read
pull-requests: read
concurrency:
group: screenshots-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
screenshots:
name: Send screenshots
runs-on: ubuntu-22.04
env:
PERCY_POSTINSTALL_BROWSER: false
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
PUPPETEER_SKIP_DOWNLOAD: true
# Skip when secrets are unavailable on forks
if: ${{ !github.event.pull_request.head.repo.fork }}
steps:
- name: Check secrets
if: ${{ !env.PERCY_TOKEN }}
run: echo "::warning title=GitHub Actions secrets::Workflow requires 'PERCY_TOKEN' secret"
- name: Checkout
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
- name: Get changed files
id: files
if: github.event_name != 'workflow_dispatch'
run: |
BASE_REF="${{ github.base_ref || 'main' }}"
echo "Comparing with base branch: $BASE_REF"
git fetch origin $BASE_REF:$BASE_REF 2>/dev/null || true
CHANGED_FILES=$(git diff --name-only origin/$BASE_REF..HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
CHANGED_FILES_JSON=$(echo "$CHANGED_FILES" | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "changed_files=$CHANGED_FILES_JSON" >> $GITHUB_OUTPUT
- name: Check for relevant changes
id: changes
uses: actions/github-script@v8.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
console.log('Checking if Percy needs to run.')
if (context.eventName === 'workflow_dispatch') {
console.log('workflow_dispatch - running Percy')
core.setOutput('relevant_changes', 'true')
} else if (context.eventName === 'push') {
console.log(`Merging to ${context.ref} - running Percy`)
core.setOutput('relevant_changes', 'true')
} else {
const changedFiles = JSON.parse('${{ steps.files.outputs.changed_files }}')
const { checkRelevantChanges } = await import('${{ github.workspace }}/shared/github-scripts/check-percy-files.mjs')
const relevantChanges = checkRelevantChanges(changedFiles)
core.setOutput('relevant_changes', relevantChanges)
console.log('Relevant changes detected:', relevantChanges)
}
- name: Install dependencies
if: steps.changes.outputs.relevant_changes == 'true'
uses: ./.github/workflows/actions/install-node
- name: Cache browser download
if: steps.changes.outputs.relevant_changes == 'true'
uses: actions/cache@v5.0.4
with:
# Use faster GNU tar for all runners
enableCrossOsArchive: true
key: puppeteer-${{ runner.os }}
path: .cache/puppeteer
- name: Build
if: steps.changes.outputs.relevant_changes == 'true'
uses: ./.github/workflows/actions/build
- name: Start review app
if: steps.changes.outputs.relevant_changes == 'true'
run: npm start --workspace @govuk-frontend/review &
- name: Send screenshots to Percy
if: steps.changes.outputs.relevant_changes == 'true'
run: npx --workspace @govuk-frontend/review percy exec -- npm run test:screenshots