Skip to content

Commit 453d0ca

Browse files
Merge pull request #200 from kate-goldenring/version-update-script
chore(*): add script to easily update project version before releases
2 parents 80e2b25 + 29e0eee commit 453d0ca

File tree

3 files changed

+130
-20
lines changed

3 files changed

+130
-20
lines changed

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/spinframework/containerd-shim-spin/examples/spin-rust-hello:v0.20.0
18+
image: ghcr.io/spinframework/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: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +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.
7+
green](https://github.com/spinframework/containerd-shim-spin/actions) for the commit selected to be
8+
tagged and released.
99

10-
1. Change all references of the version number in package
11-
12-
* [Cargo.toml](./Cargo.toml),
13-
* [quickstart](./containerd-shim-spin/quickstart.md),
14-
* [README](./README.md),
15-
* [deployments](./deployments/),
16-
* [images](./images/).
17-
* [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
18-
19-
Run `cargo build
20-
--release` to make sure lockfiles reflect Cargo.toml updates. Add a new
21-
column to the [README shim and Spin version
22-
map](./README.md#shim-and-spin-version-map) that lists the version of the
23-
Spin dependencies for the release.
24-
10+
1. Change all references of the version number in repository using the [`version.sh`](./scripts/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+
scripts/version.sh -n
16+
```
2517

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.
24+
2625
1. Create a pull request with these changes and merge once approved.
2726

2827
1. Checkout the commit with the version bump from above.
@@ -35,12 +34,12 @@ following:
3534
# Create a GPG-signed and annotated tag
3635
git tag -s -m "Containerd Shim Spin v0.15.0" v0.15.0
3736
38-
# Push the tag to the remote corresponding to spinkube/containerd-shim-spin (here 'origin')
37+
# Push the tag to the remote corresponding to spinframework/containerd-shim-spin (here 'origin')
3938
git push origin v0.15.0
4039
```
4140
4241
1. Pushing the tag upstream will trigger the [release
43-
action](https://github.com/spinkube/containerd-shim-spin/actions/workflows/release.yaml).
42+
action](https://github.com/spinframework/containerd-shim-spin/actions/workflows/release.yaml).
4443
- The release build will create binary releases of the shim and upload these
4544
assets to a new GitHub release for the pushed tag. Release notes are
4645
auto-generated but edit as needed especially around breaking changes or

scripts/version.sh

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

0 commit comments

Comments
 (0)