From 3e714f6139f46700bd95d9bd859cd206a6e2266a Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 15 Jan 2025 16:43:08 +0100 Subject: [PATCH] setup script for maintenance branch By changing the folder changie uses for the changelog we can make sure that users can put the changelog entries into a specific folder based on if the change will be backported. This way it will only appear in the patch release of the maintenance branch and not in the changelog of the current development branch. --- .changes/backported/.gitkeep | 0 scripts/changelog.sh | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 .changes/backported/.gitkeep diff --git a/.changes/backported/.gitkeep b/.changes/backported/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scripts/changelog.sh b/scripts/changelog.sh index c12ae22d6a..fd66202f0f 100755 --- a/scripts/changelog.sh +++ b/scripts/changelog.sh @@ -21,12 +21,18 @@ Commands: type. The release type should be one of "dev", "alpha", "rc", "release", or "patch". `dev`: will update the changelog with the latest unreleased changes. `alpha`: will generate a new section with an alpha version for today. + `beta`: will generate a new beta release. `rc`: will generate a new rc release. `release`: will make the initial minor release for this branch. `patch`: will generate a new patch release nextminor - Run this to get a new release branch for the next minor version. + This function expects the current branch to be main. Run it if you want to set main to the next + minor version. + + maintenancerelease + + EOF } @@ -128,11 +134,13 @@ function generate { cat ./.changes/previous-releases.md >> CHANGELOG.md } +# This function expects the current branch to be main. Run it if you want to set main to the next +# minor version. function nextminor { + # Prepend the latest version to the previous releases LATEST_VERSION=$(npx -y changie@$CHANGIE_VERSION latest -r --skip-prereleases) LATEST_VERSION=${LATEST_VERSION%.*} # Remove the patch version CURRENT_FILE_CONTENT=$(cat ./.changes/previous-releases.md) - # Prepend the latest version to the previous releases echo "- [v$LATEST_VERSION](https://github.com/hashicorp/terraform/blob/v$LATEST_VERSION/CHANGELOG.md)" > ./.changes/previous-releases.md echo "$CURRENT_FILE_CONTENT" >> ./.changes/previous-releases.md @@ -141,22 +149,42 @@ function nextminor { rm ./.changes/*.*.*.md # Remove all unreleased changes rm ./.changes/unreleased/*.yaml + # Remove all backported changes + rm ./.changes/backported/*.yaml # Create a new empty version file for the next minor version touch ./.changes/$NEXT_VERSION.md generate "dev" } +# This function is expected to be run on the branch of the last minor release. It will make sure +# that backports work properly +function maintenancerelease { + # For the maintenance branch we don't want to base our changelog on the unreleased but the backported folder instead + awk '{sub(/unreleasedDir: unreleased/, "unreleasedDir: backported")}1' ./.changie.yaml > temp && mv temp ./.changie.yaml + + # If we have unreleased changes, they will be released in the next patch, therefore they need + # to go into the backported folder + if [ "$(ls -A ./.changes/unreleased/)" ]; then + mv ./.changes/unreleased/* ./.changes/backported/ + fi + + generate "dev" +} + function main { case "$1" in generate) generate "${@:2}" - ;; + nextminor) nextminor "${@:2}" - ;; + + maintenancerelease) + maintenancerelease "${@:2}" + ;; *) usage exit 1