From 09337f338c8ee794eb16047d94feb9ae7a143fe9 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Fri, 2 May 2025 17:22:24 +0200 Subject: [PATCH 1/3] fix(release): Make scripts exit on failure If they were originally there to handle failures without exiting then that should be done through regular means without disabling the flag. --- release/create-release-candidate-branch.sh | 3 --- release/post-release.sh | 6 ------ release/tag-release-candidate.sh | 3 --- 3 files changed, 12 deletions(-) diff --git a/release/create-release-candidate-branch.sh b/release/create-release-candidate-branch.sh index e394194..eee8271 100755 --- a/release/create-release-candidate-branch.sh +++ b/release/create-release-candidate-branch.sh @@ -344,10 +344,7 @@ main() { check_dependencies # sanity checks before we start: folder, branches etc. - # deactivate -e so that piped commands can be used - set +e checks - set -e echo "Cloning docker-images and/or operators to [$TEMP_RELEASE_FOLDER]" rc_branch_repos diff --git a/release/post-release.sh b/release/post-release.sh index a814777..f48822d 100755 --- a/release/post-release.sh +++ b/release/post-release.sh @@ -199,20 +199,14 @@ main() { if [ "products" == "$WHAT" ] || [ "all" == "$WHAT" ]; then # sanity checks before we start: folder, branches etc. - # deactivate -e so that piped commands can be used - set +e check_products - set -e echo "Update $DOCKER_IMAGES_REPO main changelog for release $RELEASE_TAG" update_products fi if [ "operators" == "$WHAT" ] || [ "all" == "$WHAT" ]; then # sanity checks before we start: folder, branches etc. - # deactivate -e so that piped commands can be used - set +e check_operators - set -e echo "Update the operator main changelog for release $RELEASE_TAG" update_operators diff --git a/release/tag-release-candidate.sh b/release/tag-release-candidate.sh index 0e2bd60..b97d846 100755 --- a/release/tag-release-candidate.sh +++ b/release/tag-release-candidate.sh @@ -210,10 +210,7 @@ main() { check_dependencies # sanity checks before we start: folder, branches etc. - # deactivate -e so that piped commands can be used - set +e checks - set -e tag_repos cleanup From 9a5c903cc51d5af65eda0e1e03f95eb1789784a1 Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Wed, 28 May 2025 17:12:40 +0200 Subject: [PATCH 2/3] chore(release): Handle failing commands gracefully in strict mode --- release/create-release-candidate-branch.sh | 32 +++++++++++----------- release/merge-release-candidate.sh | 8 ++---- release/post-release.sh | 17 ++++++------ release/tag-release-candidate.sh | 16 +++++------ 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/release/create-release-candidate-branch.sh b/release/create-release-candidate-branch.sh index eee8271..a852722 100755 --- a/release/create-release-candidate-branch.sh +++ b/release/create-release-candidate-branch.sh @@ -71,8 +71,7 @@ check_tag_is_valid() { git fetch --tags # check tags: N.B. look for exact match - TAG_EXISTS=$(git tag --list | grep -E "$RELEASE_TAG$") - if [ -n "$TAG_EXISTS" ]; then + if git tag --list | grep -E "^$RELEASE_TAG\$"; then >&2 echo "Tag $RELEASE_TAG already exists!" exit 1 fi @@ -100,17 +99,18 @@ check_products() { # switch to the release branch, which should exist as tagging # is subsequent to creating the branch. - BRANCH_EXISTS=$(git branch -a | grep -E "$RELEASE_BRANCH$") - - if [ -z "${BRANCH_EXISTS}" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$RELEASE_BRANCH\$" + if ! git branch -a | grep -E "$RELEASE_BRANCH\$"; then >&2 echo "Expected release branch is missing: $RELEASE_BRANCH" exit 1 fi # the new PR should not exist, otherwise a duplicate commit # will be prepared - BRANCH_EXISTS=$(git branch -a | grep -E "$PR_BRANCH$") - if [ -n "${BRANCH_EXISTS}" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$PR_BRANCH\$" + if git branch -a | grep -E "$PR_BRANCH\$"; then >&2 echo "PR branch already exists: ${REMOTE}/$PR_BRANCH" exit 1 fi @@ -137,16 +137,18 @@ check_operators() { fi cd "$TEMP_RELEASE_FOLDER/${operator}" - BRANCH_EXISTS=$(git branch -a | grep -E "$RELEASE_BRANCH$") - if [ -z "${BRANCH_EXISTS}" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$RELEASE_BRANCH\$" + if ! git branch -a | grep -E "$RELEASE_BRANCH\$"; then >&2 echo "Expected release branch is missing: ${operator}/$RELEASE_BRANCH" exit 1 fi # the new PR should not exist, otherwise a duplicate commit # will be prepared - BRANCH_EXISTS=$(git branch -a | grep -E "$PR_BRANCH$") - if [ -n "${BRANCH_EXISTS}" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$PR_BRANCH\$" + if git branch -a | grep -E "$PR_BRANCH\$"; then >&2 echo "PR branch already exists: ${operator}/$PR_BRANCH" exit 1 fi @@ -292,14 +294,12 @@ parse_inputs() { check_dependencies() { # check for a globally configured git user - git_user=$(git config --global --includes --get user.name) - git_email=$(git config --global --includes --get user.email) - echo "global git user: $git_user <$git_email>" - - if [ -z "$git_user" ] || [ -z "$git_email" ]; then + if ! git_user=$(git config --global --includes --get user.name) \ + || ! git_email=$(git config --global --includes --get user.email); then >&2 echo "Error: global git user name/email is not set." exit 1 else + echo "global git user: $git_user <$git_email>" echo "Is this correct? (y/n)" read -r response if [[ "$response" == "y" || "$response" == "Y" ]]; then diff --git a/release/merge-release-candidate.sh b/release/merge-release-candidate.sh index 22bd8e6..7ef771d 100755 --- a/release/merge-release-candidate.sh +++ b/release/merge-release-candidate.sh @@ -89,14 +89,12 @@ merge() { check_dependencies() { # check for a globally configured git user - git_user=$(git config --global --includes --get user.name) - git_email=$(git config --global --includes --get user.email) - echo "global git user: $git_user <$git_email>" - - if [ -z "$git_user" ] || [ -z "$git_email" ]; then + if ! git_user=$(git config --global --includes --get user.name) \ + || ! git_email=$(git config --global --includes --get user.email); then >&2 echo "Error: global git user name/email is not set." exit 1 else + echo "global git user: $git_user <$git_email>" echo "Is this correct? (y/n)" read -r response if [[ "$response" == "y" || "$response" == "Y" ]]; then diff --git a/release/post-release.sh b/release/post-release.sh index f48822d..57f22bd 100755 --- a/release/post-release.sh +++ b/release/post-release.sh @@ -64,14 +64,14 @@ check_operators() { exit 2 fi - BRANCH_EXISTS=$(git branch -a | grep "$RELEASE_BRANCH") - if [ -z "$BRANCH_EXISTS" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$RELEASE_BRANCH\$" + if ! git branch -a | grep "$RELEASE_BRANCH\$"; then >&2 echo "Expected release branch is missing: $OPERATOR/$RELEASE_BRANCH" exit 1 fi git fetch --tags - TAG_EXISTS=$(git tag | grep "$RELEASE_TAG") - if [ -z "$TAG_EXISTS" ]; then + if ! git tag | grep "^$RELEASE_TAG\$"; then >&2 echo "Expected tag $RELEASE_TAG missing for operator $OPERATOR" exit 1 fi @@ -127,15 +127,16 @@ check_products() { exit 2 fi - BRANCH_EXISTS=$(git branch -a | grep "$RELEASE_BRANCH") - if [ -z "${BRANCH_EXISTS}" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$RELEASE_BRANCH\$" + if ! git branch -a | grep "$RELEASE_BRANCH\$"; then >&2 echo "Expected release branch is missing: $DOCKER_IMAGES_REPO/$RELEASE_BRANCH" exit 1 fi git fetch --tags - TAG_EXISTS=$(git tag | grep "$RELEASE_TAG") - if [ -z "${TAG_EXISTS}" ]; then + # check tags: N.B. look for exact match + if ! git tag | grep "^$RELEASE_TAG\$"; then >&2 echo "Expected tag $RELEASE_TAG missing for $DOCKER_IMAGES_REPO" exit 1 fi diff --git a/release/tag-release-candidate.sh b/release/tag-release-candidate.sh index b97d846..359336b 100755 --- a/release/tag-release-candidate.sh +++ b/release/tag-release-candidate.sh @@ -44,8 +44,7 @@ check_tag_is_valid() { git fetch --tags # check tags: N.B. look for exact match - TAG_EXISTS=$(git tag --list | grep -E "$RELEASE_TAG$") - if [ -n "$TAG_EXISTS" ]; then + if git tag --list | grep -E "^$RELEASE_TAG\$"; then >&2 echo "Tag $RELEASE_TAG already exists!" exit 1 fi @@ -81,8 +80,9 @@ check_operators() { fi cd "$TEMP_RELEASE_FOLDER/${operator}" - BRANCH_EXISTS=$(git branch -a | grep -E "$RELEASE_BRANCH$") - if [ -z "${BRANCH_EXISTS}" ]; then + # Note, if this needs to check the branch exists locally, then use: + # "^[ *]*$RELEASE_BRANCH\$" + if ! git branch -a | grep -E "$RELEASE_BRANCH\$"; then >&2 echo "Expected release branch is missing: ${operator}/$RELEASE_BRANCH" exit 1 fi @@ -158,14 +158,12 @@ parse_inputs() { check_dependencies() { # check for a globally configured git user - git_user=$(git config --global --includes --get user.name) - git_email=$(git config --global --includes --get user.email) - echo "global git user: $git_user <$git_email>" - - if [ -z "$git_user" ] || [ -z "$git_email" ]; then + if ! git_user=$(git config --global --includes --get user.name) \ + || ! git_email=$(git config --global --includes --get user.email); then >&2 echo "Error: global git user name/email is not set." exit 1 else + echo "global git user: $git_user <$git_email>" echo "Is this correct? (y/n)" read -r response if [[ "$response" == "y" || "$response" == "Y" ]]; then From 857c776aa6c07890f715571fcb6559d3a10794be Mon Sep 17 00:00:00 2001 From: Nick Larsen Date: Wed, 28 May 2025 17:13:02 +0200 Subject: [PATCH 3/3] chore(nix): Add pyyaml dependency to pass the pre-req checks in release scripts --- shell.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index 04c6a49..4883b4f 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,6 @@ -{ pkgs ? import { } }: +{ + pkgs ? import { }, +}: pkgs.mkShell { nativeBuildInputs = with pkgs; [ cargo-edit @@ -7,5 +9,6 @@ pkgs.mkShell { jinja2-cli yq-go python311Packages.pip + python311Packages.pyyaml ]; }