-
Notifications
You must be signed in to change notification settings - Fork 248
282 lines (247 loc) Β· 10.8 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
name: Build Engines
run-name: Build Engines for ${{ inputs.commit }}
# 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'
# paths-ignore:
# - '!.github/workflows/build-engines*'
# - '.github/**'
# - '.buildkite/**'
# - '*.md'
# - 'LICENSE'
# - 'CODEOWNERS'
# - 'renovate.json'
workflow_dispatch:
inputs:
commit:
description: 'Commit to build (from prisma-engines)'
required: false
pull_request:
# paths-ignore:
# - '!.github/workflows/build-engines*'
# - '.github/**'
# - '.buildkite/**'
# - '*.md'
# - 'LICENSE'
# - 'CODEOWNERS'
# - 'renovate.json'
jobs:
build-linux:
name: Build Engines for Linux
uses: ./.github/workflows/build-engines-linux-template.yml
with:
commit: ${{ inputs.commit }}
build-macos-intel:
name: Build Engines for Apple Intel
uses: ./.github/workflows/build-engines-apple-intel-template.yml
with:
commit: ${{ inputs.commit }}
build-macos-silicon:
name: Build Engines for Apple Silicon
uses: ./.github/workflows/build-engines-apple-silicon-template.yml
with:
commit: ${{ inputs.commit }}
build-react-native:
name: Build Engines for React native
uses: ./.github/workflows/build-engines-react-native-template.yml
with:
commit: ${{ inputs.commit }}
build-windows:
name: Build Engines for Windows
uses: ./.github/workflows/build-engines-windows-template.yml
with:
commit: ${{ inputs.commit }}
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:
- name: Debug Pull Request Event
if: ${{ github.event_name == 'pull_request' }}
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
echo "Pull Request: ${{ github.event.pull_request.number }}"
echo "Pull Request Author: ${{ github.event.pull_request.user.login }}"
echo "Pull Request Author Association: ${{ github.event.pull_request.author_association }}"
echo "Pull Request Body contains /integration: ${{ contains(env.PR_BODY, '/integration') }}"
- name: 'Check if the PR body contains `/integration` and the PR author has permissions to trigger the workflow'
id: check-pr-description
env:
PR_BODY: ${{ github.event.pull_request.body }}
# See https://docs.github.com/en/graphql/reference/enums
# https://michaelheap.com/github-actions-check-permission/
# Check if
# - the PR body 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(env.PR_BODY, '/integration') &&
(
github.event.pull_request.author_association == 'OWNER' ||
github.event.pull_request.author_association == 'MEMBER' ||
github.event.pull_request.author_association == 'COLLABORATOR' ||
github.event.pull_request.author_association == 'CONTRIBUTOR'
)
run: |
echo "PR body contains /integration and PR author has permissions"
# set value to GitHub output
echo "release=true" >> $GITHUB_OUTPUT
- name: Find "/integration" comment
uses: peter-evans/find-comment@v3
id: check-comments
if: ${{ github.event_name == 'pull_request' }}
with:
issue-number: ${{ github.event.pull_request.number }}
body-includes: '/integration'
- name: Debug event & outputs
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_PATH: ${{ github.event_path }}
CHECK_PR_DESC: ${{ steps.check-pr-description.outputs.release }}
CHECK_COMMENT: ${{ steps.check-comments.outputs.comment-id }}
run: |
echo "Event Name: $EVENT_NAME"
echo "Event path: $EVENT_PATH"
echo "Check PR Description outputs: $CHECK_PR_DESC"
echo "Check Comments outputs: $CHECK_COMMENT"
- 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-comments.outputs.comment-id != 0 || steps.check-pr-description.outputs.release == 'true'
id: decision
env:
EVENT_NAME: ${{ github.event_name }}
EVENT_PATH: ${{ github.event_path }}
CHECK_PR_DESC: ${{ steps.check-pr-description.outputs.release }}
CHECK_COMMENT: ${{ steps.check-comments.outputs.comment-id }}
run: |
echo "Event Name: $EVENT_NAME"
echo "Event path: $EVENT_PATH"
echo "Check PR Description outputs: $CHECK_PR_DESC"
echo "Check Comments outputs: $CHECK_COMMENT"
echo "Release is necessary"
echo "release=true" >> $GITHUB_OUTPUT
release-artifacts:
name: 'Release artifacts from branch ${{ github.event.ref }} for commit ${{ inputs.commit }}'
runs-on: ubuntu-22.04
concurrency:
group: ${{ inputs.commit || github.sha }}
needs:
- is-release-necessary
- build-linux
- build-macos-intel
- build-macos-silicon
- build-react-native
- build-windows
if: ${{ needs.is-release-necessary.outputs.release == 'true' }}
env:
BUCKET_NAME: 'prisma-builds'
PRISMA_ENGINES_COMMIT_SHA: ${{ inputs.commit || github.sha }}
DESTINATION_TARGET_PATH: 's3://prisma-builds/all_commits/${{ inputs.commit || 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/${{ inputs.commit }}/.finished'
FILE_PATH_LEGACY: 'all_commits/${{ inputs.commit }}/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/${{ inputs.commit }}/.finished'
FILE_PATH_LEGACY: 'all_commits/${{ inputs.commit }}/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: Cleanup local directories
run: rm -rf engines-artifacts engines-artifacts-for-r2 engines-artifacts-for-s3