-
Notifications
You must be signed in to change notification settings - Fork 13
305 lines (263 loc) · 9.95 KB
/
publish-go-nightly-task.yml
File metadata and controls
305 lines (263 loc) · 9.95 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
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/publish-go-nightly-task.md
name: Publish Nightly Build
env:
# As defined by the Taskfile's PROJECT_NAME variable
PROJECT_NAME: arduino-lint
# As defined by the Taskfile's DIST_DIR variable
DIST_DIR: dist
# The project's folder on Arduino's download server for uploading builds
AWS_PLUGIN_TARGET: /arduino-lint/
AWS_REGION: "us-east-1"
ARTIFACT_PREFIX: dist-
# See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
on:
schedule:
# run every day at 1AM
- cron: "0 1 * * *"
workflow_dispatch:
repository_dispatch:
jobs:
create-nightly-artifacts:
runs-on: ${{ matrix.os.runner }}
permissions:
contents: read
strategy:
matrix:
os:
- task: Windows_32bit
artifact-suffix: Windows_32bit
runner: ubuntu-latest
- task: Windows_64bit
artifact-suffix: Windows_64bit
runner: ubuntu-latest
- task: Windows_ARM64
artifact-suffix: Windows_ARM64
runner: ubuntu-24.04-arm
- task: Linux_32bit
artifact-suffix: Linux_32bit
runner: ubuntu-latest
- task: Linux_64bit
artifact-suffix: Linux_64bit
runner: ubuntu-latest
- task: Linux_ARMv6
artifact-suffix: Linux_ARMv6
runner: ubuntu-latest
- task: Linux_ARMv7
artifact-suffix: Linux_ARMv7
runner: ubuntu-latest
- task: Linux_ARM64
artifact-suffix: Linux_ARM64
runner: ubuntu-24.04-arm
- task: macOS_64bit
artifact-suffix: macOS_64bit
runner: ubuntu-latest
- task: macOS_ARM64
artifact-suffix: macOS_ARM64
runner: ubuntu-24.04-arm
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Build
env:
NIGHTLY: true
run: |
go tool \
github.com/go-task/task/v3/cmd/task dist:${{ matrix.os.task }}
- name: Upload artifacts
uses: actions/upload-artifact@v6
with:
if-no-files-found: error
name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.os.artifact-suffix }}
path: ${{ env.DIST_DIR }}
notarize-macos:
name: Notarize ${{ matrix.build.folder-suffix }}
runs-on: macos-latest
needs: create-nightly-artifacts
permissions:
contents: read
env:
GON_CONFIG_PATH: gon.config.hcl
strategy:
matrix:
build:
- artifact-suffix: macOS_64bit
folder-suffix: darwin_amd64
package-suffix: "macOS_64bit.tar.gz"
- artifact-suffix: macOS_ARM64
folder-suffix: darwin_arm64
package-suffix: "macOS_ARM64.tar.gz"
steps:
- name: Set environment variables
run: |
# See: https://docs.github.com/actions/reference/workflows-and-actions/workflow-commands#setting-an-environment-variable
echo "BUILD_FOLDER=${{ env.PROJECT_NAME }}_osx_${{ matrix.build.folder-suffix }}" >>"$GITHUB_ENV"
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Download artifacts
uses: actions/download-artifact@v7
with:
name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.build.artifact-suffix }}
path: ${{ env.DIST_DIR }}
- name: Import Code-Signing Certificates
env:
KEYCHAIN: "sign.keychain"
INSTALLER_CERT_MAC_PATH: "/tmp/ArduinoCerts2020.p12"
# Arbitrary password for a keychain that exists only for the duration of the job, so not secret
KEYCHAIN_PASSWORD: keychainpassword
run: |
echo "${{ secrets.INSTALLER_CERT_MAC_P12 }}" | base64 --decode >"${{ env.INSTALLER_CERT_MAC_PATH }}"
security create-keychain \
-p "${{ env.KEYCHAIN_PASSWORD }}" \
"${{ env.KEYCHAIN }}"
security default-keychain \
-s "${{ env.KEYCHAIN }}"
security unlock-keychain \
-p "${{ env.KEYCHAIN_PASSWORD }}" \
"${{ env.KEYCHAIN }}"
security import \
"${{ env.INSTALLER_CERT_MAC_PATH }}" \
-k "${{ env.KEYCHAIN }}" \
-f pkcs12 \
-A \
-T /usr/bin/codesign \
-P '${{ secrets.INSTALLER_CERT_MAC_PASSWORD }}'
security set-key-partition-list \
-S apple-tool:,apple: \
-s \
-k "${{ env.KEYCHAIN_PASSWORD }}" \
"${{ env.KEYCHAIN }}"
- name: Write gon config to file
# gon does not allow env variables in config file (https://github.com/mitchellh/gon/issues/20)
run: |
cat >"${{ env.GON_CONFIG_PATH }}" \
<<EOF
# See: https://github.com/Bearer/gon#configuration-file
source = ["${{ env.DIST_DIR }}/${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"]
bundle_id = "cc.arduino.${{ env.PROJECT_NAME }}"
sign {}
# Ask Gon for zip output to force notarization process to take place.
# The CI will ignore the zip output, using the signed binary only.
zip {
output_path = "unused.zip"
}
EOF
- name: Sign and notarize binary
env:
AC_APPLICATION_IDENTITY: ${{ vars.AC_APPLICATION_IDENTITY }}
AC_USERNAME: ${{ secrets.AC_USERNAME }}
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
AC_PROVIDER: ${{ vars.AC_PROVIDER }}
run: |
go tool \
github.com/bearer/gon/cmd/gon "${{ env.GON_CONFIG_PATH }}"
- name: Re-package binary
working-directory: ${{ env.DIST_DIR }}
# Repackage the signed binary replaced in place by Gon (ignoring the output zip file)
run: |
# GitHub's upload/download-artifact actions don't preserve file permissions,
# so we need to add execution permission back until the action is made to do this.
chmod \
+x \
"${{ env.BUILD_FOLDER }}/${{ env.PROJECT_NAME }}"
# Use of an array here is required for globbing
PACKAGE_FILENAME=(${{ env.PROJECT_NAME }}_nightly-*${{ matrix.build.package-suffix }})
tar \
-czvf "$PACKAGE_FILENAME" \
-C "${{ env.BUILD_FOLDER }}/" \
"${{ env.PROJECT_NAME }}" \
-C ../../ \
LICENSE.txt
echo "PACKAGE_FILENAME=$PACKAGE_FILENAME" >>$GITHUB_ENV
- name: Replace artifact with notarized build
uses: actions/upload-artifact@v6
with:
if-no-files-found: error
name: ${{ env.ARTIFACT_PREFIX }}${{ matrix.build.artifact-suffix }}
overwrite: true
path: ${{ env.DIST_DIR }}/${{ env.PACKAGE_FILENAME }}
checksums:
needs: notarize-macos
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Set environment variables
run: |
# See: https://docs.github.com/actions/reference/workflows-and-actions/workflow-commands#setting-an-environment-variable
TAG="nightly-$(date -u +"%Y%m%d")"
echo "CHECKSUM_FILE_PATH=${{ runner.temp }}/${TAG}-checksums.txt" >>"$GITHUB_ENV"
echo "TAG=$TAG" >>"$GITHUB_ENV"
- name: Download artifacts
uses: actions/download-artifact@v7
with:
merge-multiple: true
path: ${{ env.DIST_DIR }}
pattern: ${{ env.ARTIFACT_PREFIX }}*
- name: Create checksum file
working-directory: ${{ env.DIST_DIR }}
run: |
sha256sum ${{ env.PROJECT_NAME }}_${{ env.TAG }}* >"${{ env.CHECKSUM_FILE_PATH }}"
- name: Upload checksum artifact
uses: actions/upload-artifact@v6
with:
if-no-files-found: error
name: ${{ env.ARTIFACT_PREFIX }}checksums
path: ${{ env.CHECKSUM_FILE_PATH }}
publish-nightly:
runs-on: ubuntu-latest
environment: production
needs: checksums
permissions:
contents: write
id-token: write # This is required for requesting the JWT
steps:
- name: Determine whether publishing to AWS is possible
id: aws-determination
run: |
echo "publish=${{ secrets.AWS_ROLE_TO_ASSUME != '' }}" >>$GITHUB_OUTPUT
- name: Download artifact
if: steps.aws-determination.outputs.publish == 'true'
uses: actions/download-artifact@v7
with:
pattern: ${{ env.ARTIFACT_PREFIX }}*
merge-multiple: true
path: ${{ env.DIST_DIR }}
- name: configure aws credentials
if: steps.aws-determination.outputs.publish == 'true'
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: "github_${{ env.PROJECT_NAME }}"
aws-region: ${{ env.AWS_REGION }}
- name: Upload release files on Arduino downloads servers
if: steps.aws-determination.outputs.publish == 'true'
run: |
aws s3 sync \
${{ env.DIST_DIR }} \
s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.AWS_PLUGIN_TARGET }}nightly
report:
runs-on: ubuntu-latest
needs: publish-nightly
if: failure() # Run if publish-nightly or any of its job dependencies failed
permissions: {}
steps:
- name: Report failure
uses: masci/datadog@v1
with:
api-key: ${{ secrets.DD_API_KEY }}
events: |
- title: "${{ env.PROJECT_NAME }} nightly build failed"
text: "Nightly build workflow has failed"
alert_type: "error"
host: ${{ github.repository }}
tags:
- "project:${{ env.PROJECT_NAME }}"
- "workflow:${{ github.workflow }}"