-
Notifications
You must be signed in to change notification settings - Fork 240
330 lines (294 loc) Β· 12.5 KB
/
build-engines.yml
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
name: Build Engines
run-name: Build Engines for ${{ github.sha }}
# Run on `push` only for main, if not it will trigger `push` & `pull_request` on PRs at the same time
on:
push:
branches:
- main
- '*.*.x'
- 'integration/*'
paths-ignore:
- '!.github/workflows/build-engines*'
- '.github/**'
- '.buildkite/**'
- '*.md'
- 'LICENSE'
- 'CODEOWNERS'
- 'renovate.json'
workflow_dispatch:
pull_request:
paths-ignore:
- '!.github/workflows/build-engines*'
- '.github/**'
- '.buildkite/**'
- '*.md'
- 'LICENSE'
- 'CODEOWNERS'
- 'renovate.json'
jobs:
is-release-necessary:
name: 'Decide if a release of the engines artifacts is necessary'
runs-on: ubuntu-22.04
outputs:
release: ${{ steps.decision.outputs.release }}
steps:
- uses: actions/checkout@v4
with:
# using head ref rather than merge branch to get original commit message
ref: ${{ github.event.pull_request.head.sha }}
- name: Get commit message
id: commit-msg
run: |
commit_msg=$(git log --format=%B -n 1)
echo 'commit-msg<<EOF' >> $GITHUB_OUTPUT
echo "$commit_msg" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Debug Pull Request Event
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "Pull Request: ${{ github.event.pull_request.number }}"
echo "Repository Owner: ${{ github.repository_owner }}"
echo "Pull Request Author: ${{ github.actor }}"
echo "Pull Request Author Association: ${{ github.event.pull_request.author_association }}"
cat <<END_OF_COMMIT_MESSAGE
Commit message:
${{ steps.commit-msg.outputs.commit-msg }}
END_OF_COMMIT_MESSAGE
echo "Commit message contains [integration]: ${{ contains(steps.commit-msg.outputs.commit-msg, '[integration]') }}"
- name: 'Check if commit message conatains `[integration]` and the PR author has permissions to trigger the workflow'
id: check-commit-message
# See https://docs.github.com/en/graphql/reference/enums
# https://michaelheap.com/github-actions-check-permission/
# Check if
# - the commit message contains `[integration]`
# - the PR author has permissions to trigger the workflow (must be part of the org or a collaborator)
if: |
github.event_name == 'pull_request' &&
contains(steps.commit-msg.outputs.commit-msg, '[integration]') &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'CONTRIBUTOR' ||
github.event.pull_request.author_association == 'COLLABORATOR'
)
run: |
echo "Commit message contains [integration] and PR author has permissions"
# set value to GitHub output
echo "release=true" >> $GITHUB_OUTPUT
#
# A patch branch (e.g. "4.6.x")
#
- name: Check if branch is a patch or integration branch
id: check-branch
uses: actions/github-script@v7
env:
BRANCH: ${{ github.ref }}
with:
script: |
const { BRANCH } = process.env
const parts = BRANCH.split('.')
if (parts.length === 3 && parts[2] === 'x') {
console.log(`Branch is a patch branch: ${BRANCH}`)
core.setOutput('release', true)
} else if (BRANCH.startsWith("integration/")) {
console.log(`Branch is an "integration/" branch: ${BRANCH}`)
core.setOutput('release', true)
} else {
core.setOutput('release', false)
}
- name: Debug event & outputs
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_PATH: ${{ github.event_path }}
CHECK_COMMIT_MESSAGE: ${{ steps.check-commit-message.outputs.release }}
CHECK_BRANCH: ${{ steps.check-branch.outputs.release }}
run: |
echo "Event Name: $EVENT_NAME"
echo "Event path: $EVENT_PATH"
echo "Check Commit Message outputs: $CHECK_COMMIT_MESSAGE"
echo "Check branch: $CHECK_BRANCH"
- name: Release is necessary!
# https://github.com/peter-evans/find-comment/tree/v3/?tab=readme-ov-file#outputs
# Tip: Empty strings evaluate to zero in GitHub Actions expressions. e.g. If comment-id is an empty string steps.fc.outputs.comment-id == 0 evaluates to true.
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
steps.check-commit-message.outputs.release == 'true' ||
steps.check-branch.outputs.release == 'true'
id: decision
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_PATH: ${{ github.event_path }}
CHECK_COMMIT_MESSAGE: ${{ steps.check-commit-message.outputs.release }}
CHECK_BRANCH: ${{ steps.check-branch.outputs.release }}
run: |
echo "Event Name: $EVENT_NAME"
echo "Event path: $EVENT_PATH"
echo "Check Commit Message outputs: $CHECK_COMMIT_MESSAGE"
echo "Check branch: $CHECK_BRANCH"
echo "Release is necessary"
echo "release=true" >> $GITHUB_OUTPUT
build-linux:
name: Build Engines for Linux
needs:
- is-release-necessary
if: ${{ needs.is-release-necessary.outputs.release == 'true' }}
uses: ./.github/workflows/build-engines-linux-template.yml
with:
commit: ${{ github.sha }}
build-macos-intel:
name: Build Engines for Apple Intel
needs:
- is-release-necessary
if: ${{ needs.is-release-necessary.outputs.release == 'true' }}
uses: ./.github/workflows/build-engines-apple-intel-template.yml
with:
commit: ${{ github.sha }}
build-macos-silicon:
name: Build Engines for Apple Silicon
needs:
- is-release-necessary
if: ${{ needs.is-release-necessary.outputs.release == 'true' }}
uses: ./.github/workflows/build-engines-apple-silicon-template.yml
with:
commit: ${{ github.sha }}
build-react-native:
name: Build Engines for React native
needs:
- is-release-necessary
if: ${{ needs.is-release-necessary.outputs.release == 'true' }}
uses: ./.github/workflows/build-engines-react-native-template.yml
with:
commit: ${{ github.sha }}
build-windows:
name: Build Engines for Windows
needs:
- is-release-necessary
if: ${{ needs.is-release-necessary.outputs.release == 'true' }}
uses: ./.github/workflows/build-engines-windows-template.yml
with:
commit: ${{ github.sha }}
release-artifacts:
name: 'Release artifacts from branch ${{ github.head_ref || github.ref_name }} for commit ${{ github.sha }}'
runs-on: ubuntu-22.04
concurrency:
group: ${{ github.sha }}
needs:
- build-linux
- build-macos-intel
- build-macos-silicon
- build-react-native
- build-windows
env:
BUCKET_NAME: 'prisma-builds'
PRISMA_ENGINES_COMMIT_SHA: ${{ github.sha }}
DESTINATION_TARGET_PATH: 's3://prisma-builds/all_commits/${{ github.sha }}'
steps:
# Because we need the scripts
- name: Checkout git repository
uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: engines-artifacts
# For debug purposes
# A previous run ID can be specified, to avoid the build step
# First disable the build step, then specify the run ID
# The github-token is mandatory for this to work
# https://github.com/prisma/prisma-engines-builds/actions/runs/9526334324
# run-id: 9526334324
# github-token: ${{ secrets.GITHUB_TOKEN }}
- name: 'R2: Check if artifacts were already built and uploaded before via `.finished` file'
env:
FILE_PATH: 'all_commits/${{ github.sha }}/.finished'
FILE_PATH_LEGACY: 'all_commits/${{ github.sha }}/rhel-openssl-1.1.x/.finished'
AWS_DEFAULT_REGION: 'auto'
AWS_ACCESS_KEY_ID: ${{ vars.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL_S3: ${{ vars.R2_ENDPOINT }}
working-directory: .github/workflows/utils
run: bash checkFinishedMarker.sh
- name: 'S3: Check if artifacts were already built and uploaded before via `.finished` file'
env:
FILE_PATH: 'all_commits/${{ github.sha }}/.finished'
FILE_PATH_LEGACY: 'all_commits/${{ github.sha }}/rhel-openssl-1.1.x/.finished'
AWS_DEFAULT_REGION: 'eu-west-1'
AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
working-directory: .github/workflows/utils
run: bash checkFinishedMarker.sh
- name: Display structure of downloaded files
run: ls -Rl engines-artifacts
# TODO in a next major version of Prisma: remove this, and replace both `Debian` and `Rhel` with a single `LinuxGlibc`/`LinuxGnu` option.
- name: Duplicate engines for debian
working-directory: engines-artifacts
run: |
cp -r rhel-openssl-1.0.x debian-openssl-1.0.x
cp -r rhel-openssl-1.1.x debian-openssl-1.1.x
cp -r rhel-openssl-3.0.x debian-openssl-3.0.x
- name: Create .zip for react-native
working-directory: engines-artifacts
run: |
mkdir react-native
zip -r react-native/binaries.zip ios android
rm -rf ios android
- name: 'Create compressed engine files (.gz)'
working-directory: engines-artifacts
run: |
set -eu
find . -type f -not -name "*.zip" | while read filename; do
gzip -c "$filename" > "$filename.gz"
echo "$filename.gz file created."
done
ls -Rl .
- name: 'Create SHA256 checksum files (.sha256).'
working-directory: engines-artifacts
run: |
set -eu
find . -type f | while read filename; do
sha256sum "$filename" > "$filename.sha256"
echo "$filename.sha256 file created."
done
ls -Rl .
# https://github.com/crazy-max/ghaction-import-gpg
- name: Import GPG key
# See https://github.com/crazy-max/ghaction-import-gpg/releases
# v6 -> 01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4
# For security reasons, we should pin the version of the action
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_KEY_PASSPHRASE }}
- name: List keys
run: gpg -K
# next to each file (excluding .sha256 files)
- name: 'Create a GPG detached signature (.sig)'
working-directory: engines-artifacts
run: |
set -eu
for file in $(find . -type f ! -name "*.sha256"); do
gpg --detach-sign --armor --batch --output "${file#*/}.sig" "$file"
done
ls -Rl .
- name: 'Cloudflare R2: Upload to bucket and verify uploaded files then create `.finished` file'
# https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-envvars.html
env:
AWS_DEFAULT_REGION: 'auto'
AWS_ACCESS_KEY_ID: ${{ vars.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL_S3: ${{ vars.R2_ENDPOINT }}
run: bash .github/workflows/utils/uploadAndVerify.sh engines-artifacts-for-r2
- name: 'AWS S3: Upload to bucket and verify uploaded files then create `.finished` file'
env:
AWS_DEFAULT_REGION: 'eu-west-1'
AWS_ACCESS_KEY_ID: ${{ vars.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: bash .github/workflows/utils/uploadAndVerify.sh engines-artifacts-for-s3
- name: Repository dispatch to prisma/engines-wrapper
uses: peter-evans/repository-dispatch@v3
with:
repository: prisma/engines-wrapper
event-type: publish-engines
client-payload: '{ "commit": "${{ github.sha }}", "branch": "${{ github.head_ref || github.ref_name }}" }'
token: ${{ secrets.PRISMA_BOT_TOKEN }}
- name: Cleanup local directories
run: rm -rf engines-artifacts engines-artifacts-for-r2 engines-artifacts-for-s3