Skip to content

Commit 1f653b1

Browse files
chore(*): add script to easily update project version before releases
Signed-off-by: Kate Goldenring <[email protected]>
1 parent ca66312 commit 1f653b1

File tree

5 files changed

+128
-27
lines changed

5 files changed

+128
-27
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "Apache-2.0"
55
readme = "README.md"
66
repository = "https://github.com/spinkube/containerd-shim-spin"
77
homepage = "https://github.com/spinkube/containerd-shim-spin"
8-
8+
authors = ["SpinKube Engineering Team"]
99

1010
[workspace]
1111
resolver = "2"

containerd-shim-spin/Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "containerd-shim-spin-v2"
3-
version = "0.15.1"
4-
authors = ["SpinKube Engineering Team"]
5-
edition = "2021"
6-
repository = 'https://github.com/spinkube/containerd-shim-spin'
7-
license = "Apache-2.0"
8-
homepage = 'https://github.com/spinkube/containerd-shim-spin'
3+
version = { workspace = true}
4+
authors = { workspace = true}
5+
edition = { workspace = true}
6+
repository = { workspace = true}
7+
license = { workspace = true}
8+
homepage = { workspace = true}
99
description = """
1010
Containerd shim for running Spin workloads.
1111
"""

deployments/workloads/workload.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ spec:
1515
runtimeClassName: wasmtime-spin
1616
containers:
1717
- name: spin-hello
18-
image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:v0.15.1
18+
image: ghcr.io/spinkube/containerd-shim-spin/examples/spin-rust-hello:latest
1919
command: ["/"]
2020
resources: # limit the resources to 128Mi of memory and 100m of CPU
2121
limits:

release.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ To cut a new release of the `containerd-shim-spin`, you will need to do the
44
following:
55

