-
Notifications
You must be signed in to change notification settings - Fork 23
345 lines (298 loc) · 14.5 KB
/
Copy pathsync-fleet-manager.yml
File metadata and controls
345 lines (298 loc) · 14.5 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
335
336
337
338
339
340
341
342
343
344
345
name: Sync Fleet Manager artifacts
on:
push:
branches:
- master
paths:
- otel-integration/k8s-helm/Chart.yaml
- otel-integration/CHANGELOG.md
- otel-ecs-ec2/Chart.yaml
- otel-ecs-ec2/CHANGELOG.md
- otel-linux-standalone/Chart.yaml
- otel-linux-standalone/CHANGELOG.md
- otel-macos-standalone/Chart.yaml
- otel-macos-standalone/CHANGELOG.md
- otel-windows-standalone/Chart.yaml
- otel-windows-standalone/CHANGELOG.md
workflow_dispatch:
inputs:
force:
description: "Run map sync even if no version bump is detected"
type: boolean
default: false
integration_chart_version:
description: "Override otel-integration chart version (e.g. 0.0.268)"
type: string
required: false
collector_chart_version:
description: "Override opentelemetry-collector chart version (e.g. 0.128.15)"
type: string
required: false
app_version:
description: "Override collector appVersion (skips helm lookup)"
type: string
required: false
create_pr:
description: "If true, create commit/push and open PR in Fleet Manager Helm Data"
type: boolean
default: false
permissions:
contents: read
jobs:
sync-fleet-manager:
runs-on: ubuntu-latest
env:
FLEET_MANAGER_HELM_DATA_DESTINATION_DIR: integration_releases
FLEET_MANAGER_HELM_DATA_DIR: ${{ github.workspace }}/fleet-manager-helm-data/integration_releases
steps:
- name: Checkout telemetry-shippers
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install yq and jq
run: sudo apt-get update && sudo apt-get install -y yq jq
- name: Detect otel-integration chart version bump
id: detect
run: |
set -euo pipefail
file="otel-integration/k8s-helm/Chart.yaml"
integration_chart_version="${INTEGRATION_CHART_VERSION_OVERRIDE:-}"
if [ -z "$integration_chart_version" ]; then
integration_chart_version="$(scripts/resolve-integration-chart-version.sh "$file")"
fi
old_integration_chart_version=""
base_sha="${GITHUB_EVENT_BEFORE:-}"
if [ -n "$base_sha" ] && [ "$base_sha" != "0000000000000000000000000000000000000000" ]; then
if git cat-file -e "$base_sha^{commit}" 2>/dev/null; then
old_file="$(mktemp)"
if git show "$base_sha:$file" > "$old_file" 2>/dev/null; then
old_integration_chart_version="$(yq -r '.version' "$old_file")"
fi
rm -f "$old_file"
fi
fi
if [ -z "$old_integration_chart_version" ]; then
old_file="$(mktemp)"
if git show "HEAD^1:$file" > "$old_file" 2>/dev/null; then
old_integration_chart_version="$(yq -r '.version' "$old_file")"
fi
rm -f "$old_file"
fi
collector_chart_version="${COLLECTOR_CHART_VERSION_OVERRIDE:-}"
if [ -z "$collector_chart_version" ]; then
collector_chart_version="$(scripts/resolve-collector-chart-version.sh "$file")"
fi
app_version="${APP_VERSION_OVERRIDE:-}"
echo "integration_chart_version=$integration_chart_version" >> "$GITHUB_OUTPUT"
echo "old_integration_chart_version=$old_integration_chart_version" >> "$GITHUB_OUTPUT"
echo "collector_chart_version=$collector_chart_version" >> "$GITHUB_OUTPUT"
echo "app_version=$app_version" >> "$GITHUB_OUTPUT"
bumped="false"
if [ "${FORCE_RUN:-false}" = "true" ]; then
bumped="true"
elif [ -n "$old_integration_chart_version" ] && [ "$integration_chart_version" != "$old_integration_chart_version" ]; then
bumped="true"
fi
echo "bumped=$bumped" >> "$GITHUB_OUTPUT"
env:
FORCE_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.force }}
INTEGRATION_CHART_VERSION_OVERRIDE: ${{ (github.event_name == 'workflow_dispatch' && inputs.integration_chart_version) || '' }}
COLLECTOR_CHART_VERSION_OVERRIDE: ${{ (github.event_name == 'workflow_dispatch' && inputs.collector_chart_version) || '' }}
APP_VERSION_OVERRIDE: ${{ (github.event_name == 'workflow_dispatch' && inputs.app_version) || '' }}
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Validate changelog format
run: |
go run ./cmd/helmlog validate \
otel-integration/CHANGELOG.md \
otel-ecs-ec2/CHANGELOG.md \
otel-linux-standalone/CHANGELOG.md \
otel-macos-standalone/CHANGELOG.md \
otel-windows-standalone/CHANGELOG.md
- name: Generate changelog artifacts (json)
run: |
set -euo pipefail
go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel_integration_changelog.json" otel-integration/CHANGELOG.md
go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel_ecs_ec2_changelog.json" otel-ecs-ec2/CHANGELOG.md
go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel_linux_standalone_changelog.json" otel-linux-standalone/CHANGELOG.md
go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel_macos_standalone_changelog.json" otel-macos-standalone/CHANGELOG.md
go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel_windows_standalone_changelog.json" otel-windows-standalone/CHANGELOG.md
go run ./cmd/helmlog chart-mapping --output "$RUNNER_TEMP/otel_ecs_ec2_chart_versions_map.json" otel-ecs-ec2/Chart.yaml
go run ./cmd/helmlog chart-mapping --output "$RUNNER_TEMP/otel_linux_standalone_chart_versions_map.json" otel-linux-standalone/Chart.yaml
go run ./cmd/helmlog chart-mapping --output "$RUNNER_TEMP/otel_windows_standalone_chart_versions_map.json" otel-windows-standalone/Chart.yaml
go run ./cmd/helmlog chart-mapping --output "$RUNNER_TEMP/otel_macos_standalone_chart_versions_map.json" otel-macos-standalone/Chart.yaml
- name: Set up Helm
if: steps.detect.outputs.bumped == 'true'
uses: azure/setup-helm@v4
- name: Checkout Fleet Manager Helm Data
uses: actions/checkout@v4
with:
repository: coralogix/fleet-manager-helm-data
ref: master
path: fleet-manager-helm-data
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- name: Prepare Fleet Manager Helm Data branch
run: |
set -euo pipefail
repo_dir="$GITHUB_WORKSPACE/fleet-manager-helm-data"
base_branch="master"
branch="bot/sync-fleet-manager-artifacts"
git -C "$repo_dir" config user.name "github-actions[bot]"
git -C "$repo_dir" config user.email "github-actions[bot]@users.noreply.github.com"
if git -C "$repo_dir" ls-remote --exit-code --heads origin "$branch" >/dev/null 2>&1; then
git -C "$repo_dir" fetch origin "$branch"
git -C "$repo_dir" checkout "$branch"
git -C "$repo_dir" rebase "origin/$base_branch"
else
git -C "$repo_dir" checkout -b "$branch"
fi
- name: Update Fleet Manager collector chart mapping
id: update_map
if: steps.detect.outputs.bumped == 'true'
env:
INTEGRATION_CHART_VERSION: ${{ steps.detect.outputs.integration_chart_version }}
COLLECTOR_CHART_VERSION: ${{ steps.detect.outputs.collector_chart_version }}
APP_VERSION_OVERRIDE: ${{ steps.detect.outputs.app_version }}
run: |
set -euo pipefail
output_env="$RUNNER_TEMP/fleet-manager-output.env"
args=(
--chart-file otel-integration/k8s-helm/Chart.yaml
--output-env "$output_env"
--integration-chart-version "$INTEGRATION_CHART_VERSION"
--chart-version "$COLLECTOR_CHART_VERSION"
)
if [ -n "${APP_VERSION_OVERRIDE:-}" ]; then
args+=(--app-version "$APP_VERSION_OVERRIDE")
fi
scripts/update-fleet-manager-collector-chart-map.sh "${args[@]}"
set -a
. "$output_env"
set +a
if [ "${MAPPING_UPDATED:-false}" = "true" ]; then
echo "updated=true" >> "$GITHUB_OUTPUT"
else
echo "updated=false" >> "$GITHUB_OUTPUT"
fi
- name: Copy artifacts to Fleet Manager Helm Data
id: update_helm_data
run: |
set -euo pipefail
destination_dir="${FLEET_MANAGER_HELM_DATA_DESTINATION_DIR#/}"
destination_dir="${destination_dir%/}"
if [ -z "$destination_dir" ]; then
echo "Fleet Manager Helm data destination directory cannot be empty." >&2
exit 1
fi
mappings=(
"$RUNNER_TEMP/otel_integration_changelog.json:$destination_dir/otel_integration_changelog.json"
"$RUNNER_TEMP/otel_ecs_ec2_changelog.json:$destination_dir/otel_ecs_ec2_changelog.json"
"$RUNNER_TEMP/otel_linux_standalone_changelog.json:$destination_dir/otel_linux_standalone_changelog.json"
"$RUNNER_TEMP/otel_macos_standalone_changelog.json:$destination_dir/otel_macos_standalone_changelog.json"
"$RUNNER_TEMP/otel_windows_standalone_changelog.json:$destination_dir/otel_windows_standalone_changelog.json"
"$RUNNER_TEMP/otel_ecs_ec2_chart_versions_map.json:$destination_dir/otel_ecs_ec2_chart_versions_map.json"
"$RUNNER_TEMP/otel_linux_standalone_chart_versions_map.json:$destination_dir/otel_linux_standalone_chart_versions_map.json"
"$RUNNER_TEMP/otel_windows_standalone_chart_versions_map.json:$destination_dir/otel_windows_standalone_chart_versions_map.json"
"$RUNNER_TEMP/otel_macos_standalone_chart_versions_map.json:$destination_dir/otel_macos_standalone_chart_versions_map.json"
)
changed_files=()
for mapping in "${mappings[@]}"; do
src="${mapping%%:*}"
dst_name="${mapping#*:}"
dst="$GITHUB_WORKSPACE/fleet-manager-helm-data/$dst_name"
if [ -f "$dst" ] && cmp -s "$src" "$dst"; then
continue
fi
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
done
mapfile -t changed_files < <(
git -C "$GITHUB_WORKSPACE/fleet-manager-helm-data" ls-files --modified --others --exclude-standard -- "$destination_dir"
)
if [ "${#changed_files[@]}" -eq 0 ]; then
echo "updated=false" >> "$GITHUB_OUTPUT"
echo "changed_files=" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "updated=true" >> "$GITHUB_OUTPUT"
printf 'changed_files=%s\n' "${changed_files[*]}" >> "$GITHUB_OUTPUT"
- name: Commit, push, and create/update Fleet Manager Helm Data PR
if: steps.update_helm_data.outputs.updated == 'true'
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
CREATE_PR: ${{ github.event_name != 'workflow_dispatch' || inputs.create_pr }}
FLEET_MANAGER_HELM_DATA_REPO: coralogix/fleet-manager-helm-data
FLEET_MANAGER_HELM_DATA_REF: master
INTEGRATION_CHART_VERSION: ${{ steps.detect.outputs.integration_chart_version }}
COLLECTOR_CHART_VERSION: ${{ steps.detect.outputs.collector_chart_version }}
run: |
set -euo pipefail
repo_dir="$GITHUB_WORKSPACE/fleet-manager-helm-data"
branch="bot/sync-fleet-manager-artifacts"
changed_files="${{ steps.update_helm_data.outputs.changed_files }}"
destination_dir="${FLEET_MANAGER_HELM_DATA_DESTINATION_DIR#/}"
destination_dir="${destination_dir%/}"
enable_auto_merge() {
local pr_number="$1"
local head_sha="$2"
echo "Enabling auto-merge with squash strategy for PR #$pr_number"
gh pr merge "$pr_number" \
-R "$FLEET_MANAGER_HELM_DATA_REPO" \
--auto \
--match-head-commit "$head_sha" \
--squash
}
read -r -a files <<< "$changed_files"
if [ "${#files[@]}" -eq 0 ]; then
echo "No files to stage."
exit 0
fi
git -C "$repo_dir" add "${files[@]}"
if git -C "$repo_dir" diff --cached --quiet; then
echo "No changes to commit."
exit 0
fi
if [ "${CREATE_PR:-false}" != "true" ]; then
echo "CREATE_PR is false; skipping commit/push/PR. (Dry run complete.)"
echo ""
echo "Changed files in Fleet Manager Helm Data:"
git -C "$repo_dir" --no-pager diff --cached --stat
echo ""
echo "Full staged diff:"
git -C "$repo_dir" --no-pager diff --cached
exit 0
fi
if [ -z "${GH_TOKEN:-}" ]; then
echo "Missing GH_TOKEN secret"
exit 1
fi
git -C "$repo_dir" commit -m "Sync Fleet Manager artifacts from telemetry-shippers"
git -C "$repo_dir" push --force-with-lease -u origin "$branch"
pushed_head_sha="$(git -C "$repo_dir" rev-parse HEAD)"
existing_pr="$(gh pr list -R "$FLEET_MANAGER_HELM_DATA_REPO" --head "$branch" --state open --json number --jq '.[0].number')"
if [ -n "$existing_pr" ]; then
echo "PR already exists: #$existing_pr"
enable_auto_merge "$existing_pr" "$pushed_head_sha"
exit 0
fi
pr_body="$RUNNER_TEMP/fleet-manager-helm-data-sync-pr-body.md"
{
echo "Automated synchronization from telemetry-shippers."
echo ""
echo "## Helm data artifacts"
printf -- "- Destination directory: \`%s\`\n" "$destination_dir"
printf -- "- otel-integration chart: \`%s\`\n" "$INTEGRATION_CHART_VERSION"
printf -- "- opentelemetry-collector chart: \`%s\`\n" "$COLLECTOR_CHART_VERSION"
echo ""
echo "Dumb ticket reference to pass build: CX-39963."
} > "$pr_body"
created_pr_url="$(gh pr create \
-R "$FLEET_MANAGER_HELM_DATA_REPO" \
--base "$FLEET_MANAGER_HELM_DATA_REF" \
--head "$branch" \
--title "Sync Fleet Manager Helm data from telemetry-shippers" \
--body-file "$pr_body")"
enable_auto_merge "$created_pr_url" "$pushed_head_sha"