Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor improvements to version bump workflow #1964

Merged
merged 5 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 58 additions & 43 deletions scripts/bump_cloudbeat.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#!/bin/bash
set -euo pipefail

export NEXT_CLOUDBEAT_BRANCH="bump-to-$NEXT_CLOUDBEAT_VERSION"
# versions
CURRENT_MINOR_VERSION=$(echo "$CURRENT_CLOUDBEAT_VERSION" | cut -d '.' -f1,2)
export CURRENT_MINOR_VERSION

# branches
export NEXT_CLOUDBEAT_BRANCH="bump-to-$NEXT_CLOUDBEAT_VERSION"
export NEXT_CLOUDBEAT_HERMIT_BRANCH="bump-hermit-to-$CURRENT_CLOUDBEAT_VERSION"
export RELEASE_CLOUDBEAT_BRANCH="release-$CURRENT_MINOR_VERSION"

# paths
export ARM_SINGLE_ACCOUNT_FILE="deploy/azure/ARM-for-single-account.json"
export ARM_SINGLE_ACCOUNT_FILE_DEV="deploy/azure/ARM-for-single-account.dev.json"
export ARM_ORGANIZATION_ACCOUNT_FILE="deploy/azure/ARM-for-organization-account.json"
export ARM_ORGANIZATION_ACCOUNT_FILE_DEV="deploy/azure/ARM-for-organization-account.dev.json"
export HERMIT_FILE="bin/hermit.hcl"

echo "NEXT_CLOUDBEAT_VERSION: $NEXT_CLOUDBEAT_VERSION"
echo "CURRENT_CLOUDBEAT_VERSION: $CURRENT_CLOUDBEAT_VERSION"
echo "CURRENT_MINOR_VERSION: $CURRENT_MINOR_VERSION"
Expand All @@ -27,94 +38,83 @@ update_version_mergify() {
- "backport"
title: "[{{ destination_branch }}](backport #{{ number }}) {{ title }}"
EOF
git add .mergify.yml
git commit -m "Update .mergify.yml"

gh label create "backport-v$CURRENT_CLOUDBEAT_VERSION"
}

update_version_arm_template_default_value() {
echo "• Update ARM templates with new version"
local single_account_file="deploy/azure/ARM-for-single-account.json"
local organization_account_file="deploy/azure/ARM-for-organization-account.json"

echo "• Replace defaultValue for ElasticAgentVersion in ARM templates"
jq --indent 4 ".parameters.ElasticAgentVersion.defaultValue = \"$NEXT_CLOUDBEAT_VERSION\"" $single_account_file >tmp.json && mv tmp.json $single_account_file
jq --indent 4 ".parameters.ElasticAgentVersion.defaultValue = \"$NEXT_CLOUDBEAT_VERSION\"" $organization_account_file >tmp.json && mv tmp.json $organization_account_file
jq --indent 4 ".parameters.ElasticAgentVersion.defaultValue = \"$NEXT_CLOUDBEAT_VERSION\"" $ARM_SINGLE_ACCOUNT_FILE >tmp.json && mv tmp.json $ARM_SINGLE_ACCOUNT_FILE
jq --indent 4 ".parameters.ElasticAgentVersion.defaultValue = \"$NEXT_CLOUDBEAT_VERSION\"" $ARM_ORGANIZATION_ACCOUNT_FILE >tmp.json && mv tmp.json $ARM_ORGANIZATION_ACCOUNT_FILE

echo "• Generate dev ARM templates"
./deploy/azure/generate_dev_template.py --template-type single-account
./deploy/azure/generate_dev_template.py --template-type organization-account

git add $ARM_SINGLE_ACCOUNT_FILE $ARM_ORGANIZATION_ACCOUNT_FILE $ARM_SINGLE_ACCOUNT_FILE_DEV $ARM_ORGANIZATION_ACCOUNT_FILE_DEV
git commit -m "Update ARM templates"
}

update_version_arm_template_file_uris() {
echo "• Update ARM templates with new version"
local single_account_file="deploy/azure/ARM-for-single-account.json"
local organization_account_file="deploy/azure/ARM-for-organization-account.json"

echo "• Replace fileUris git branch in ARM templates"
sed -i'' -E "s/cloudbeat\/main/cloudbeat\/$CURRENT_MINOR_VERSION/g" $single_account_file
sed -i'' -E "s/cloudbeat\/main/cloudbeat\/$CURRENT_MINOR_VERSION/g" $organization_account_file

echo "• Generate dev ARM templates"
./deploy/azure/generate_dev_template.py --template-type single-account
./deploy/azure/generate_dev_template.py --template-type organization-account
sed -i'' -E "s/cloudbeat\/main/cloudbeat\/$CURRENT_MINOR_VERSION/g" $ARM_SINGLE_ACCOUNT_FILE
sed -i'' -E "s/cloudbeat\/main/cloudbeat\/$CURRENT_MINOR_VERSION/g" $ARM_ORGANIZATION_ACCOUNT_FILE
git add $ARM_SINGLE_ACCOUNT_FILE $ARM_ORGANIZATION_ACCOUNT_FILE
git commit -m "Update ARM templates"
}

update_version_beat() {
echo "• Update version/version.go with new version"
sed -i'' -E "s/const defaultBeatVersion = .*/const defaultBeatVersion = \"$NEXT_CLOUDBEAT_VERSION\"/g" version/version.go
git add version/version.go
git commit -m "Update version.go"
}

