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

Automate some release steps with scripts #2052

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions docs/developer/release/1-create-release-branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ A single release branch is created for every major or minor release. That releas
branch is then used for all Release Candidates, the Stable Release, and all
Patch Releases for that version of Alloy.

> **NOTE**: There's an experimental script in `scripts/release-process/create-release-branch.sh` that can
> facilitate this process.

## Before you begin

1. Determine the [VERSION_PREFIX](concepts/version.md).
Expand Down
3 changes: 3 additions & 0 deletions docs/developer/release/4-tag-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

A tag is required to create GitHub artifacts and as a prerequisite for publishing.

> **NOTE**: There's an experimental script in `scripts/release-process/tag-release.sh` that can
> facilitate this process.

## Before you begin

1. All required commits for the release should exist on the release branch. This includes functionality and documentation such as the `CHANGELOG.md`. All versions in code should have already been updated.
Expand Down
5 changes: 3 additions & 2 deletions internal/runtime/alloy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/grafana/alloy/internal/component"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/runtime/internal/controller"
"github.com/grafana/alloy/internal/runtime/internal/dag"
"github.com/grafana/alloy/internal/runtime/internal/testcomponents"
"github.com/grafana/alloy/internal/runtime/logging"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

var testFile = `
Expand Down
39 changes: 39 additions & 0 deletions tools/release-process/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function confirm_with_user() {
set +x
local prompt="$1"

printf "\n\n$prompt\n\n"
read -r -p "Answer Y/N: " CONFIRMATION

set -x
if [[ ! $CONFIRMATION =~ ^[Yy]$ ]]; then
echo "Confirmation failed. Exiting..."
exit 1
fi
}

function check_env_var_exists() {
local var_name="$1"
if [[ -z "${!var_name}" ]]; then
echo "ERROR: missing environment variable ${var_name}"
print_help_message
exit 1
else
echo "${var_name} confirmed to exist and set to '${!var_name}'"
fi
}

function check_on_branch() {
branch="$1"
if [[ "$(git branch --show-current)" != "$branch" ]]; then
echo "ERROR: You are not on the 'main' branch. Please switch to 'main' branch."
exit 1
fi
}

function verify_remote_exists() {
if ! git remote get-url "${1}" > /dev/null 2>&1; then
echo "Error: Remote '${1}' is not defined. This script requires it to exist and point to Alloy repo."
exit 1
fi
}
47 changes: 47 additions & 0 deletions tools/release-process/create-release-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -x -e

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$script_dir/common.sh"

function print_help_message() {
set +x
echo "USAGE: ${0}"
echo "Required environment variables:"
echo " - VERSION_PREFIX is the v<MAJOR>.<MINOR>, for example v1.5"
echo " - VERSION is the v<MAJOR>.<MINOR>.<PATCH>, for example v1.5.1"
echo " - COMMIT_SHA is the commit sha that we want to release"
set -x
}

check_env_var_exists "VERSION_PREFIX"
check_env_var_exists "COMMIT_SHA"

pushd "$(git rev-parse --show-toplevel)"

check_on_branch "main"

git pull

git checkout "${COMMIT_SHA}" > /dev/null 2>&1
git rev-parse --verify "${COMMIT_SHA}"

verify_remote_exists "origin"

RELEASE_BRANCH_NAME="release/${VERSION_PREFIX}"

if [[ -n "$(git branch -r --list "origin/${RELEASE_BRANCH_NAME}")" ]]; then
echo "Branch ${RELEASE_BRANCH_NAME} already exists in the upstream."
exit 1
fi

echo "Branch ${RELEASE_BRANCH_NAME} doesn't exist in the upstream yet. Creating..."
git checkout -b "${RELEASE_BRANCH_NAME}"

confirm_with_user "Successfully created branch for ${RELEASE_BRANCH_NAME} at ${COMMIT_SHA}. Push to origin?"

git push origin "${RELEASE_BRANCH_NAME}"
echo "DONE"

git checkout main # Go back to where we were.
popd
26 changes: 26 additions & 0 deletions tools/release-process/tag-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
set -e

script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$script_dir/common.sh"

check_env_var_exists "VERSION"
check_env_var_exists "VERSION_PREFIX"

confirm_with_user "All required commits for the release should exist on the release branch. This includes functionality and documentation such as the CHANGELOG.md. All versions in code should have already been updated. Do you confirm this is completed?"

verify_remote_exists "origin"

RELEASE_BRANCH_NAME="release/${VERSION_PREFIX}"

git checkout "${RELEASE_BRANCH_NAME}"
check_on_branch "${RELEASE_BRANCH_NAME}"

git pull origin "${RELEASE_BRANCH_NAME}"
git diff --name-only "origin/${RELEASE_BRANCH_NAME}...HEAD"

GPG_TTY=$(tty) git tag -s "$VERSION"

confirm_with_user "Tag for ${VERSION} successful on ${RELEASE_BRANCH_NAME}. Push to origin?"

git push origin "$VERSION"