-
Notifications
You must be signed in to change notification settings - Fork 33
309 lines (270 loc) · 12.5 KB
/
Copy pathrelease-python-playwright.yaml
File metadata and controls
309 lines (270 loc) · 12.5 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
name: Python + Playwright images
on:
workflow_dispatch:
inputs:
release_tag:
description: 'Tag for the images (e.g.: "latest" or "beta")'
required: true
rebuild_images:
description: "Rebuilds images even if the cache state matches the current state."
required: false
type: boolean
trigger_templates_pr:
description: "When set to true, always triggers the workflow on actor-templates."
required: false
type: boolean
repository_dispatch:
types: [build-python-images]
pull_request:
paths:
- "python-playwright/**"
- "python-playwright-chrome/**"
- "python-playwright-firefox/**"
- "python-playwright-webkit/**"
- "python-playwright-camoufox/**"
- "certificates/**"
- ".github/workflows/release-python-playwright.yaml"
- ".github/actions/version-matrix/**"
- ".github/scripts/prepare-python-image-tags.js"
- "Makefile"
schedule:
- cron: 0 */2 * * *
env:
RELEASE_TAG: ${{ github.event.inputs.release_tag || github.event.client_payload.release_tag }}
SHOULD_USE_LAST_FIVE: ${{ github.event_name != 'pull_request' }}
SKIP_CACHE_CHECK: ${{ github.event_name == 'pull_request' || github.event.inputs.rebuild_images == 'true' }}
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v6
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version-file: .github/actions/version-matrix/package.json
cache: yarn
cache-dependency-path: .github/actions/version-matrix/yarn.lock
- run: yarn
working-directory: ./.github/actions/version-matrix
- name: Generate matrix
id: set-matrix
run: echo "matrix=$(yarn python:playwright)" >> $GITHUB_OUTPUT
working-directory: ./.github/actions/version-matrix
- name: Print matrix
run: |
echo "Matrix:"
echo '${{ steps.set-matrix.outputs.matrix }}' | jq -r '.include[] | "python-version=\(.["python-version"]) playwright-version=\(.["playwright-version"]) camoufox-version=\(.["camoufox-version"]) is-latest=\(.["is-latest"]) image-name=\(.["image-name"])"'
echo ""
echo "Raw matrix:"
echo ""
echo '${{ steps.set-matrix.outputs.matrix }}' | jq -e
- name: Commit updated matrix
id: commit
if: github.event_name != 'pull_request'
uses: apify/actions/signed-commit@v1.2.0
with:
message: "chore(docker): update ${{ env.RELEASE_TAG || 'latest' }} python:playwright cache"
add: ./.github/actions/version-matrix/data/*.json
retries: 5
pull: '--rebase --autostash'
github-token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
- name: Trigger workflow on actor-templates
if: (steps.commit.outputs.committed == 'true' || github.event.inputs.trigger_templates_pr == 'true') && steps.set-matrix.outputs.latest-runtime-version != ''
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
repository: apify/actor-templates
event-type: update-templates
client-payload: |-
{
"base_image": "apify/actor-python-playwright,apify/actor-python-playwright-chrome,apify/actor-python-playwright-firefox,apify/actor-python-playwright-webkit",
"module_version": "${{ steps.set-matrix.outputs.latest-module-version }}",
"default_runtime_version": "${{ steps.set-matrix.outputs.latest-runtime-version }}"
}
# Camoufox lags behind on Playwright, so it needs its own dispatch with its own version.
- name: Trigger workflow on actor-templates for camoufox
if: ((steps.commit.outputs.committed == 'true' || github.event.inputs.trigger_templates_pr == 'true') && steps.set-matrix.outputs.latest-runtime-version != '') && steps.set-matrix.outputs.latest-camoufox-module-version != ''
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
repository: apify/actor-templates
event-type: update-templates
client-payload: |-
{
"base_image": "apify/actor-python-playwright-camoufox",
"module_version": "${{ steps.set-matrix.outputs.latest-camoufox-module-version }}",
"default_runtime_version": "${{ steps.set-matrix.outputs.latest-runtime-version }}"
}
# Build master images that are not dependent on existing builds.
build-main:
needs: [matrix]
runs-on: ubuntu-latest
if: ${{ toJson(fromJson(needs.matrix.outputs.matrix).include) != '[]' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
name: "img: ${{ matrix.image-name }} py: ${{ matrix.python-version }}, pw: ${{ matrix.playwright-version }}, cf: ${{ matrix.camoufox-version }}, is-latest: ${{ matrix.is-latest }}"
steps:
- name: Set default inputs if event is pull request
if: github.event_name == 'pull_request'
run: |
if [[ -z "$RELEASE_TAG" ]]; then echo "RELEASE_TAG=CI_TEST" >> $GITHUB_ENV; fi
- name: Set default inputs if event is schedule
if: github.event_name == 'schedule'
run: |
if [[ -z "$RELEASE_TAG" ]]; then echo "RELEASE_TAG=latest" >> $GITHUB_ENV; fi
- name: Check if inputs are set correctly
run: |
if [[ -z "$RELEASE_TAG" ]]; then echo "RELEASE_TAG input is empty!" >&2; exit 1; fi
- name: Checkout
uses: actions/checkout@v6
- name: Copy Firefox certificates to image folder
run: |
if [ -f "./certificates/firefox-certificates.zip" ]; then
mkdir -p ./${{ matrix.image-name }}/firefox-certs
unzip -q -o ./certificates/firefox-certificates.zip -d ./${{ matrix.image-name }}/firefox-certs
echo "Extracted $(ls -1 ./${{ matrix.image-name }}/firefox-certs/*.crt | wc -l) certificates"
else
mkdir -p ./${{ matrix.image-name }}/firefox-certs
echo "No certificate archive found, created empty folder"
fi
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Prepare image tags
id: prepare-tags
uses: actions/github-script@v8
env:
CURRENT_PYTHON: ${{ matrix.python-version }}
LATEST_PYTHON: ${{ matrix.latest-python-version }}
FRAMEWORK_VERSION: ${{ matrix.playwright-version }}
RELEASE_TAG: ${{ env.RELEASE_TAG }}
IMAGE_NAME: apify/actor-${{ matrix.image-name }}
IS_LATEST_BROWSER_IMAGE: ${{ matrix.is-latest }}
with:
script: |
const generateTags = require("./.github/scripts/prepare-python-image-tags.js");
return generateTags()
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and tag image for testing
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.image-name }}
file: ./${{ matrix.image-name }}/Dockerfile
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
PLAYWRIGHT_VERSION=${{ matrix.playwright-version }}
CAMOUFOX_VERSION=${{ matrix.camoufox-version }}
platforms: linux/amd64
provenance: false
load: true
tags: ${{ fromJson(steps.prepare-tags.outputs.result).allTags }}
cache-from: type=gha,scope=${{ matrix.image-name }}-${{ matrix.python-version }}-${{ matrix.playwright-version }}-${{ matrix.camoufox-version }}
cache-to: type=gha,mode=max,scope=${{ matrix.image-name }}-${{ matrix.python-version }}-${{ matrix.playwright-version }}-${{ matrix.camoufox-version }}
- name: Test image
run: docker run ${{ fromJson(steps.prepare-tags.outputs.result).firstImageName }}
- name: Measure image size
id: image-size
if: github.event_name == 'pull_request'
env:
MATRIX_JSON: ${{ toJSON(matrix) }}
NEW_IMAGE: ${{ fromJson(steps.prepare-tags.outputs.result).firstImageName }}
BASE_IMAGE: apify/actor-${{ matrix.image-name }}:${{ matrix.python-version }}
run: |
set -euo pipefail
mkdir -p size-report
id="$(printf '%s' "$MATRIX_JSON" | sha256sum | cut -c1-16)"
new_bytes="$(docker image inspect "$NEW_IMAGE" --format '{{.Size}}')"
if docker pull --platform linux/amd64 "$BASE_IMAGE" >/dev/null 2>&1; then
current_bytes="$(docker image inspect "$BASE_IMAGE" --format '{{.Size}}')"
else
current_bytes=""
echo "No published baseline image found for ${BASE_IMAGE}"
fi
jq -n \
--argjson matrix "$MATRIX_JSON" \
--arg base "$BASE_IMAGE" \
--arg current "$current_bytes" \
--arg new "$new_bytes" \
'{matrix: $matrix, baseImage: $base, currentBytes: $current, newBytes: $new}' \
> "size-report/${id}.json"
echo "id=${id}" >> "$GITHUB_OUTPUT"
- name: Upload image size report
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v7
with:
name: image-size-${{ steps.image-size.outputs.id }}
path: size-report/
retention-days: 1
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
username: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_USERNAME }}
password: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_TOKEN }}
- name: Build and push OCI image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.image-name }}
file: ./${{ matrix.image-name }}/Dockerfile
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
PLAYWRIGHT_VERSION=${{ matrix.playwright-version }}
CAMOUFOX_VERSION=${{ matrix.camoufox-version }}
platforms: ${{ matrix.supports-arm64 == 'true' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
provenance: true
push: true
tags: ${{ fromJson(steps.prepare-tags.outputs.result).allTags }}
outputs: type=image,oci-mediatypes=true
cache-from: type=gha,scope=${{ matrix.image-name }}-${{ matrix.python-version }}-${{ matrix.playwright-version }}-${{ matrix.camoufox-version }}
# Aggregate the per-image size reports uploaded by the build matrix and post/update
# a single sticky PR comment comparing current vs new image sizes.
size-report:
name: Report image size changes
needs: [build-main]
if: ${{ always() && github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
# All image workflows update sections of ONE shared PR comment; the repo-wide
# concurrency group serializes their read-modify-write so no section is lost.
concurrency:
group: image-size-comment-${{ github.event.pull_request.number }}
cancel-in-progress: false
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download image size reports
uses: actions/download-artifact@v8
continue-on-error: true
with:
pattern: image-size-*
path: size-reports
merge-multiple: true
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Render comment section
run: |
mkdir -p size-reports
node .github/scripts/format-image-size-report.ts size-reports "Python + Playwright images" "${{ github.event.pull_request.head.sha }}" | tee image-size-comment.md
- name: Post or update image size comment
uses: actions/github-script@v8
env:
SECTION_KEY: python-playwright
with:
script: |
const { readFileSync } = require('node:fs');
const upsertSection = require('./.github/scripts/upsert-image-size-comment.js');
await upsertSection({ github, context }, process.env.SECTION_KEY, readFileSync('image-size-comment.md', 'utf8'));