From 230b109c09a796adefda2c191a9b957d67b800eb Mon Sep 17 00:00:00 2001 From: Abhinandan Purkait Date: Mon, 22 Jul 2024 11:17:39 +0000 Subject: [PATCH] ci: update script to allow no op on rc tags Signed-off-by: Abhinandan Purkait --- .github/workflows/branch_preparation.yml | 2 ++ scripts/test-update-chart-version.sh | 8 ++++++++ scripts/update-chart-version.sh | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/branch_preparation.yml b/.github/workflows/branch_preparation.yml index fd2338867..3deb6367f 100644 --- a/.github/workflows/branch_preparation.yml +++ b/.github/workflows/branch_preparation.yml @@ -32,6 +32,7 @@ jobs: tag=${{ github.ref_name }} echo "BASE=$(nix-shell --pure --run "./scripts/update-chart-version.sh --tag $tag --type develop" ./shell.nix)" >> $GITHUB_ENV - name: Create Pull Request to develop + if: ${{ env.BASE }} id: cpr uses: peter-evans/create-pull-request@v5 with: @@ -67,6 +68,7 @@ jobs: tag=${{ github.ref_name }} echo "BASE=$(nix-shell --pure --run "./scripts/update-chart-version.sh --tag $tag --type release" ./shell.nix)" >> $GITHUB_ENV - name: Create Pull Request to release + if: ${{ env.BASE }} id: cpr uses: peter-evans/create-pull-request@v5 with: diff --git a/scripts/test-update-chart-version.sh b/scripts/test-update-chart-version.sh index bdd59c52b..61f5cf083 100755 --- a/scripts/test-update-chart-version.sh +++ b/scripts/test-update-chart-version.sh @@ -51,3 +51,11 @@ run_test "Test 6: Valid tag with type develop [patch release]" \ run_test "Test 7: Invalid tag format" \ "Invalid tag format. Expected 'vX.Y.Z'" \ --tag "1.2.3" --type "release" --dry-run + +run_test "Test 8: Supply an rc tag, with release type" \ + "" \ + --tag "v1.2.3-rc" --type "release" --dry-run + +run_test "Test 9: Supply an rc tag, with develop type" \ + "" \ + --tag "v1.2.3-rc" --type "develop" --dry-run \ No newline at end of file diff --git a/scripts/update-chart-version.sh b/scripts/update-chart-version.sh index 978f1cfef..f19f0206c 100755 --- a/scripts/update-chart-version.sh +++ b/scripts/update-chart-version.sh @@ -49,7 +49,7 @@ create_version_from_release_branch() { if [[ "$CURRENT_CHART_VERSION" == *"-develop" ]]; then VERSION="${EXTRACTED_VERSION}.0-prerelease" elif [[ "$CURRENT_CHART_VERSION" == *"-prerelease" ]]; then - VERSION=$CURRENT_CHART_VERSION + NO_OP=1 else die "Current chart version doesn't match a develop or prerel format" fi @@ -74,6 +74,8 @@ create_version_from_tag() { else die "Invalid type. Expected 'release' or 'develop'." fi + elif [[ "$TAG" == *"-rc" ]]; then + NO_OP=1 else die "Invalid tag format. Expected 'vX.Y.Z'" fi @@ -91,6 +93,8 @@ update_chart_yaml() { set -euo pipefail +DRY_RUN= +NO_OP= # Set the path to the Chart.yaml file SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")" ROOT_DIR="$SCRIPT_DIR/.." @@ -144,12 +148,14 @@ else die "Either --branch or --tag and --type must be specified." fi -if [[ -n $VERSION ]]; then - if [[ -z $DRY_RUN ]];then - update_chart_yaml "$VERSION" "$VERSION" +if [[ -z $NO_OP ]]; then + if [[ -n $VERSION ]]; then + if [[ -z $DRY_RUN ]];then + update_chart_yaml "$VERSION" "$VERSION" + else + echo "$VERSION" + fi else - echo "$VERSION" + die "Failed to update the chart versions" fi -else - die "Failed to update the chart versions" fi