|
| 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 | +# And check that the REMOTE points to the -tools repo. |
| 21 | +REMOTE="${REMOTE:-origin}" |
| 22 | +if [[ "$(git remote get-url $REMOTE 2>/dev/null)" != *"awsdocs/aws-doc-sdk-examples-tools.git"* ]] ; then |
| 23 | + echo "REMOTE=${REMOTE} is not set to awsdocs/aws-doc-sdk-examples-tools.git, please adjust accordingly and rerun." |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | + |
| 27 | +# CURRENT and NEXT have the format YYYY.WW.REV, where YYYY is the current year, |
| 28 | +# WW is the current week, and REV is the number of releases this week. |
| 29 | +# The next revision compares the two, in this way |
| 30 | +# - If NEXT is later than CURRENT in any fields, accept NEXT. |
| 31 | +# - Otherwise, return CURRENT, with one added to REV. |
| 32 | +# |
| 33 | +# THIS FUNCTION IS NOT TRANSITIVE! It must be called with |
| 34 | +# `compare_versions CURRENT NEXT` |
| 35 | +compare_versions() { |
| 36 | + if [[ "$1" < "$2" ]] ; then |
| 37 | + echo "$2" |
| 38 | + else |
| 39 | + IFS='.' read -r y1 w1 r1 <<< "$1" |
| 40 | + r1=$((r1 + 1)) |
| 41 | + echo "${y1}.${w1}.${r1}" |
| 42 | + fi |
| 43 | +} |
| 44 | + |
| 45 | +# compare_versions 2024.44.4 2024.44.0 # 2024.44.5 |
| 46 | +# compare_versions 2024.44.4 2024.45.0 # 2024.45.0 |
| 47 | +# compare_versions 2024.44.4 2025.1.0 # 2025.1.0 |
| 48 | + |
| 49 | +CURRENT=$(grep version= setup.py | awk -F\" '{print $2}') |
| 50 | +NEXT=$(date +%Y.%W.0) |
| 51 | +VERSION=$(compare_versions "$CURRENT" "$NEXT") |
| 52 | +echo "Releasing $VERSION..." |
| 53 | +sed "/version=/ s/$CURRENT/$VERSION/" setup.py > setup.py.out ; mv setup.py.out setup.py |
| 54 | +git --no-pager diff |
| 55 | +git add setup.py |
| 56 | +git commit --message "Release ${VERSION}" |
| 57 | + |
| 58 | +if [ "$1" == "--release" ] ; then |
| 59 | + git tag "$VERSION" main |
| 60 | + git push "$REMOTE" "$VERSION" |
| 61 | + git push "$REMOTE" main |
| 62 | +fi |
0 commit comments