From 33742da422c0cb946e68c57b422b9bfa546d6be7 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Fri, 29 Mar 2024 21:52:27 +1100 Subject: [PATCH] Scripts for removing click ops --- do-release.sh | 97 ++++++++++++++++++++++++++++++++ scripts/get_release_version.py | 7 +++ scripts/merge_changelogs.py | 44 +++++++++++++++ scripts/prep_for_next_release.sh | 59 +++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100755 do-release.sh create mode 100755 scripts/get_release_version.py create mode 100755 scripts/merge_changelogs.py create mode 100755 scripts/prep_for_next_release.sh diff --git a/do-release.sh b/do-release.sh new file mode 100755 index 0000000000..9e4ee9dcc2 --- /dev/null +++ b/do-release.sh @@ -0,0 +1,97 @@ +#!/bin/sh + +set -e + +DOCKER_IMAGE=swiftnav/libsbp-build:2023-12-19 +RUN_DOCKER="docker run -it --rm -v $PWD:/mnt/workspace -t ${DOCKER_IMAGE}" +VERSION=$(./scripts/get_release_version.py $(git describe --match 'v*' --always --tags)) + +if [ $# -ne 0 ]; then + VERSION=$1 + shift +fi + +if [ -z "${CHANGELOG_GITHUB_TOKEN}" ]; then + echo "You must set CHANGELOG_GITHUB_TOKEN in your environment before running this command" + exit 1 +fi + +git diff --exit-code >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Working directory is not clean. Remove any and all changes before running this command" + exit 1 +fi + +echo "Releasing libsbp version ${VERSION}" + +echo "Creating initial commit and tag" +git commit --allow-empty -m "Release ${VERSION}" +git tag -a ${VERSION} -m "Version ${VERSION} of libsbp." + +echo "Building python" +${RUN_DOCKER} make gen-python + +echo "Updating tag" +git add . +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +echo "Building language bindings" +${RUN_DOCKER} make gen-java gen-javascript gen-protobuf +${RUN_DOCKER} make gen-c gen-haskell gen-javascript gen-rust + +echo "Updating tag" +git add . +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +echo "Rebuilding javascript" +${RUN_DOCKER} make gen-javascript +${RUN_DOCKER} make gen-javascript + +echo "Updating tag" +git add . +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +echo "Buliding kaitai" +${RUN_DOCKER} make gen-kaitai + +echo "Updating tag" +git add . +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +echo "Building documentation" +${RUN_DOCKER} make docs + +echo "Updating tag" +git add . +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +echo "Generating changelog" +make release +./scripts/merge_changelogs.py ${VERSION} +rm -f DRAFT_CHANGELOG.md + +echo "Updating tag" +git add . +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +git diff HEAD~1 + +cat < +git commit --amend -a -m "Release ${VERSION}" +git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp." + +Once you have fixed everything you can push to master + +Once pushed prepare for the next release by running ./scripts/prep_for_next_release.sh +EOF diff --git a/scripts/get_release_version.py b/scripts/get_release_version.py new file mode 100755 index 0000000000..41b1eb2f3c --- /dev/null +++ b/scripts/get_release_version.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +import sys + +major, minor, patch = sys.argv[1].split(".")[:3] +if "-" in patch: + patch = patch.split("-")[0] +print(f"{major}.{minor}.{int(patch) + 1}") diff --git a/scripts/merge_changelogs.py b/scripts/merge_changelogs.py new file mode 100755 index 0000000000..d726213a41 --- /dev/null +++ b/scripts/merge_changelogs.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +import re +import sys +from datetime import datetime + +with open("DRAFT_CHANGELOG.md", "r") as f: + draft = f.readlines() + +# The first 4 lines are just the title and "unreleased" headers which we will recreate later +draft = draft[4:] + +# The first line should now be the first real line of the "unreleased" section which is always a link to the full changelog. Find the next heading and discard everything afterwards +assert draft[0].startswith("[Full Changelog]") + +for i in range(1, len(draft)): + if draft[i].startswith("## [v"): + draft = draft[: i - 1] + break + +proposed = [ + f"## [{sys.argv[1]}](https://github.com/swift-nav/libsbp/tree/{sys.argv[1]}) ({datetime.today().strftime('%Y-%m-%d')})\n", + "\n", +] + +# Strip out anything which looks like a Jira ticket number +for i in range(len(draft)): + proposed.append(re.sub(r"\\\[[A-Z]*-[0-9]*\\\](?=[^(])", r"", draft[i])) +proposed.append("\n") + +print("Proposed new changelog section") +print("\n".join(proposed)) + +with open("CHANGELOG.md", "r") as f: + changelog = f.readlines() + +with open("CHANGELOG.md", "w") as f: + # Keep the first 2 lines from the original changelog + f.writelines(changelog[0:2]) + + # Then the new section + f.writelines(proposed) + + # Then the rest of the original + f.writelines(changelog[2:]) diff --git a/scripts/prep_for_next_release.sh b/scripts/prep_for_next_release.sh new file mode 100755 index 0000000000..717d689625 --- /dev/null +++ b/scripts/prep_for_next_release.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +set -e + +DOCKER_IMAGE=swiftnav/libsbp-build:2023-12-19 +RUN_DOCKER="docker run -it --rm -v $PWD:/mnt/workspace -t ${DOCKER_IMAGE}" +VERSION=$(./scripts/get_release_version.py $(git describe --match 'v*' --always --tags)) + +git diff --exit-code >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Working directory is not clean. Remove any and all changes before running this command" + exit 1 +fi + +echo "Creating initial commit" +git commit --allow-empty -m "prep for next release #no_auto_pr" + +echo "Building python" +${RUN_DOCKER} make gen-python + +echo "Updating commit" +git add . +git commit --amend -a -m "prep for next release #no_auto_pr" + +echo "Building language bindings" +${RUN_DOCKER} make gen-java gen-javascript gen-protobuf +${RUN_DOCKER} make gen-c gen-haskell gen-javascript gen-rust + +echo "Updating commit" +git add . +git commit --amend -a -m "prep for next release #no_auto_pr" + +echo "Rebuilding javascript" +${RUN_DOCKER} make gen-javascript +${RUN_DOCKER} make gen-javascript + +echo "Updating commit" +git add . +git commit --amend -a -m "prep for next release #no_auto_pr" + +echo "Buliding kaitai" +${RUN_DOCKER} make gen-kaitai + +echo "Updating commit" +git add . +git commit --amend -a -m "prep for next release #no_auto_pr" + +git diff HEAD~1 + +cat < +git commit --amend -a -m "prep for next release #no_auto_pr" + +Once you have fixed everything you can push to master +EOF