Repository navigation
161 lines (159 loc) · 6.55 KB
/
Copy pathdeploy.yml
File metadata and controls
161 lines (159 loc) · 6.55 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
update-snapshots:
description: "Regenerate Playwright screenshot baselines and commit them to this branch"
type: boolean
default: false
jobs:
deploy:
permissions:
actions: read
contents: read
deployments: write
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
url: ${{ steps.deploy_cloudflare.outputs.url}}
playwright-version: ${{ steps.playwright.outputs.version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
with:
persist-credentials: false
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 #v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v7.1.0
with:
node-version-file: "package.json"
cache: "pnpm"
- name: Cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0
with:
path: |
~/.cache/
key: ${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml', '**/eslint.config.js', '**/prettier.config.js', '**/www/tsconfig.json', 'prek.toml') }}
- run: pnpm install
- name: Get Playwright version
id: playwright
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> "$GITHUB_OUTPUT"
# Same hooks as the local pre-commit stage (Prettier, ESLint, actionlint,
# zizmor, ...). no-commit-to-branch would fail every push to main.
- run: pnpm exec prek run --all-files --show-diff-on-failure
env:
SKIP: no-commit-to-branch
- run: pnpm run test && pnpm run build
working-directory: ./www
- name: "Deploy to Cloudflare Pages"
id: deploy_cloudflare
uses: andykenward/github-actions-cloudflare-pages@f3b833c8f206f03c6ce74daea7a6fa8ae5c279ff #v3.6.1
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: dist
working-directory: www
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: ${{ (github.ref == 'refs/heads/main' && 'production') || 'preview' }}
- name: "Deploy deletion from Cloudflare Pages"
uses: andykenward/github-actions-cloudflare-pages/delete@f3b833c8f206f03c6ce74daea7a6fa8ae5c279ff #v3.6.1
if: github.ref == 'refs/heads/main'
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
keep-latest: 2
playwright:
permissions:
actions: read
needs:
- deploy
timeout-minutes: 5
runs-on: ubuntu-latest
container:
# Match the installed @playwright/test so browsers and screenshot
# baselines stay in sync when it is bumped.
image: mcr.microsoft.com/playwright:v${{ needs.deploy.outputs.playwright-version }}-noble
options: --user 1001
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
with:
persist-credentials: false
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 #v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 #v7.1.0
with:
node-version-file: "package.json"
cache: "pnpm"
# Tests run against the deployed URL, so www's dependencies aren't needed.
- run: pnpm install --filter unlike-dev
- name: Run Playwright tests
# "all" rewrites every baseline. The default only rewrites ones that
# fail, so a change inside the pixel tolerance would never land.
run: pnpm exec playwright test ${{ inputs.update-snapshots && '--update-snapshots=all' || '' }}
env:
CLOUDFLARE_ACCESS_CLIENT_ID: ${{ secrets.CLOUDFLARE_ACCESS_CLIENT_ID }}
CLOUDFLARE_ACCESS_CLIENT_SECRET: ${{ secrets.CLOUDFLARE_ACCESS_CLIENT_SECRET }}
PLAYWRIGHT_TEST_BASE_URL: ${{ needs.deploy.outputs.url }}
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 #v7.0.2
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 #v7.0.2
if: ${{ inputs.update-snapshots }}
with:
name: playwright-snapshots
path: tests/screenshots/
retention-days: 7
commit-snapshots:
if: ${{ inputs.update-snapshots }}
permissions:
contents: write
needs:
- playwright
timeout-minutes: 5
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8.0.2
with:
name: playwright-snapshots
path: tests/screenshots/
# Commit through the GraphQL API rather than git push so GitHub signs it.
- name: Commit updated screenshot baselines
env:
GH_TOKEN: ${{ github.token }}
run: |
git add tests/screenshots/
files=$(git diff --cached --name-only)
if [ -z "$files" ]; then
echo "Screenshot baselines unchanged."
exit 0
fi
for f in $files; do
base64 -w0 "$f" | jq -Rc --arg path "$f" '{path: $path, contents: .}'
done > "$RUNNER_TEMP/additions.jsonl"
jq -n \
--arg repo "$GITHUB_REPOSITORY" \
--arg branch "$GITHUB_REF_NAME" \
--arg oid "$(git rev-parse HEAD)" \
--slurpfile additions "$RUNNER_TEMP/additions.jsonl" \
'{
query: "mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { url } } }",
variables: {input: {
branch: {repositoryNameWithOwner: $repo, branchName: $branch},
expectedHeadOid: $oid,
message: {headline: "test: update Playwright screenshot baselines"},
fileChanges: {additions: $additions}
}}
}' > "$RUNNER_TEMP/request.json"
gh api graphql --input "$RUNNER_TEMP/request.json" --jq .data.createCommitOnBranch.commit.url