-
Notifications
You must be signed in to change notification settings - Fork 19
220 lines (185 loc) · 8.44 KB
/
Copy pathvrt-update.yaml
File metadata and controls
220 lines (185 loc) · 8.44 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: VRT Update
on:
workflow_dispatch:
inputs:
ref:
description: 'Branch name to run against (e.g., main, develop, feature/my-branch)'
required: true
default: 'main'
type: string
pull_request:
types: [opened, synchronize, reopened]
jobs:
vrt-update:
runs-on: ubuntu-24.04
container: mcr.microsoft.com/playwright:v1.57.0-noble
# PR from non-collaborators requires a manual re-run from collaborators which
# makes run_attempt > 1 on first attempt causing the workflow to run.
# So we always skip if the PR is not from a collaborator.
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.run_attempt > 1 && contains(fromJSON('["COLLABORATOR", "MEMBER", "OWNER"]'), github.event.pull_request.author_association))
steps:
- name: Check execution conditions and set target ref
id: check
run: |
echo "should-run=true" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "target-ref=${{ inputs.ref }}" >> $GITHUB_OUTPUT
else
# For PR re-runs, use the head ref
echo "target-ref=${{ github.head_ref }}" >> $GITHUB_OUTPUT
fi
# As we are in another container, we need to install LFS manually.
# See: https://github.com/orgs/community/discussions/160433
- name: Install LFS
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
apt install git-lfs -y
- name: Configure Git
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: actions/checkout@v6
with:
ref: ${{ steps.check.outputs.target-ref }}
lfs: true
- uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Get latest workflow run
id: get-workflow
uses: actions/github-script@v8
with:
script: |
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'build-and-test.yaml',
branch: '${{ steps.check.outputs.target-ref }}',
per_page: 10,
status: 'completed'
});
if (runs.total_count === 0) {
core.setFailed(`No completed workflow runs found for branch '${{ steps.check.outputs.target-ref }}'. Make sure the build-and-test workflow has run on this branch.`);
return;
}
// Find the most recent run that has the required jobs completed successfully
const requiredJobs = ['build'];
let latestValidRun = null;
for (const run of runs.workflow_runs) {
try {
// Get jobs for this workflow run
const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id
});
// Check if all required jobs completed successfully
const jobStatuses = {};
for (const job of jobs.jobs) {
jobStatuses[job.name] = job.conclusion;
}
console.log(`Checking run ${run.id}: Jobs found:`, Object.keys(jobStatuses));
console.log(`Job statuses:`, jobStatuses);
const allRequiredJobsSuccessful = requiredJobs.every(jobName =>
jobStatuses[jobName] === 'success'
);
if (allRequiredJobsSuccessful) {
latestValidRun = run;
break;
} else {
const failedJobs = requiredJobs.filter(jobName =>
!jobStatuses[jobName] || jobStatuses[jobName] !== 'success'
);
console.log(`❌ Run ${run.id} missing or failed jobs:`, failedJobs);
}
} catch (error) {
console.log(`Error checking run ${run.id}:`, error.message);
continue;
}
}
if (!latestValidRun) {
core.setFailed(`No workflow runs found for branch '${{ steps.check.outputs.target-ref }}' with successful completion of required jobs: ${requiredJobs.join(', ')}. Make sure build, test, and aot jobs have completed successfully.`);
return;
}
core.setOutput('workflow-run-id', latestValidRun.id);
# Download the dist artifacts from the latest successful build-and-test workflow
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
name: dist
path: dist
run-id: ${{ steps.get-workflow.outputs.workflow-run-id }}
github-token: ${{ github.token }}
# Not injecting the token will exclude the brand packages, but this is fine for e2e tests.
- run: npm ci --no-audit --include=optional
- name: Update VRTs
run: |
# Remove existing snapshots to ensure we generate fresh ones
if [ -d "playwright/snapshots" ]; then
echo "Removing existing snapshots to ensure fresh generation..."
rm -rf playwright/snapshots
fi
# Create snapshots directory
mkdir -p playwright/snapshots
echo "Starting fresh snapshot generation..."
npx playwright test --update-snapshots=all
# Verify that snapshots were generated
if [ ! -d "playwright/snapshots" ] || [ -z "$(ls -A playwright/snapshots 2>/dev/null)" ]; then
echo "ERROR: No snapshots were generated!"
exit 1
fi
echo "Snapshots generated successfully:"
find playwright/snapshots -type f -name "*.png" | head -10
env:
PLAYWRIGHT_CONTAINER: true
PLAYWRIGHT_isvrt: 'true'
PLAYWRIGHT_isa11y: 'false'
PLAYWRIGHT_WEB_SERVER_TIMEOUT: 120000
- name: Create snapshots archive
run: |
# Create a timestamped archive of the updated snapshots
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
BRANCH_NAME="${{ inputs.ref || github.ref_name }}"
# Sanitize branch name by replacing invalid characters for artifact names
# Replace forward slashes, colons, and other invalid characters with hyphens
SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/\\:*?"<>|]/-/g')
ARCHIVE_NAME="playwright-snapshots-${SAFE_BRANCH_NAME}-${TIMESTAMP}"
# Create archive directory structure
mkdir -p "${ARCHIVE_NAME}"
cp -r playwright/snapshots "${ARCHIVE_NAME}/"
# Verify the copy was successful
COPIED_COUNT=$(find "${ARCHIVE_NAME}/snapshots" -type f -name "*.png" | wc -l)
echo "Copied $COPIED_COUNT snapshot files to archive"
if [ "$COPIED_COUNT" -ne "$SNAPSHOT_COUNT" ]; then
echo "WARNING: Snapshot count mismatch! Original: $SNAPSHOT_COUNT, Copied: $COPIED_COUNT"
fi
# Create tar.gz archive
tar -czf "${ARCHIVE_NAME}.tar.gz" "${ARCHIVE_NAME}"
echo "ARCHIVE_NAME=${ARCHIVE_NAME}" >> $GITHUB_ENV
echo "Archive created: ${ARCHIVE_NAME}.tar.gz"
- name: Upload fresh snapshots
id: upload-artifact
uses: actions/upload-artifact@v6
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.tar.gz
retention-days: 30
- name: Get artifact download URL
if: success()
id: artifact
uses: actions/github-script@v8
with:
script: |
// Wait a bit for the artifact to be uploaded and indexed
await new Promise(resolve => setTimeout(resolve, 5000));
const downloadUrl = "${{ steps.upload-artifact.outputs.artifact-url }}";
core.setOutput('download_url', downloadUrl);
- name: Comment on PR with download link
if: success() && github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
message: |
[⬇️ Download VRTs](${{ steps.artifact.outputs.download_url }})