Skip to content

Commit ce531ee

Browse files
committed
Add stamp.sh file to more sanely advance the version number.
1 parent 1003c3c commit ce531ee

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="aws_doc_sdk_examples_tools",
8-
version="2024.40.0",
8+
version="2024.40.2",
99
packages=["aws_doc_sdk_examples_tools"],
1010
package_data={"aws_doc_sdk_examples_tools": ["config/*.yaml"]},
1111
entry_points={

stamp.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/sh
2+
3+
set -e # Exit on errors
4+
# set -x # Shell debugging
5+
6+
# First, check that we're on the main branch.
7+
BRANCH=$(git rev-parse --abbrev-rev HEAD)
8+
if [ "$BRANCH" != "main" ] ; then
9+
echo "Not on main, exiting!"
10+
exit 1
11+
fi
12+
13+
# And check that the main branch is clean
14+
STATUS=$(git status --porcelain)
15+
if [ -n "${STATUS}" ] ; then
16+
echo "Repository is not clean, exiting!"
17+
exit 1
18+
fi
19+
20+
# VERSION and DATE have the format YYYY.WW.REV, where YYYY is the current year,
21+
# WW is the current week, and REV is the number of releases this week.
22+
# The next revision compares the two, in this way
23+
# - If DATE is later than VERSION in all fields, accept date.
24+
# - Otherwise, return VERSION, with one added to REV.
25+
#
26+
# THIS FUNCTION IS NOT TRANSITIVE! It must be called with
27+
# `compare_versions CURRENT NEXT`
28+
compare_versions() {
29+
IFS='.' read -r y1 w1 r1 <<< "$1"
30+
IFS='.' read -r y2 w2 r2 <<< "$2"
31+
32+
if [ "$y1" -lt "$y2" ] || \
33+
[ "$w1" -lt "$w2" ] || \
34+
[ "$r1" -lt "$r2" ]; then
35+
echo "$2"
36+
else
37+
r1=$((r1 + 1))
38+
echo "${y1}.${w1}.${r1}"
39+
fi
40+
}
41+
42+
# compare_versions 2024.44.4 2024.44.0 # 2024.44.5
43+
# compare_versions 2024.44.4 2024.45.0 # 2024.45.0
44+
# compare_versions 2024.44.4 2025.1.0 # 2025.1.0
45+
46+
CURRENT=$(grep version= setup.py | awk -F\" '{print $2}')
47+
NEXT=$(date +%Y.%W.0)
48+
VERSION=$(compare_versions "$CURRENT" "$NEXT")
49+
echo "Releasing $VERSION..."
50+
sed -i '' "/version=/ s/$CURRENT/$VERSION/" setup.py
51+
git diff
52+
git add setup.py
53+
git commit --message "Release ${VERSION}"
54+
git tag $VERSION main
55+
git push origin $VERSION
56+
git push origin main

0 commit comments

Comments
 (0)