-
-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (189 loc) · 7.58 KB
/
build-binaries.yml
File metadata and controls
214 lines (189 loc) · 7.58 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
name: Build Binaries
on:
workflow_call:
inputs:
version:
description: "Version string to embed"
required: true
type: string
commit_sha:
description: "Commit SHA to embed"
required: true
type: string
build_date:
description: "Build date to embed"
required: true
type: string
secrets:
DEVELOPER_ID_P12_BASE64:
description: "Base64-encoded Developer ID certificate"
required: true
DEVELOPER_ID_PASSWORD:
description: "Password for the Developer ID certificate"
required: true
APPLE_NOTARIZATION_APPLE_ID_PASSWORD:
description: "App-specific password for Apple ID notarization"
required: true
jobs:
build:
name: Build ${{ matrix.platform }}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
include:
- platform: linux-amd64
goos: linux
goarch: amd64
- platform: linux-arm64
goos: linux
goarch: arm64
- platform: darwin-amd64
goos: darwin
goarch: amd64
- platform: darwin-arm64
goos: darwin
goarch: arm64
- platform: windows-amd64
goos: windows
goarch: amd64
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
check-latest: false
- name: Build CLI
run: |
BINARY="github-actions-utils-cli-${{ matrix.platform }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
BINARY="${BINARY}.exe"
fi
# Build static binary (no CGO, static linking)
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
-ldflags "-s -w -extldflags '-static' \
-X github.com/techprimate/github-actions-utils-cli/internal/cli/cmd.version=${{ inputs.version }} \
-X github.com/techprimate/github-actions-utils-cli/internal/cli/cmd.commit=${{ inputs.commit_sha }} \
-X github.com/techprimate/github-actions-utils-cli/internal/cli/cmd.date=${{ inputs.build_date }}" \
-o "dist/${BINARY}" \
./cmd/cli
- name: Upload artifact
uses: actions/upload-artifact@v5
with:
name: cli-${{ matrix.platform }}
path: dist/github-actions-utils-cli-*
retention-days: 1
sign-and-notarize-macos:
name: Sign and Notarize macOS Binaries
needs: build
runs-on: macos-latest
timeout-minutes: 20
steps:
- name: Download Darwin CLI artifacts
uses: actions/download-artifact@v6
with:
path: dist
pattern: cli-darwin-*
merge-multiple: true
- name: Setup signing certificate
env:
CERTIFICATE_BASE64: ${{ secrets.DEVELOPER_ID_P12_BASE64 }}
CERTIFICATE_PASSWORD: ${{ secrets.DEVELOPER_ID_PASSWORD }}
run: |
# Create temporary keychain
KEYCHAIN_NAME="github-actions-utils-signing.keychain-db"
KEYCHAIN_PASSWORD=$(openssl rand -hex 32)
# Delete any existing keychain with the same name
security delete-keychain "$KEYCHAIN_NAME" 2>/dev/null || true
# Create and setup keychain
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_NAME"
security set-keychain-settings -lut 21600 "$KEYCHAIN_NAME"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_NAME"
# Import certificate
CERTIFICATE_PATH=$RUNNER_TEMP/certificate.p12
echo "$CERTIFICATE_BASE64" | base64 --decode -o "$CERTIFICATE_PATH"
security import "$CERTIFICATE_PATH" -k "$KEYCHAIN_NAME" -P "$CERTIFICATE_PASSWORD" -T /usr/bin/codesign -T /usr/bin/security
# Make keychain available for codesign
security list-keychains -d user -s "$KEYCHAIN_NAME" $(security list-keychains -d user | sed s/\"//g)
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_NAME"
security default-keychain -s "$KEYCHAIN_NAME"
# Clean up certificate file
rm -f "$CERTIFICATE_PATH"
# Store keychain info for cleanup
echo "KEYCHAIN_NAME=$KEYCHAIN_NAME" >> $GITHUB_ENV
echo "KEYCHAIN_PASSWORD=$KEYCHAIN_PASSWORD" >> $GITHUB_ENV
- name: Sign and notarize CLI darwin-amd64
env:
APPLE_ID: ${{ vars.APPLE_NOTARIZATION_APPLE_ID_USERNAME }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_APPLE_ID_PASSWORD }}
APPLE_TEAM_ID: ${{ vars.APPLE_NOTARIZATION_TEAM_ID }}
SIGNING_IDENTITY: ${{ vars.APPLE_NOTARIZATION_SIGNING_IDENTITY }}
run: |
cd dist
# Sign the binary
codesign --sign "$SIGNING_IDENTITY" \
--options runtime \
--timestamp \
--force \
--verbose \
github-actions-utils-cli-darwin-amd64
# Verify signature
codesign --verify --verbose github-actions-utils-cli-darwin-amd64
# Create zip and submit for notarization
zip -q github-actions-utils-cli-darwin-amd64.zip github-actions-utils-cli-darwin-amd64
xcrun notarytool submit github-actions-utils-cli-darwin-amd64.zip \
--apple-id "$APPLE_ID" \
--password "$APPLE_ID_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait
rm github-actions-utils-cli-darwin-amd64.zip
- name: Sign and notarize CLI darwin-arm64
env:
APPLE_ID: ${{ vars.APPLE_NOTARIZATION_APPLE_ID_USERNAME }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_NOTARIZATION_APPLE_ID_PASSWORD }}
APPLE_TEAM_ID: ${{ vars.APPLE_NOTARIZATION_TEAM_ID }}
SIGNING_IDENTITY: ${{ vars.APPLE_NOTARIZATION_SIGNING_IDENTITY }}
run: |
cd dist
# Sign the binary
codesign --sign "$SIGNING_IDENTITY" \
--options runtime \
--timestamp \
--force \
--verbose \
github-actions-utils-cli-darwin-arm64
# Verify signature
codesign --verify --verbose github-actions-utils-cli-darwin-arm64
# Create zip and submit for notarization
zip -q github-actions-utils-cli-darwin-arm64.zip github-actions-utils-cli-darwin-arm64
xcrun notarytool submit github-actions-utils-cli-darwin-arm64.zip \
--apple-id "$APPLE_ID" \
--password "$APPLE_ID_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait
rm github-actions-utils-cli-darwin-arm64.zip
- name: Cleanup keychain
if: always()
run: |
if [ -n "$KEYCHAIN_NAME" ]; then
security delete-keychain "$KEYCHAIN_NAME" || true
fi
- name: Upload signed CLI darwin-amd64
uses: actions/upload-artifact@v5
with:
name: cli-darwin-amd64
path: dist/github-actions-utils-cli-darwin-amd64
retention-days: 1
overwrite: true
- name: Upload signed CLI darwin-arm64
uses: actions/upload-artifact@v5
with:
name: cli-darwin-arm64
path: dist/github-actions-utils-cli-darwin-arm64
retention-days: 1
overwrite: true