create_cloudbeat_versions_pr_for_main() {
echo "• Create PR for cloudbeat next version"
git add .
git commit -m "Bump cloudbeat to $NEXT_CLOUDBEAT_VERSION"
git push origin "$NEXT_CLOUDBEAT_BRANCH"

cat <<EOF >cloudbeat_pr_body
Bump cloudbeat version - \`$NEXT_CLOUDBEAT_VERSION\`

> [!NOTE]
> This is an automated PR
EOF

gh pr create --title "Bump cloudbeat version" \
pr_url="$(gh pr create --title "Bump cloudbeat version" \
--body-file cloudbeat_pr_body \
--base "main" \
--head "$NEXT_CLOUDBEAT_BRANCH" \
--label "backport-skip"
rm -rf cloudbeat_pr_body
--label "backport-skip")"
# shellcheck disable=SC2086
echo "[Cloudbeat Version PR to main]($pr_url)" >>$GITHUB_STEP_SUMMARY
}

create_cloudbeat_versions_pr_for_release() {
echo "• Create PR for cloudbeat release version"
git add .
git commit -m "Release cloudbeat $CURRENT_CLOUDBEAT_VERSION"
git push origin "$RELEASE_CLOUDBEAT_BRANCH"

cat <<EOF >cloudbeat_pr_body_release
Release cloudbeat version - \`$CURRENT_CLOUDBEAT_VERSION\`

> [!NOTE]
> This is an automated PR
EOF

gh pr create --title "Release cloudbeat version" \
pr_url="$(gh pr create --title "Release cloudbeat version" \
--body-file cloudbeat_pr_body_release \
--base "$CURRENT_MINOR_VERSION" \
--head "$RELEASE_CLOUDBEAT_BRANCH" \
--label "backport-skip"

rm -rf cloudbeat_pr_body_release
--label "backport-skip")"
# shellcheck disable=SC2086
echo "[Cloudbeat Version PR to release branch]($pr_url)" >>$GITHUB_STEP_SUMMARY
}

# We need to bump hermit seperately because we need to wait for the snapshot build to be available
bump_hermit() {
echo "• Bump hermit cloudbeat version"
local BRANCH="bump-hermit-to-$CURRENT_CLOUDBEAT_VERSION"
git checkout -b "$BRANCH" origin/main

sed -i'' -E "s/\"CLOUDBEAT_VERSION\": .*/\"CLOUDBEAT_VERSION\": \"$CURRENT_CLOUDBEAT_VERSION\",/g" bin/hermit.hcl
git add bin/hermit.hcl
sed -i'' -E "s/\"CLOUDBEAT_VERSION\": .*/\"CLOUDBEAT_VERSION\": \"$CURRENT_CLOUDBEAT_VERSION\",/g" $HERMIT_FILE
git add $HERMIT_FILE
git commit -m "Bump cloudbeat to $CURRENT_CLOUDBEAT_VERSION"
git push origin "$BRANCH"
git push origin "$NEXT_CLOUDBEAT_HERMIT_BRANCH"

cat <<EOF >hermit_pr_body
Bump cloudbeat version - \`$CURRENT_CLOUDBEAT_VERSION\`
Expand All @@ -127,13 +127,13 @@ Bump cloudbeat version - \`$CURRENT_CLOUDBEAT_VERSION\`
EOF

echo "• Create a PR for cloudbeat hermit version"
gh pr create --title "Bump hermit cloudbeat version" \
pr_url="$(gh pr create --title "Bump hermit cloudbeat version" \
--body-file hermit_pr_body \
--base "main" \
--head "$BRANCH" \
--label "backport-skip"

rm -rf hermit_pr_body
--head "$NEXT_CLOUDBEAT_HERMIT_BRANCH" \
--label "backport-skip")"
# shellcheck disable=SC2086
echo "[Cloudbeat Hermit PR]($pr_url)" >>$GITHUB_STEP_SUMMARY
}

upload_cloud_formation_templates() {
Expand All @@ -146,21 +146,36 @@ upload_cloud_formation_templates() {

# make changes to 'main' for next version
run_version_changes_for_main() {
# create a new branch from the main branch
git fetch origin main
git checkout -b "$NEXT_CLOUDBEAT_BRANCH" origin/main

# commit
update_version_beat
update_version_mergify
update_version_arm_template_default_value

# push
create_cloudbeat_versions_pr_for_main

# create, commit and push a separate PR for hermit
git checkout -b "$NEXT_CLOUDBEAT_HERMIT_BRANCH" origin/main
bump_hermit
}

# make changes for 'release' version
run_version_changes_for_release_branch() {
# create a new branch from the current minor version
git fetch origin "$CURRENT_MINOR_VERSION"
git checkout -b "$RELEASE_CLOUDBEAT_BRANCH" origin/"$CURRENT_MINOR_VERSION"

# commit
update_version_arm_template_file_uris

# push
create_cloudbeat_versions_pr_for_release

# upload cloud formation templates for the release version
upload_cloud_formation_templates
}

Expand Down
4 changes: 3 additions & 1 deletion scripts/bump_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ EOF
--label "enhancement" \
--label "Team:Cloud Security" \
--repo "$INTEGRATION_REPO")"
# shellcheck disable=SC2086
echo "[Integrations PR]($PR_URL)" >>$GITHUB_STEP_SUMMARY
export PR_URL
}

Expand All @@ -76,7 +78,7 @@ update_manifest_version() {
update_changelog_version() {
echo "• Update changelog version"
yq -i ".[0].version = \"$NEXT_INTEGRATION_VERSION\"" $CHANGELOG_PATH
# this line below requires single quotes and env(PR) to interpolate this env var
# PR_URL needs to be exported
yq -i '.[0].changes += [{"description": "Bump version", "type": "enhancement", "link": env(PR_URL) }]' $CHANGELOG_PATH
git add $CHANGELOG_PATH
git commit -m "Update changelog version"
Expand Down
Loading