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

chore(*): add script to easily update project version before releases #200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions containerd-shim-spin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion deployments/workloads/workload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 17 additions & 19 deletions release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
103 changes: 103 additions & 0 deletions version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

place it to ./scripts?


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/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this one covers versions like v0.15.1-pre?

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