-
-
Notifications
You must be signed in to change notification settings - Fork 0
334 lines (296 loc) · 11 KB
/
release.yml
File metadata and controls
334 lines (296 loc) · 11 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
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
331
332
333
334
name: Release
on:
push:
tags:
- v[0-9].[0-9]+.[0-9]*
workflow_dispatch:
env:
MAKE_DEBUG: true
permissions:
id-token: write
security-events: write
actions: write
contents: write
pull-requests: read
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: ./go.mod
- name: Test
run: make test
build-linux:
name: Build Distribution (Linux)
needs: test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: ./go.mod
- name: Build Linux distribution
run: |
GIT_VERSION=${{ github.ref_name }} GO_OS="linux" make build-dist
- name: Install Cosign
uses: sigstore/cosign-installer@v3
- name: Sign Linux binaries with Cosign (keyless)
run: |
for arch in arm64 amd64; do
for bin in machineid; do
cosign sign-blob \
--yes \
--bundle "./dist/${bin}-linux-${arch}.sigstore.json" \
"./dist/${bin}-linux-${arch}"
done
done
- name: Upload Linux distribution files
uses: actions/upload-artifact@v6
with:
name: dist-linux
path: ./dist/
# build-sign-windows:
# name: Build & Sign Windows
# needs: test
# runs-on: windows-latest
# steps:
# - name: Check out code
# uses: actions/checkout@v6
#
# - name: Set up Go
# uses: actions/setup-go@v6
# with:
# go-version-file: ./go.mod
#
# - name: Build Windows binaries (arm64 & amd64)
# shell: pwsh
# run: |
# $ErrorActionPreference = 'Stop'
# $gitVersion = "${{ github.ref_name }}"
# $gitCommit = (git rev-parse HEAD).Trim()
# $gitBranch = (git rev-parse --abbrev-ref HEAD).Trim()
# $buildDate = [System.DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ")
# $gitUser = (git config --get user.email).Trim()
# $ns = "github.com/slashdevops/machineid/internal/version"
# $ldflags = "-s -w " +
# "-X `"${ns}.Version=${gitVersion}`" " +
# "-X `"${ns}.BuildDate=${buildDate}`" " +
# "-X `"${ns}.GitCommit=${gitCommit}`" " +
# "-X `"${ns}.GitBranch=${gitBranch}`" " +
# "-X `"${ns}.BuildUser=${gitUser}`"
#
# New-Item -ItemType Directory -Force -Path ./dist | Out-Null
# $env:CGO_ENABLED = "0"
# $env:GOOS = "windows"
#
# foreach ($arch in @("arm64", "amd64")) {
# $env:GOARCH = $arch
# foreach ($bin in @("machineid")) {
# Write-Host "Building ${bin}-windows-${arch}.exe"
# go build -v -ldflags $ldflags -o "./dist/${bin}-windows-${arch}.exe" "./cmd/${bin}/"
# }
# }
#
# - name: Azure Login
# uses: azure/login@v2
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS }}
#
# - name: Install Azure Trusted Signing PowerShell module
# shell: pwsh
# run: |
# Install-Module -Name TrustedSigning -RequiredVersion 0.4.1 -Force -Repository PSGallery
# Get-Module -ListAvailable -Name TrustedSigning
#
# - name: Sign Windows binaries
# shell: pwsh
# env:
# AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
# AZURE_TRUSTED_SIGNING_ACCOUNT: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT }}
# AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
# run: |
# Invoke-TrustedSigning `
# -Endpoint $env:AZURE_TRUSTED_SIGNING_ENDPOINT `
# -AccountName $env:AZURE_TRUSTED_SIGNING_ACCOUNT `
# -CertificateProfileName $env:AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE `
# -FilesFolder "./dist" `
# -FilesFolderFilter "*.exe" `
# -FilesFolderRecurse $false `
# -FileDigest SHA256 `
# -TimestampRfc3161 "http://timestamp.acs.microsoft.com" `
# -TimestampDigest SHA256
#
# - name: Generate checksums for signed Windows binaries
# shell: pwsh
# run: |
# New-Item -ItemType Directory -Force -Path ./dist/assets | Out-Null
# foreach ($arch in @("arm64", "amd64")) {
# foreach ($bin in @("machineid")) {
# $src = "./dist/${bin}-windows-${arch}.exe"
# $zip = "./dist/assets/${bin}-windows-${arch}.zip"
# $tmp = "./dist/zip-${bin}-windows-${arch}"
# New-Item -ItemType Directory -Force -Path $tmp | Out-Null
# Copy-Item $src -Destination "${tmp}/${bin}.exe"
# Compress-Archive -Path "${tmp}/${bin}.exe" -DestinationPath $zip -Force
# Remove-Item -Recurse -Force $tmp
# $hash = (Get-FileHash -Algorithm SHA256 $zip).Hash.ToLower()
# Set-Content -Path "./dist/assets/${bin}-windows-${arch}.sha256" -Value $hash
# }
# }
#
# - name: Upload signed Windows artifacts
# uses: actions/upload-artifact@v6
# with:
# name: dist-windows-signed
# path: ./dist/assets/
build-sign-macos:
name: Build, Sign & Notarize macOS
needs: test
runs-on: macos-latest
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: ./go.mod
- name: Build macOS binaries (arm64 & amd64)
run: |
GIT_VERSION=${{ github.ref_name }} GO_OS="darwin" make build-dist
- name: Import Apple signing certificate
env:
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
run: |
KEYCHAIN_PASSWORD=$(openssl rand -base64 32)
KEYCHAIN_PATH="$RUNNER_TEMP/build.keychain"
echo "$MACOS_CERTIFICATE" | base64 --decode > "$RUNNER_TEMP/certificate.p12"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security import "$RUNNER_TEMP/certificate.p12" \
-k "$KEYCHAIN_PATH" \
-P "$MACOS_CERTIFICATE_PASSWORD" \
-T /usr/bin/codesign \
-T /usr/bin/productsign
security list-keychain -d user -s "$KEYCHAIN_PATH"
security set-key-partition-list \
-S apple-tool:,apple: \
-s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
- name: Create universal binaries with lipo
run: |
mkdir -p ./dist/macos
for bin in machineid; do
lipo -create \
"./dist/${bin}-darwin-arm64" \
"./dist/${bin}-darwin-amd64" \
-output "./dist/macos/${bin}"
chmod +x "./dist/macos/${bin}"
done
- name: Sign universal binaries
env:
MACOS_SIGNING_IDENTITY: ${{ secrets.MACOS_SIGNING_IDENTITY }}
run: |
for bin in machineid; do
codesign --force \
--options runtime \
--sign "$MACOS_SIGNING_IDENTITY" \
--timestamp \
"./dist/macos/${bin}"
done
- name: Verify binary signatures
run: |
for bin in machineid; do
codesign --verify --verbose=4 "./dist/macos/${bin}"
done
- name: Create, sign, notarize & staple .pkg installers
env:
MACOS_INSTALLER_SIGNING_IDENTITY: ${{ secrets.MACOS_INSTALLER_SIGNING_IDENTITY }}
MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.MACOS_NOTARIZATION_APPLE_ID }}
MACOS_NOTARIZATION_PASSWORD: ${{ secrets.MACOS_NOTARIZATION_PASSWORD }}
MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.MACOS_NOTARIZATION_TEAM_ID }}
run: |
for bin in machineid; do
pkg="./dist/assets/${bin}-darwin-universal.pkg"
echo "📦 Creating .pkg for ${bin}..."
PKG_APP_NAME="${bin}" GIT_VERSION=${{ github.ref_name }} make build-dist-pkg
echo "🔏 Signing ${bin} .pkg..."
productsign \
--sign "$MACOS_INSTALLER_SIGNING_IDENTITY" \
"${pkg}" \
"${pkg}.signed"
mv "${pkg}.signed" "${pkg}"
echo "📤 Notarizing ${bin} .pkg..."
xcrun notarytool submit \
"${pkg}" \
--apple-id "$MACOS_NOTARIZATION_APPLE_ID" \
--password "$MACOS_NOTARIZATION_PASSWORD" \
--team-id "$MACOS_NOTARIZATION_TEAM_ID" \
--wait
echo "📎 Stapling ${bin} .pkg..."
xcrun stapler staple "${pkg}"
xcrun stapler validate "${pkg}"
echo "🔢 Generating ${bin} .pkg checksum..."
shasum -a 256 "${pkg}" \
| cut -d ' ' -f 1 > "./dist/assets/${bin}-darwin-universal.sha256"
done
- name: Clean up keychain
if: always()
run: security delete-keychain "$RUNNER_TEMP/build.keychain" || true
- name: Upload macOS pkg artifacts
uses: actions/upload-artifact@v6
with:
name: dist-macos
path: ./dist/assets/
create-github-release:
name: Create GitHub Release
# needs: [build-linux, build-sign-windows, build-sign-macos]
needs: [build-linux, build-sign-macos]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: ./go.mod
- name: Download Linux distribution files
uses: actions/download-artifact@v7
with:
name: dist-linux
path: ./dist/
# - name: Download signed Windows artifacts
# uses: actions/download-artifact@v7
# with:
# name: dist-windows-signed
# path: ./dist/assets/
- name: Download macOS pkg
uses: actions/download-artifact@v7
with:
name: dist-macos
path: ./dist/assets/
- name: Zip Linux binaries
run: |
GIT_VERSION=${{ github.ref_name }} GO_OS="linux" make build-dist-zip
- name: Copy Linux Sigstore bundles to release assets
run: |
cp ./dist/*.sigstore.json ./dist/assets/
- name: Create GitHub Release
id: create-github-release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
draft: false
prerelease: false
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}
files: |
dist/assets/**