-
Notifications
You must be signed in to change notification settings - Fork 41
277 lines (242 loc) · 10.4 KB
/
workflow-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
name: Build Otelcol
on:
workflow_call:
inputs:
arch_os:
description: Architecture and OS in the form "{arch}_{os}". See GOARCH and GOOS for accepted values.
default: linux_amd64
type: string
sumo_component_gomod_version:
description: Package version for components hosted in this repo. Normally, this is the v0.0.0-00010101000000-000000000000 placeholder.
type: string
required: false
fips:
description: Build binary with FIPS support
default: false
type: boolean
runs-on:
default: ubuntu-20.04
type: string
save-cache:
description: Save the module and build caches.
default: false
type: boolean
version:
description: Version to use when building the binary
required: true
type: string
secrets:
apple_developer_certificate_p12_base64:
required: false
apple_developer_certificate_password:
required: false
app_store_connect_password:
required: false
microsoft_certificate:
required: false
microsoft_certificate_password:
required: false
microsoft_certificate_hash:
required: false
microsoft_certificate_name:
required: false
microsoft_description:
required: false
defaults:
run:
shell: bash
env:
GO_VERSION: "1.22.8"
VERSION: ${{ inputs.version }}
jobs:
build:
name: Build
runs-on: ${{ inputs.runs-on }}
env:
OTELCOL_BINARY_EXTENSION: ${{ contains(inputs.arch_os, 'windows') && '.exe' || '' }}
OTELCOL_FIPS_SUFFIX: ${{ inputs.fips && '-fips' || '' }}
steps:
- uses: actions/checkout@v4
- name: Determine if MacOS package should be signed
if: runner.os == 'macOS'
env:
APPLE_DEVELOPER_CERTIFICATE: ${{ secrets.apple_developer_certificate_p12_base64 }}
run: |
if [ -n "${APPLE_DEVELOPER_CERTIFICATE}" ]; then
echo "MACOS_SIGNING_ENABLED=true" >> $GITHUB_ENV
fi
- name: Determine if Windows package should be signed
if: runner.os == 'Windows'
env:
WINDOWS_CERTIFICATE: "${{ secrets.microsoft_certificate }}"
run: |
if [ -n "${WINDOWS_CERTIFICATE}" ]; then
echo "WINDOWS_SIGNING_ENABLED=true" >> $GITHUB_ENV
fi
- name: Setup go
if: (! (contains(inputs.arch_os, 'windows') && inputs.fips))
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: Setup go (Microsoft fork) and enable FIPS on Windows
if: contains(inputs.arch_os, 'windows') && inputs.fips
run: |
curl -Lo go.zip https://aka.ms/golang/release/latest/go${{ env.GO_VERSION }}.windows-amd64.zip &&
powershell -command "Expand-Archive go.zip D:\\a\\_work\\1\\s" &&
echo "/d/a/_work/1/s/go/bin" >> $GITHUB_PATH &&
powershell -command "Set-ItemProperty -Path HKLM:\System\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy -Name Enabled -Value \$true"
- name: Set Sumo component version in go.mod
if: inputs.sumo_component_gomod_version != ''
run: make prepare-tag TAG=${{ inputs.sumo_component_gomod_version }}
- name: Get Go env values
run: |
echo "GOMODCACHE=$(go env GOMODCACHE)" >> "$GITHUB_ENV"
echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_ENV"
echo "GOARCH=$(go env GOARCH)" >> "$GITHUB_ENV"
echo "GOOS=$(go env GOOS)" >> "$GITHUB_ENV"
echo "ARCH_OS=$(go env GOOS)_$(go env GOARCH)" >> $GITHUB_ENV
- name: Get cache key
id: get-cache-key
run: |
echo "cache-key=go-build-${{ env.GO_VERSION }}${OTELCOL_FIPS_SUFFIX}-${{inputs.arch_os}}-${{ hashFiles('pkg/**/go.sum', 'otelcolbuilder/.otelcol-builder.yaml') }}" >> $GITHUB_OUTPUT
echo "restore-keys=go-build-${{ env.GO_VERSION }}${OTELCOL_FIPS_SUFFIX}-${{inputs.arch_os}}-" >> $GITHUB_OUTPUT
echo "toolchain-cache-key=toolchain-${{inputs.arch_os}}-${{ hashFiles('toolchains/config.mak', 'toolchains/Makefile') }}" >> $GITHUB_OUTPUT
- uses: actions/cache/restore@v4
with:
path: |
${{ env.GOMODCACHE }}/cache
${{ env.GOCACHE }}
key: ${{ steps.get-cache-key.outputs.cache-key }}
restore-keys: |
${{ steps.get-cache-key.outputs.restore-keys }}
- name: Install yq (Windows)
if: contains(inputs.arch_os, 'windows')
run: choco install yq
- name: Set default BUILDER_BIN_PATH
run: echo "BUILDER_BIN_PATH=${HOME}/bin" >> $GITHUB_ENV
- name: Add opentelemetry-collector-builder installation dir to PATH
run: echo "$BUILDER_BIN_PATH" >> $GITHUB_PATH
- name: Install opentelemetry-collector-builder
run: make install-builder
working-directory: ./otelcolbuilder
- name: Build
if: "! inputs.fips"
run: make otelcol-sumo-${{inputs.arch_os}}
working-directory: ./otelcolbuilder
- uses: actions/cache/restore@v4
id: restore-toolchain-cache
if: inputs.fips && contains(inputs.arch_os, 'linux')
with:
path: |
/opt/toolchain
key: ${{ steps.get-cache-key.outputs.toolchain-cache-key }}
- name: Rebuild Toolchains
id: rebuild-toolchain
if: ${{ steps.restore-toolchain-cache.outcome == 'success' && steps.restore-toolchain-cache.outputs.cache-hit != 'true' }}
run: make toolchain-${{ inputs.arch_os }} OUTPUT=/opt/toolchain -j3
working-directory: ./otelcolbuilder
- name: Build (FIPS)
if: inputs.fips && contains(inputs.arch_os, 'linux')
run: |
CC=$(find /opt/toolchain/bin -type f -name "*-linux-musl-gcc")
test "$CC"
echo "Using toolchain: $CC"
make otelcol-sumo-${{inputs.arch_os}} \
FIPS_SUFFIX="-fips" \
CGO_ENABLED="1" \
CC="$CC" \
EXTRA_LDFLAGS="-linkmode external -extldflags '-static'"
working-directory: ./otelcolbuilder
- name: Build (FIPS)
if: inputs.fips && ! contains(inputs.arch_os, 'linux')
run: make otelcol-sumo-${{inputs.arch_os}} FIPS_SUFFIX="-fips" CGO_ENABLED=1
working-directory: ./otelcolbuilder
- name: Set binary name
id: set-binary-name
run: echo "binary_name=otelcol-sumo${OTELCOL_FIPS_SUFFIX}-${{inputs.arch_os}}${OTELCOL_BINARY_EXTENSION}" >> $GITHUB_OUTPUT
- name: Show file info
working-directory: ./otelcolbuilder/cmd
run: |
file ${{ steps.set-binary-name.outputs.binary_name }}
- name: Show ldd info
if: contains(inputs.arch_os, 'linux')
working-directory: ./otelcolbuilder/cmd
run: |
ldd ${{ steps.set-binary-name.outputs.binary_name }} || true
- name: Show BoringSSL symbols
if: inputs.fips && contains(inputs.arch_os, 'linux')
working-directory: ./otelcolbuilder/cmd
run: |
go tool nm ${{ steps.set-binary-name.outputs.binary_name }} | \
grep "_Cfunc__goboringcrypto_"
- name: Show Microsoft Cryptography Next-Generation symbols
if: inputs.fips && contains(inputs.arch_os, 'windows')
working-directory: ./otelcolbuilder/cmd
run: |
go tool nm ${{ steps.set-binary-name.outputs.binary_name }} | \
grep "vendor/github.com/microsoft/go-crypto-winnative/internal/bcrypt.GetFipsAlgorithmMode"
- name: Verify binary version
if: inputs.arch_os == 'linux_amd64' || inputs.arch_os == 'darwin_amd64'
run: |
binary=${{ steps.set-binary-name.outputs.binary_name }}
binary_path=otelcolbuilder/cmd/${binary}
./ci/get_version_from_binary.sh core "${binary_path}"
./ci/get_version_from_binary.sh sumo "${binary_path}"
- uses: apple-actions/import-codesign-certs@v3
if: ${{ runner.os == 'macOS' && env.MACOS_SIGNING_ENABLED == 'true' }}
with:
p12-file-base64: ${{ secrets.apple_developer_certificate_p12_base64 }}
p12-password: ${{ secrets.apple_developer_certificate_password }}
- name: Sign the mac binaries
if: ${{ runner.os == 'macOS' && env.MACOS_SIGNING_ENABLED == 'true' }}
env:
AC_PASSWORD: ${{ secrets.app_store_connect_password }}
working-directory: ./otelcolbuilder/
run: |
for i in $(seq 1 5); do
make ${{ inputs.arch_os }}-sign && break || sleep 5
done
- name: Sign Windows binary
if: runner.os == 'Windows' && env.WINDOWS_SIGNING_ENABLED == 'true'
uses: skymatic/code-sign-action@v3
with:
certificate: "${{ secrets.microsoft_certificate }}"
password: "${{ secrets.microsoft_certificate_password }}"
certificatesha1: "${{ secrets.microsoft_certificate_hash }}"
certificatename: "${{ secrets.microsoft_certificate_name }}"
description: "${{ secrets.microsoft_description }}"
folder: ./otelcolbuilder/cmd
- name: Test binary
if: inputs.arch_os == env.ARCH_OS
working-directory: ./otelcolbuilder/cmd
run: |
./${{ steps.set-binary-name.outputs.binary_name }} help
./${{ steps.set-binary-name.outputs.binary_name }} components
./${{ steps.set-binary-name.outputs.binary_name }} completion bash
- name: Store binary as action artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-binary-name.outputs.binary_name }}
path: ./otelcolbuilder/cmd/${{ steps.set-binary-name.outputs.binary_name }}
if-no-files-found: error
- name: Store Mac .dmg as action artifact
uses: actions/upload-artifact@v4
if: runner.os == 'macOS' && env.MACOS_SIGNING_ENABLED == 'true'
with:
name: ${{ steps.set-binary-name.outputs.binary_name }}.dmg
path: ./otelcolbuilder/cmd/${{ steps.set-binary-name.outputs.binary_name }}.dmg
if-no-files-found: error
- uses: actions/cache/save@v4
if: ${{ steps.rebuild-toolchain.outcome == 'success' }}
with:
path: |
/opt/toolchain
key: ${{ steps.get-cache-key.outputs.toolchain-cache-key }}
- uses: actions/cache/save@v4
if: inputs.save-cache
with:
path: |
${{ env.GOMODCACHE }}/cache
${{ env.GOCACHE }}
key: ${{ steps.get-cache-key.outputs.cache-key }}