forked from SumoLogic/sumologic-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
179 lines (157 loc) · 6.28 KB
/
workflow-build-otelcol-config.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
name: Build Otelcol Config Tool
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
secrets:
apple_developer_certificate_p12_base64:
required: false
apple_developer_certificate_password:
required: false
app_store_connect_password:
required: false
defaults:
run:
shell: bash
env:
GO_VERSION: "1.21.11"
jobs:
build:
name: Build
runs-on: ${{ inputs.runs-on }}
env:
FIPS_SUFFIX: ${{ inputs.fips && '-fips' || '' }}
steps:
- uses: actions/checkout@v4
- name: Fetch current branch
run: ./ci/fetch_current_branch.sh
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- 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-config${FIPS_SUFFIX}-${{inputs.arch_os}}-${{ hashFiles('pkg/tools/otelcol-config/go.sum') }}" >> $GITHUB_OUTPUT
echo "restore-keys=go-build-${{ env.GO_VERSION }}-otelcol-config${FIPS_SUFFIX}-${{inputs.arch_os}}-" >> $GITHUB_OUTPUT
echo "toolchain-cache-key=toolchain-${{inputs.arch_os}}-${{ hashFiles('pkg/tools/otelcol-config/build-fips/config.mak', 'pkg/tools/otelcol-config/build-fips/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: Build
if: '! inputs.fips'
run: make otelcol-config-${{inputs.arch_os}}
working-directory: ./pkg/tools/otelcol-config
- 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: ./toolchains
- 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-config-${{inputs.arch_os}} \
FIPS_SUFFIX="-fips" \
CGO_ENABLED="1" \
CC="$CC" \
EXTRA_LDFLAGS="-linkmode external -extldflags '-static'"
working-directory: ./pkg/tools/otelcol-config
- 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-config-${{inputs.arch_os}} \
FIPS_SUFFIX="-fips" \
CGO_ENABLED="1" \
CC="$CC" \
EXTRA_LDFLAGS="-linkmode external -extldflags '-static'"
working-directory: ./pkg/tools/otelcol-config
- name: Set binary name
id: set-binary-name
run: echo "binary_name=otelcol-config${FIPS_SUFFIX}-${{inputs.arch_os}}" >> $GITHUB_OUTPUT
- name: Show BoringSSL symbols
if: inputs.fips && contains(inputs.arch_os, 'linux')
working-directory: ./pkg/tools/otelcol-config
run: |
go tool nm ${{ steps.set-binary-name.outputs.binary_name }} | \
grep "_Cfunc__goboringcrypto_"
- uses: apple-actions/import-codesign-certs@v3
if: ${{ runner.os == 'macOS' }}
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:
AC_PASSWORD: ${{ secrets.app_store_connect_password }}
working-directory: ./pkg/tools/otelcol-config
run: make ${{ inputs.arch_os }}-sign
- name: Store binary as action artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-binary-name.outputs.binary_name }}
path: ./pkg/tools/otelcol-config/${{ steps.set-binary-name.outputs.binary_name }}
if-no-files-found: error
- name: Store macOS .dmg as action artifact
uses: actions/upload-artifact@v4
if: runner.os == 'macOS'
with:
name: ${{ steps.set-binary-name.outputs.binary_name }}.dmg
path: ./pkg/tools/otelcol-config/${{ 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 }}