66
1. Confirm that [CI is
7-
green](https://github.com/spinkube/containerd-shim-spin/actions) for the
8-
commit selected to be tagged and released.
9-
10-
1. Change all references of the version number in package
11-
12-
* [Cargo.toml](./Cargo.toml),
13-
* crate [Cargo.toml](./containerd-shim-spin/Cargo.toml),
14-
* [quickstart](./containerd-shim-spin/quickstart.md),
15-
* [README](./README.md),
16-
* [deployments](./deployments/),
17-
* [images](./images/).
18-
* [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
7+
green](https://github.com/spinkube/containerd-shim-spin/actions) for the commit selected to be
8+
tagged and released.
9+
10+
1. Change all references of the version number in repository using the `version.sh` script, which
11+
updates all Cargo manifests and README documentation to use a bumped version. Specify a major,
12+
minor, or patch version update using the `-m`, `-n`, `-p` flags, respectively.
13+
```sh
14+
# Update minor version (1.2.3 -> 1.3.0)
15+
version.sh -n
16+
```
17+
18+
1. Update [CHANGELOG.md](./CHANGELOG.md). The Unreleased section should be updated with the new
19+
version number and the date of the release. Update the links to new version tag in the footer of
20+
CHANGELOG.md.
21+
22+
1. Add a new column to the [README shim and Spin version map](./README.md#shim-and-spin-version-map)
23+
that lists the version of the Spin dependencies for the release.
1924

20-
Run `cargo build
21-
--release` to make sure lockfiles reflect Cargo.toml updates. Add a new
22-
column to the [README shim and Spin version
23-
map](./README.md#shim-and-spin-version-map) that lists the version of the
24-
Spin dependencies for the release.
25-
26-
2725
1. Create a pull request with these changes and merge once approved.
2826

2927
1. Checkout the commit with the version bump from above.

version.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
3+
OTHER_FILES=${MD_FILES_TO_UPDATE:-"containerd-shim-spin/quickstart.md, images/spin-dapr/README.md, deployments/k3d/README.md"}
4+
5+
get_version()
6+
{
7+
pkg_version=$(cargo pkgid --package containerd-shim-spin-v2)
8+
version=$(echo $pkg_version | sed -E 's/.*@([0-9]+\.[0-9]+\.[0-9]+)$/\1/')
9+
echo $version
10+
}
11+
12+
new_version()
13+
{
14+
OLD_VERSION=$1
15+
if [ "$SAME" != "1" ]; then
16+
if [ "$MAJOR" == "1" ]; then
17+
NEW_VERSION="$( echo $OLD_VERSION | awk -F '.' '{print $1 + 1}' ).0.0"
18+
elif [ "$MINOR" == "1" ]; then
19+
NEW_VERSION="$( echo $OLD_VERSION | awk -F '.' '{print $1}' ).$( echo $OLD_VERSION | awk -F '.' '{print $2 + 1}' ).0"
20+
elif [ "$PATCH" == "1" ]; then
21+
NEW_VERSION="$( echo $OLD_VERSION | awk -F '.' '{print $1}' ).$( echo $OLD_VERSION | awk -F '.' '{print $2}' ).$( echo $OLD_VERSION | awk -F '.' '{print $3 + 1}' )"
22+
fi
23+
else
24+
NEW_VERSION=$OLD_VERSION
25+
fi
26+
echo "$NEW_VERSION"
27+
}
28+
29+
update_file_version()
30+
{
31+
FILE=$1
32+
LINE_PATTERN=$2
33+
NEW_LINE=$3
34+
35+
echo "Update $FILE [$LINE_PATTERN] => [$NEW_LINE]"
36+
sed -i s/"$LINE_PATTERN"/"$NEW_LINE"/g $FILE
37+
return $?
38+
}
39+
40+
41+
BASEDIR=$(dirname "$0")
42+
43+
SAME=0
44+
MAJOR=0
45+
MINOR=0
46+
PATCH=1
47+
48+
49+
while getopts mnphs option
50+
do
51+
case "${option}" in
52+
m) MAJOR=1;;
53+
n) MINOR=1;;
54+
p) PATCH=1;;
55+
s) SAME=1;;
56+
h)
57+
echo "Increments versions depending on the semver option chosen"
58+
echo "Usage: version.sh [-u] [-c]"
59+
echo " -s updates all files to reflect the current base Cargo.toml version"
60+
echo " -m increments major version and sets minor and patch to 0"
61+
echo " -n increments minor version and sets patch to 0"
62+
echo " -p increments patch version"
63+
exit 0
64+
;;
65+
*)
66+
echo "Invalid option: -$OPTARG" >&2
67+
echo "Usage: version.sh [-s] [-m] [-n] [-p] [-h]"
68+
exit 1
69+
;;
70+
esac
71+
done
72+
73+
OLD_VERSION=$(get_version)
74+
NEW_VERSION=$(new_version $OLD_VERSION)
75+
76+
echo "Updating to version: $NEW_VERSION"
77+
78+
TOML_VERSION_PATTERN="^version = .*"
79+
TOML_VERSION_LINE="version = \"$NEW_VERSION\""
80+
81+
# 1) Update base Cargo.toml and workspace lockfile
82+
update_file_version "$BASEDIR/Cargo.toml" "$TOML_VERSION_PATTERN" "$TOML_VERSION_LINE"
83+
if [ "$?" -eq "1" ]; then exit 1; fi
84+
cargo update
85+
86+
# 2) Update test images and lockfiles
87+
for file in $(find $BASEDIR/images -name Cargo.toml); do
88+
update_file_version "$file" "$TOML_VERSION_PATTERN" "$TOML_VERSION_LINE"
89+
if [ "$?" -eq "1" ]; then exit 1; fi
90+
dir=$(dirname $file)
91+
if [[ $dir != /* ]]; then
92+
dir=$BASEDIR/$dir
93+
fi
94+
cargo update --manifest-path $dir/Cargo.toml
95+
done
96+
97+
# 3) Update all requested markdown file versions to $NEW_VERSION
98+
for file in $(echo $OTHER_FILES | tr ',' ' '); do
99+
update_file_version "$BASEDIR/$file" $OLD_VERSION $NEW_VERSION
100+
if [ "$?" -eq "1" ]; then exit 1; fi
101+
done
102+
103+
exit 0

0 commit comments

Comments
 (0)