-
Notifications
You must be signed in to change notification settings - Fork 6
298 lines (273 loc) · 14.3 KB
/
build.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
name: 'Build OT2 image on github workflows'
run-name: 'image: mono ${{ inputs.monorepo-ref }}, buildroot ${{ inputs.buildroot-ref }}'
on:
workflow_dispatch:
inputs:
monorepo-ref:
description: |
Ref of https://github.com/opentrons/opentrons to build. This MUST be a full ref, e.g. refs/heads/edge, or '-' to indicate not-specified. If not specified, will be determined from the oe-core ref if specified, and then default to edge.
required: true
default: '-'
buildroot-ref:
description: |
Ref of https://github.com/opentrons/buildroot to build. This is different from the ref specified in the github api/webUI when starting this workflow - that ref is what contains this workflow, this ref specifies what gets built. It MUST be a full ref, e.g. refs/heads/main, or '-' to indicate not-specified. If not specified, will be decided based on the monorepo ref; if that isn't specified, will be main.
required: true
default: '-'
infra-stage:
description: |
What infra stage to run on. This should almost always be prod; dev is useful when you explicitly want to test that stage.
required: true
type: choice
options:
- 'stage-prod'
- 'stage-dev'
default: 'stage-prod'
env:
CI: true
jobs:
decide-refs:
name: 'Decide refs to build'
runs-on: 'ubuntu-latest'
outputs:
buildroot: ${{ steps.build-refs.outputs.buildroot }}
monorepo: ${{ steps.build-refs.outputs.monorepo }}
variant: ${{ steps.build-refs.outputs.variant }}
build-type: ${{ steps.build-refs.outputs.build-type }}
steps:
- name: Check out sources for action
uses: 'actions/checkout@v3'
with:
path: ./buildroot-for-workflow
- name: Get the refs
id: build-refs
uses: './buildroot-for-workflow/.github/actions/build-refs'
with:
token: ${{ github.token }}
monorepo: ${{ inputs.monorepo-ref }}
buildroot: ${{ inputs.buildroot-ref }}
run-build:
needs: decide-refs
strategy:
matrix:
build_env: [ '${{ inputs.infra-stage }}', ]
name: 'Building ${{needs.decide-refs.outputs.variant}} images on ${{ matrix.build_env }}'
timeout-minutes: 480
runs-on: ['self-hosted', '${{matrix.build_env}}', '${{needs.decide-refs.outputs.variant}}']
concurrency:
group: ${{needs.decide-refs.outputs.monorepo}} ${{needs.decide-refs.outputs.buildroot}} ${{needs.decide-refs.outputs.variant}} ${{needs.decide-refs.outputs.build-type}} ${{inputs.infra-stage}}
cancel-in-progress: false
steps:
- name: Set up vm requirements
run: |
echo 'fs.inotify.max_user_watches=655360' | tee -a /etc/sysctl.conf
echo 'fs.inotify.max_user_instances=1280' | tee -a /etc/sysctl.conf
echo 'fs.file-max=100000' | tee -a /etc/sysctl.conf
sysctl -p
- name: Fetch initial sources for action
uses: 'actions/checkout@v3'
with:
fetch-depth: 0
path: ./buildroot-for-workflow
- name: Fetch buildroot source
uses: 'actions/checkout@v3'
with:
fetch-depth: 0
ref: ${{needs.decide-refs.outputs.buildroot}}
path: ./buildroot
- name: Fetch monorepo source
uses: 'actions/checkout@v3'
with:
fetch-depth: 0
ref: ${{ needs.decide-refs.outputs.monorepo }}
repository: Opentrons/opentrons
path: ./opentrons
- name: Configure AWS Credentials
uses: './buildroot-for-workflow/.github/actions/aws-credentials'
id: aws
with:
access_key_id: ${{ secrets.ROBOT_STACK_AWS_ACCESS_KEY_ID }}
secret_access_key: ${{ secrets.ROBOT_STACK_AWS_SECRET_ACCESS_KEY }}
region: us-east-2
stage: ${{ matrix.build_env }}
- name: Pull or create cache locations
id: cache-setup
run: |
cachedir=${LOCAL_CACHE:-./cache}
for cachetype in downloads output ; do
absdir="${cachedir}/${cachetype}"
mkdir -p ${absdir}
echo "${cachetype}=${absdir}" >> $GITHUB_OUTPUT
here=$(pwd)
reldir=$(realpath --relative-to=${here} ${cachedir}/${cachetype})
echo "Created ${cachetype} cache at ${absdir} (${reldir})"
echo "${cachetype}-rel=${reldir}" >> $GITHUB_OUTPUT
done
- name: Set up docker environment file
id: docker-env
run: |
cat <<EOF >./docker-envfile
OT_BUILD_TYPE=${{needs.decide-refs.outputs.build-type}}
FORCE_UNSAFE_CONFIGURE=1
BR2_DL_DIR=/downloads
EOF
echo "envfile=$(pwd)/docker-envfile" >> $GITHUB_OUTPUT
- name: Build or download docker container
id: get-image
run: |
cd buildroot
imgname=$(./opentrons-build-container.sh pull || ./opentrons-build-container.sh build)
echo "image-name=$imgname" >> $GITHUB_OUTPUT
- name: Set up signing
if: needs.decide-refs.outputs.build-type == 'release'
run: |
echo "${{secrets.ROBOT_SIGNING_KEY}}" > ./buildroot/.signing-key
- name: Set up docker args
id: docker-args
run: |
if [ ${{needs.decide-refs.outputs.variant}} = "release" ] ; then
_project=robot-stack
else
_project=ot3
fi
echo "Stack name ${_project} from variant ${{needs.decide-refs.outputs.variant}}"
mount_args="type=bind,consistency=delegated"
bind_br="--mount source=$(pwd)/buildroot,destination=/buildroot,${mount_args}"
bind_ot="--mount source=$(pwd)/opentrons,destination=/opentrons,${mount_args}"
bind_dl="--mount source=${{steps.cache-setup.outputs.downloads}},destination=/downloads,${mount_args}"
bind_op="--mount source=${{steps.cache-setup.outputs.output}},destination=/output,${mount_args}"
binds="${bind_br} ${bind_ot} ${bind_dl} ${bind_op}"
env="--env-file ${{steps.docker-env.outputs.envfile}}"
echo "run-binds=${binds}" >> $GITHUB_OUTPUT
echo "env=${env}" >> $GITHUB_OUTPUT
args="${binds} ${env} ${{steps.get-image.outputs.image-name}} O=/output OPENTRONS_PROJECT=${_project}"
echo "args=${args}" >> $GITHUB_OUTPUT
- name: Configure
run: |
cd buildroot
docker run ${{steps.docker-args.outputs.args}} ot2_defconfig
- name: Download package sources
run: |
cd buildroot
docker run ${{steps.docker-args.outputs.args}} source
- name: Run build
run: |
cd buildroot
docker run ${{steps.docker-args.outputs.args}} all
- name: Upload build log result
if: always()
uses: actions/upload-artifact@v3
with:
name: buildlog.txt
path: ./buildroot/buildlog.txt
- name: Prep artifacts for upload
id: artifact-copy
run: |
artifact_dir="${{steps.cache-setup.outputs.output}}/images"
prepped_artifact_dir="${{steps.cache-setup.outputs.output}}/unversioned_artifacts"
mkdir -p ${prepped_artifact_dir}
echo "prepped_artifact_dir=${prepped_artifact_dir}" >> $GITHUB_OUTPUT
versioned_artifact_dir_rel="./versioned_artifacts"
versioned_artifact_dir=$(realpath ${versioned_artifact_dir_rel})
mkdir -p ${versioned_artifact_dir}
echo "versioned_artifact_dir=${versioned_artifact_dir}" >> $GITHUB_OUTPUT
echo "versioned_artifact_dir_rel=${versioned_artifact_dir_rel}" >> $GITHUB_OUTPUT
_fulltag="${{needs.decide-refs.outputs.monorepo}}"
echo "monorepo_shorttag=${_fulltag:10}" >> $GITHUB_OUTPUT
_vers_tag=${{needs.decide-refs.outputs.variant == 'release' && '${_fulltag:11}' || '${_fulltag:14}'}}
cp ${artifact_dir}/ot2-system.zip ${prepped_artifact_dir}/ot2-system.zip
echo "ot2_system=${prepped_artifact_dir}/ot2-system.zip" >> $GITHUB_OUTPUT
cp ${artifact_dir}/ot2-fullimage.zip ${prepped_artifact_dir}/ot2-fullimage.zip
echo "ot2_fullimage=${prepped_artifact_dir}/ot2-fullimage.zip" >> $GITHUB_OUTPUT
cp ${artifact_dir}/VERSION.json ${prepped_artifact_dir}/VERSION.json
echo "version_json=${prepped_artifact_dir}/VERSION.json" >> $GITHUB_OUTPUT
cp ${artifact_dir}/release-notes.md ${prepped_artifact_dir}/release-notes.md
echo "release_notes=${prepped_artifact_dir}/release-notes.md" >> $GITHUB_OUTPUT
versioned_system_zip="ot2-system-${_vers_tag}.zip"
cp ${artifact_dir}/ot2-system.zip "${versioned_artifact_dir}/${versioned_system_zip}"
echo "ot2_system_versioned=${versioned_artifact_dir}/${versioned_system_zip}" >> $GITHUB_OUTPUT
versioned_fullimage_zip="ot2-fullimage-${_vers_tag}.zip"
cp ${artifact_dir}/ot2-fullimage.zip ${versioned_artifact_dir}/${versioned_fullimage_zip}
echo "ot2_fullimage_versioned=${versioned_artifact_dir}/${versioned_fullimage_zip}" >> $GITHUB_OUTPUT
versioned_version_json="VERSION-ot2-${_vers_tag}.json"
cp ${artifact_dir}/VERSION.json ${versioned_artifact_dir}/${versioned_version_json}
echo "version_json_versioned=${versioned_artifact_dir}/${versioned_version_json}" >> $GITHUB_OUTPUT
echo "Prepared unversioned artifacts: $(find ${prepped_artifact_dir}/)"
echo "Prepared versioned artifacts: $(find ${versioned_artifact_dir}/)"
- name: Upload results to S3
shell: bash
id: 'upload-results'
run: |
prefix=ot2-br
arnslug=${S3_ARTIFACT_ARN/arn:aws:s3:::/}
root_uri=${arnslug}/${prefix}/${{github.run_id}}
pushd ${{steps.artifact-copy.outputs.prepped_artifact_dir}}
aws --profile=${{ steps.aws.outputs.profile_name }} s3 cp --recursive --acl=public-read . s3://${root_uri}/
root_url=https://${root_uri}
echo "console_url=https://s3.console.aws.amazon.com/s3/buckets/${arnslug}?prefix=${{github.run_id}}" >> $GITHUB_OUTPUT
echo "version_file_url=$root_url/VERSION.json" >> $GITHUB_OUTPUT
echo "release_notes_file_url=$root_url/release-notes.md" >> $GITHUB_OUTPUT
echo "system_url=$root_url/ot2-system.zip" >> $GITHUB_OUTPUT
echo "fullimage_url=$root_url/ot2-fullimage.zip" >> $GITHUB_OUTPUT
echo "arnslug=$arnslug" >> $GITHUB_OUTPUT
echo "root_uri=$root_uri" >> $GITHUB_OUTPUT
echo "root_url=$root_url" >> $GITHUB_OUTPUT
echo "root_prefix=ot2-br" >> $GITHUB_OUTPUT
echo "machine_root=${arnslug}/${prefix}" >> $GITHUB_OUTPUT
popd
- name: Handle release manifest
if: ${{ needs.decide-refs.outputs.build-type == 'release' }}
shell: bash
run: |
pushd buildroot
aws --profile=${{ steps.aws.outputs.profile_name }} s3 cp --acl=public-read s3://${{steps.upload-results.outputs.machine_root}}/releases.json releases.json
python3 update_releases_file.py --releases-file releases.json --version-file ${{steps.artifact-copy.outputs.version_json}} --base-url ${{ steps.upload-results.outputs.root_url }}
aws --profile=${{ steps.aws.outputs.profile_name }} s3 cp --acl=public-read releases.json s3://${{steps.upload-results.outputs.machine_root}}/releases.json
popd
- name: Upload system zip to monorepo release
if: needs.decide-refs.outputs.build-type == 'release'
uses: 'ncipollo/[email protected]'
with:
allowUpdates: true
omitBody: true
omitName: true
omitPrereleaseDuringUpdate: true
omitDraftDuringUpdate: true
repo: opentrons
tag: ${{ steps.artifact-copy.outputs.monorepo_shorttag }}
artifacts: "${{steps.artifact-copy.outputs.versioned_artifact_dir_rel}}/ot2-*.zip"
artifactContentType: application/zip
token: ${{secrets.MONOREPO_RELEASE_ARTIFACT_UPLOAD_TOKEN}}
- name: Upload version json to monorepo release
if: needs.decide-refs.outputs.build-type == 'release'
uses: 'ncipollo/[email protected]'
with:
allowUpdates: true
omitBody: true
omitName: true
omitPrereleaseDuringUpdate: true
omitDraftDuringUpdate: true
repo: opentrons
tag: ${{ steps.artifact-copy.outputs.monorepo_shorttag }}
artifacts: "${{steps.artifact-copy.outputs.versioned_artifact_dir_rel}}/VERSION-*.json"
artifactContentType: application/json
token: ${{secrets.MONOREPO_RELEASE_ARTIFACT_UPLOAD_TOKEN}}
- name: Post results as internal-release
if: matrix.build_env == 'stage-prod' && needs.decide-refs.outputs.variant == 'internal-release'
uses: slackapi/[email protected]
with:
payload: "{\"s3-url\":\"${{ steps.upload-results.outputs.console_url }}/\",\"type\":\"branch\", \"reflike\":\"${{ needs.decide-refs.outputs.buildroot }}\",\"monorepo-reflike\":\"${{ needs.decide-refs.outputs.monorepo }}\",\"full-image\":\"${{ steps.upload-results.outputs.fullimage_url }}\", \"system-update\":\"${{ steps.upload-results.outputs.system_url }}\", \"version-file\":\"${{ steps.upload-results.outputs.version_file_url }}\", \"release-notes\":\"${{ steps.upload-results.outputs.release_notes_file_url }}\"}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_INTERNAL_RELEASE }}
- name: Post results as release
if: matrix.build_env == 'stage-prod' && needs.decide-refs.outputs.variant == 'release'
uses: slackapi/[email protected]
with:
payload: "{\"s3-url\":\"${{ steps.upload-results.outputs.console_url }}/\",\"type\":\"branch\", \"reflike\":\"${{ needs.decide-refs.outputs.buildroot }}\",\"monorepo-reflike\":\"${{ needs.decide-refs.outputs.monorepo }}\",\"full-image\":\"${{ steps.upload-results.outputs.fullimage_url }}\", \"system-update\":\"${{ steps.upload-results.outputs.system_url }}\", \"version-file\":\"${{ steps.upload-results.outputs.version_file_url }}\", \"release-notes\":\"${{ steps.upload-results.outputs.release_notes_file_url }}\"}"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_RELEASE }}
- name: remove build data
if: always()
run: |
rm -rf ./*
output_check=${{steps.cache-setup.outputs.output}}
rm -rf ${output_check:-/does/not/exist}