Skip to content

Commit c14ab0c

Browse files
authored
Handle sync cloudbeat with snapshots not published (#7179)
### Summary of your changes Makes the hermit.hcl version sync self-healing and safe to automate. Two changes: - scripts/sync_internal_cloudbeat_version.sh, before opening a sync PR, the script now checks that the target ${CLOUDBEAT_VERSION}-SNAPSHOT is actually published on the Elastic artifacts API (is_snapshot_published). If it isn't available yet, it reverts the local edit and exits cleanly, so we never pin a version whose agent artifacts don't exist. If the API can't be reached, it skips to stay safe. - .github/workflows/sync-internal-cloudbeat-version.yml, added a daily schedule trigger (the previous push trigger was commented out, so the sync only ever ran manually and hermit.hcl drifted out of sync with version.go). Together this closes the gap that caused [security-team#17923](elastic/security-team#17923): hermit.hcl was stuck at 9.4.0 while version.go had moved on, so the test-runner requested a 9.4.0-SNAPSHOT agent that no longer exists. With this, the sync runs daily and opens a hermit.hcl bump PR automatically as soon as the new snapshot is published, respecting the "artifacts must exist first" constraint that previously required a manual run.
1 parent 735624b commit c14ab0c

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

.github/workflows/sync-internal-cloudbeat-version.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: Sync Cloudbeat Versions on release
22
# Makes sure all cloudbeat versions are updated with release branches
33
on:
4-
# push:
5-
# branches:
6-
# # matches branches pushed by elasticmachine, e.g. "update-version-next-8.15.3"
7-
# - 'update-version-next-*'
4+
# Runs daily: the script only opens a hermit.hcl sync PR once the target
5+
# ${version}-SNAPSHOT is actually published, so it self-heals drift without
6+
# ever pinning an unavailable build.
7+
schedule:
8+
- cron: '0 6 * * *'
89
workflow_dispatch: {}
910

1011
jobs:

scripts/sync_internal_cloudbeat_version.sh

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -xeuo pipefail
33

44
VERSION_FILE="version/version.go"
55
HERMIT_FILE="bin/hermit.hcl"
6+
ARTIFACTS_API_URL="https://artifacts-api.elastic.co/v1/versions"
67

78
git config --global user.email "cloudsecmachine@users.noreply.github.com"
89
git config --global user.name "Cloud Security Machine"
@@ -18,12 +19,62 @@ set_hermit_cloudbeat_version() {
1819
sed -E -i "s/CLOUDBEAT_VERSION\": \".*\"/CLOUDBEAT_VERSION\": \"$CLOUDBEAT_VERSION\"/g" $HERMIT_FILE
1920
}
2021

22+
sync_pr_already_open() {
23+
# A previous run may have opened a sync PR for this version that hasn't merged
24+
# yet; main still shows the drift, so avoid opening a duplicate every run.
25+
local existing
26+
existing=$(gh pr list \
27+
--search "Sync CLOUDBEAT_VERSION in hermit.hcl to $CLOUDBEAT_VERSION in:title" \
28+
--state open --json number --jq '.[0].number' 2>/dev/null || echo "")
29+
[[ -n "$existing" ]]
30+
}
31+
32+
is_snapshot_published() {
33+
# ELK_VERSION resolves to "${CLOUDBEAT_VERSION}-SNAPSHOT"; only bump once that
34+
# snapshot actually exists on the Elastic artifacts API, otherwise the test-runner
35+
# would pin a version whose agent artifacts aren't published yet (see issue #17923).
36+
local target="${CLOUDBEAT_VERSION}-SNAPSHOT"
37+
echo "Checking whether $target is published on the Elastic artifacts API"
38+
local versions
39+
if ! versions=$(curl -fsS "$ARTIFACTS_API_URL" | jq -r '.versions[]'); then
40+
echo "Could not query $ARTIFACTS_API_URL; skipping this run to be safe"
41+
return 1
42+
fi
43+
if grep -qxF "$target" <<<"$versions"; then
44+
echo "$target is available"
45+
return 0
46+
fi
47+
echo "$target is not published yet"
48+
return 1
49+
}
50+
2151
handle_version_changes() {
2252
if git diff --quiet --exit-code $HERMIT_FILE; then
2353
echo "No changes to $HERMIT_FILE; I'm done"
2454
return
2555
fi
2656

57+
if git diff --quiet --exit-code $HERMIT_FILE; then
58+
echo "No changes to $HERMIT_FILE; I'm done"
59+
return
60+
fi
61+
62+
# A sync PR for this version may already be open from a previous run
63+
# (main stays on the old version until it merges) — don't open a duplicate.
64+
if sync_pr_already_open; then
65+
echo "An open sync PR for $CLOUDBEAT_VERSION already exists; skipping."
66+
git checkout -- "$HERMIT_FILE"
67+
return
68+
fi
69+
70+
# A bump is pending — only open a PR once the target snapshot is actually
71+
# published, otherwise revert and let the next scheduled run try again.
72+
if ! is_snapshot_published; then
73+
echo "Skipping bump; ${CLOUDBEAT_VERSION}-SNAPSHOT not published yet. Will retry on the next run."
74+
git checkout -- "$HERMIT_FILE"
75+
return
76+
fi
77+
2778
# Get current branch
2879
current_branch=$(git branch --show-current)
2980
echo "Current branch is: $current_branch"
@@ -46,7 +97,6 @@ handle_version_changes() {
4697
--base "$current_branch" \
4798
--head "$branch_name"
4899
}
49-
50100
find_current_cloudbeat_version
51101
set_hermit_cloudbeat_version
52102
handle_version_changes

0 commit comments

Comments
 (0)