-
Notifications
You must be signed in to change notification settings - Fork 24
192 lines (159 loc) · 7.74 KB
/
release-node-playwright.yaml
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
name: Release Node + Playwright images
on:
workflow_dispatch:
inputs:
release_tag:
description: "Tag for the images (e.g.: beta)"
required: true
apify_version:
description: "Apify SDK version (e.g.: ^1.0.0). If missing, the latest version will be used."
required: false
crawlee_version:
description: "Crawlee version (e.g.: ^1.0.0). If missing, the latest version will be used."
required: false
repository_dispatch:
types:
- build-node-images
pull_request:
schedule:
- cron: 5 12 * * *
env:
RELEASE_TAG: ${{ github.event.inputs.release_tag || github.event.client_payload.release_tag }}
APIFY_VERSION: ${{ github.event.inputs.apify_version || github.event.client_payload.apify_version }}
CRAWLEE_VERSION: ${{ github.event.inputs.crawlee_version || github.event.client_payload.crawlee_version }}
SHOULD_USE_LAST_FIVE: ${{ github.event_name != 'pull_request' }}
SKIP_CACHE_CHECK: ${{ github.event_name == 'pull_request' }}
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up bun
uses: oven-sh/setup-bun@v2
- run: bun install
working-directory: ./.github/actions/version-matrix
- name: Generate matrix
id: set-matrix
run: echo "matrix=$(bun node:playwright)" >> $GITHUB_OUTPUT
working-directory: ./.github/actions/version-matrix
- name: Print matrix
run: |
echo '${{ steps.set-matrix.outputs.matrix }}' | jq -r '.include[] | "node-version=\(.["node-version"]) apify-version=\(.["apify-version"]) crawlee-version=\(.["crawlee-version"]) playwright-version=\(.["playwright-version"]) is-latest=\(.["is-latest"]) image-name=\(.["image-name"])"'
echo ""
echo "Raw matrix:"
echo ""
echo '${{ steps.set-matrix.outputs.matrix }}' | jq -e
- name: Push updated matrix
if: github.event_name != 'pull_request'
run: |
# Setup git user
git config --global user.email "noreply@apify.com"
git config --global user.name "Apify CI Bot"
git config pull.rebase true
# Add and commit if there are changes
git add ./.github/actions/version-matrix/data/*.json
git diff-index --quiet HEAD || git commit -m "chore(docker): update ${{ env.RELEASE_TAG || 'latest' }} node:playwright cache"
# Try to push 5 times, with pulls between retries
for i in {1..5}; do
git push && break || echo "Failed to push, retrying in 5 seconds..." && sleep 5 && git pull
done
# 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:
# By the time some build fails, other build can be already finished
# so fail-fast does not really prevent the publishing of all parallel builds
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
name: "img: ${{ matrix.image-name }} node: ${{ matrix.node-version }}, apify: ${{ matrix.apify-version }}, crawlee: ${{ matrix.crawlee-version }}, pw: ${{ matrix.playwright-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
if [[ -z "$APIFY_VERSION" ]]; then echo "APIFY_VERSION=${{ matrix.apify-version }}" >> $GITHUB_ENV; fi
if [[ -z "$CRAWLEE_VERSION" ]]; then echo "CRAWLEE_VERSION=${{ matrix.crawlee-version }}" >> $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
if [[ -z "$APIFY_VERSION" ]]; then echo "APIFY_VERSION=${{ matrix.apify-version }}" >> $GITHUB_ENV; fi
if [[ -z "$CRAWLEE_VERSION" ]]; then echo "CRAWLEE_VERSION=${{ matrix.crawlee-version }}" >> $GITHUB_ENV; fi
- name: Set default inputs if event is workflow_dispatch or repository_dispatch
if: github.event_name == 'workflow_dispatch' || github.event_name == 'repository_dispatch'
run: |
if [[ -z "$APIFY_VERSION" ]]; then echo "APIFY_VERSION=${{ matrix.apify-version }}" >> $GITHUB_ENV; fi
if [[ -z "$CRAWLEE_VERSION" ]]; then echo "CRAWLEE_VERSION=${{ matrix.crawlee-version }}" >> $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
if [[ -z "$APIFY_VERSION" ]]; then echo "APIFY_VERSION input is empty!" >&2; exit 1; fi
if [[ -z "$CRAWLEE_VERSION" ]]; then echo "CRAWLEE_VERSION input is empty!" >&2; exit 1; fi
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Set Dependency Versions
run: |
cd ${{ matrix.image-name }}
node ../.github/scripts/set-dependency-versions.js
env:
PLAYWRIGHT_VERSION: ${{ matrix.playwright-version }}
- # It seems that it takes at least two minutes before a newly published version
# becomes available in the NPM registry. We wait before starting the image builds.
name: Wait For Package Registry
uses: nick-fields/retry@v3
with:
timeout_minutes: 2 # timeout for a single attempt
max_attempts: 5
retry_wait_seconds: 60 # wait between retries
command: cd ${{ matrix.image-name }} && npm i --dry-run
- name: Prepare image tags
id: prepare-tags
uses: actions/github-script@v7
env:
CURRENT_NODE: ${{ matrix.node-version }}
LATEST_NODE: ${{ matrix.latest-node-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-node-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@v3
- name: Build and tag image
uses: docker/build-push-action@v6
with:
context: ./${{ matrix.image-name }}
file: ./${{ matrix.image-name }}/Dockerfile
# PLAYWRIGHT_VERSION here is used for the full node-playwright image
build-args: |
NODE_VERSION=${{ matrix.node-version }}
PLAYWRIGHT_VERSION=${{ format('v{0}-', matrix.playwright-version) }}
load: true
tags: ${{ fromJson(steps.prepare-tags.outputs.result).allTags }}
- name: Test image
run: docker run ${{ fromJson(steps.prepare-tags.outputs.result).firstImageName }}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_USERNAME }}
password: ${{ secrets.APIFY_SERVICE_ACCOUNT_DOCKERHUB_TOKEN }}
- name: Push images
if: github.event_name != 'pull_request'
run: docker push apify/actor-${{ matrix.image-name }} --all-tags