From 1f653b1e3cb15c5f6bae4abab151deb69d851ee8 Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Fri, 4 Oct 2024 14:54:56 -0700 Subject: [PATCH] chore(*): add script to easily update project version before releases Signed-off-by: Kate Goldenring --- Cargo.toml | 2 +- containerd-shim-spin/Cargo.toml | 12 ++-- deployments/workloads/workload.yaml | 2 +- release.md | 36 +++++----- version.sh | 103 ++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 27 deletions(-) create mode 100755 version.sh diff --git a/Cargo.toml b/Cargo.toml index 3c520c9..d7668cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ license = "Apache-2.0" readme = "README.md" repository = "https://github.com/spinkube/containerd-shim-spin" homepage = "https://github.com/spinkube/containerd-shim-spin" - +authors = ["SpinKube Engineering Team"] [workspace] resolver = "2" diff --git a/containerd-shim-spin/Cargo.toml b/containerd-shim-spin/Cargo.toml index a45e220..5b05b1b 100644 --- a/containerd-shim-spin/Cargo.toml +++ b/containerd-shim-spin/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "containerd-shim-spin-v2" -version = "0.15.1" -authors = ["SpinKube Engineering Team"] -edition = "2021" -repository = 'https://github.com/spinkube/containerd-shim-spin' -license = "Apache-2.0" -homepage = 'https://github.com/spinkube/containerd-shim-spin' +version = { workspace = true} +authors = { workspace = true} +edition = { workspace = true} +repository = { workspace = true} +license = { workspace = true} +homepage = { workspace = true} description = """ Containerd shim for running Spin workloads. """ diff --git a/deployments/workloads/workload.yaml b/deployments/workloads/workload.yaml index 152ac94..019ee6c 100644 --- a/deployments/workloads/workload.yaml +++ b/deployments/workloads/workload.yaml @@ -15,7 +15,7 @@ spec: runtimeClassName: wasmtime-spin containers: - name: spin-hello - image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.15.1 + image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:latest command: ["/"] resources: # limit the resources to 128Mi of memory and 100m of CPU limits: diff --git a/release.md b/release.md index aa90a78..01b8eab 100644 --- a/release.md +++ b/release.md @@ -4,26 +4,24 @@ To cut a new release of the `containerd-shim-spin`, you will need to do the following: 1. Confirm that [CI is - green](https://github.com/spinkube/containerd-shim-spin/actions) for the - commit selected to be tagged and released. - -1. Change all references of the version number in package - - * [Cargo.toml](./Cargo.toml), - * crate [Cargo.toml](./containerd-shim-spin/Cargo.toml), - * [quickstart](./containerd-shim-spin/quickstart.md), - * [README](./README.md), - * [deployments](./deployments/), - * [images](./images/). - * [CHANGELOG.md](./CHANGELOG.md) the Unreleased section should be updated with the new version number and the date of the release. Update the links to new version tag in the footer of CHANGELOG.md + green](https://github.com/spinkube/containerd-shim-spin/actions) for the commit selected to be + tagged and released. + +1. Change all references of the version number in repository using the `version.sh` script, which + updates all Cargo manifests and README documentation to use a bumped version. Specify a major, + minor, or patch version update using the `-m`, `-n`, `-p` flags, respectively. + ```sh + # Update minor version (1.2.3 -> 1.3.0) + version.sh -n + ``` + +1. Update [CHANGELOG.md](./CHANGELOG.md). The Unreleased section should be updated with the new + version number and the date of the release. Update the links to new version tag in the footer of + CHANGELOG.md. + +1. Add a new column to the [README shim and Spin version map](./README.md#shim-and-spin-version-map) + that lists the version of the Spin dependencies for the release. - Run `cargo build - --release` to make sure lockfiles reflect Cargo.toml updates. Add a new - column to the [README shim and Spin version - map](./README.md#shim-and-spin-version-map) that lists the version of the - Spin dependencies for the release. - - 1. Create a pull request with these changes and merge once approved. 1. Checkout the commit with the version bump from above. diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..14de28b --- /dev/null +++ b/version.sh @@ -0,0 +1,103 @@ +#!/bin/bash + +OTHER_FILES=${MD_FILES_TO_UPDATE:-"containerd-shim-spin/quickstart.md, images/spin-dapr/README.md, deployments/k3d/README.md"} + +get_version() +{ + pkg_version=$(cargo pkgid --package containerd-shim-spin-v2) + version=$(echo $pkg_version | sed -E 's/.*@([0-9]+\.[0-9]+\.[0-9]+)$/\1/') + echo $version +} + +new_version() +{ + OLD_VERSION=$1 + if [ "$SAME" != "1" ]; then + if [ "$MAJOR" == "1" ]; then + NEW_VERSION="$( echo $OLD_VERSION | awk -F '.' '{print $1 + 1}' ).0.0" + elif [ "$MINOR" == "1" ]; then + NEW_VERSION="$( echo $OLD_VERSION | awk -F '.' '{print $1}' ).$( echo $OLD_VERSION | awk -F '.' '{print $2 + 1}' ).0" + elif [ "$PATCH" == "1" ]; then + NEW_VERSION="$( echo $OLD_VERSION | awk -F '.' '{print $1}' ).$( echo $OLD_VERSION | awk -F '.' '{print $2}' ).$( echo $OLD_VERSION | awk -F '.' '{print $3 + 1}' )" + fi + else + NEW_VERSION=$OLD_VERSION + fi + echo "$NEW_VERSION" +} + +update_file_version() +{ + FILE=$1 + LINE_PATTERN=$2 + NEW_LINE=$3 + + echo "Update $FILE [$LINE_PATTERN] => [$NEW_LINE]" + sed -i s/"$LINE_PATTERN"/"$NEW_LINE"/g $FILE + return $? +} + + +BASEDIR=$(dirname "$0") + +SAME=0 +MAJOR=0 +MINOR=0 +PATCH=1 + + +while getopts mnphs option +do +case "${option}" in +m) MAJOR=1;; +n) MINOR=1;; +p) PATCH=1;; +s) SAME=1;; +h) + echo "Increments versions depending on the semver option chosen" + echo "Usage: version.sh [-u] [-c]" + echo " -s updates all files to reflect the current base Cargo.toml version" + echo " -m increments major version and sets minor and patch to 0" + echo " -n increments minor version and sets patch to 0" + echo " -p increments patch version" + exit 0 + ;; +*) + echo "Invalid option: -$OPTARG" >&2 + echo "Usage: version.sh [-s] [-m] [-n] [-p] [-h]" + exit 1 + ;; +esac +done + +OLD_VERSION=$(get_version) +NEW_VERSION=$(new_version $OLD_VERSION) + +echo "Updating to version: $NEW_VERSION" + +TOML_VERSION_PATTERN="^version = .*" +TOML_VERSION_LINE="version = \"$NEW_VERSION\"" + +# 1) Update base Cargo.toml and workspace lockfile +update_file_version "$BASEDIR/Cargo.toml" "$TOML_VERSION_PATTERN" "$TOML_VERSION_LINE" +if [ "$?" -eq "1" ]; then exit 1; fi +cargo update + +# 2) Update test images and lockfiles +for file in $(find $BASEDIR/images -name Cargo.toml); do + update_file_version "$file" "$TOML_VERSION_PATTERN" "$TOML_VERSION_LINE" + if [ "$?" -eq "1" ]; then exit 1; fi + dir=$(dirname $file) + if [[ $dir != /* ]]; then + dir=$BASEDIR/$dir + fi + cargo update --manifest-path $dir/Cargo.toml +done + +# 3) Update all requested markdown file versions to $NEW_VERSION +for file in $(echo $OTHER_FILES | tr ',' ' '); do + update_file_version "$BASEDIR/$file" $OLD_VERSION $NEW_VERSION + if [ "$?" -eq "1" ]; then exit 1; fi +done + +exit 0 \ No newline at end of file