Skip to content

Commit 33742da

Browse files
author
Matt Woodward
committed
Scripts for removing click ops
1 parent b5183cf commit 33742da

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed

do-release.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
DOCKER_IMAGE=swiftnav/libsbp-build:2023-12-19
6+
RUN_DOCKER="docker run -it --rm -v $PWD:/mnt/workspace -t ${DOCKER_IMAGE}"
7+
VERSION=$(./scripts/get_release_version.py $(git describe --match 'v*' --always --tags))
8+
9+
if [ $# -ne 0 ]; then
10+
VERSION=$1
11+
shift
12+
fi
13+
14+
if [ -z "${CHANGELOG_GITHUB_TOKEN}" ]; then
15+
echo "You must set CHANGELOG_GITHUB_TOKEN in your environment before running this command"
16+
exit 1
17+
fi
18+
19+
git diff --exit-code >/dev/null 2>&1
20+
if [ $? -ne 0 ]; then
21+
echo "Working directory is not clean. Remove any and all changes before running this command"
22+
exit 1
23+
fi
24+
25+
echo "Releasing libsbp version ${VERSION}"
26+
27+
echo "Creating initial commit and tag"
28+
git commit --allow-empty -m "Release ${VERSION}"
29+
git tag -a ${VERSION} -m "Version ${VERSION} of libsbp."
30+
31+
echo "Building python"
32+
${RUN_DOCKER} make gen-python
33+
34+
echo "Updating tag"
35+
git add .
36+
git commit --amend -a -m "Release ${VERSION}"
37+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
38+
39+
echo "Building language bindings"
40+
${RUN_DOCKER} make gen-java gen-javascript gen-protobuf
41+
${RUN_DOCKER} make gen-c gen-haskell gen-javascript gen-rust
42+
43+
echo "Updating tag"
44+
git add .
45+
git commit --amend -a -m "Release ${VERSION}"
46+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
47+
48+
echo "Rebuilding javascript"
49+
${RUN_DOCKER} make gen-javascript
50+
${RUN_DOCKER} make gen-javascript
51+
52+
echo "Updating tag"
53+
git add .
54+
git commit --amend -a -m "Release ${VERSION}"
55+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
56+
57+
echo "Buliding kaitai"
58+
${RUN_DOCKER} make gen-kaitai
59+
60+
echo "Updating tag"
61+
git add .
62+
git commit --amend -a -m "Release ${VERSION}"
63+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
64+
65+
echo "Building documentation"
66+
${RUN_DOCKER} make docs
67+
68+
echo "Updating tag"
69+
git add .
70+
git commit --amend -a -m "Release ${VERSION}"
71+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
72+
73+
echo "Generating changelog"
74+
make release
75+
./scripts/merge_changelogs.py ${VERSION}
76+
rm -f DRAFT_CHANGELOG.md
77+
78+
echo "Updating tag"
79+
git add .
80+
git commit --amend -a -m "Release ${VERSION}"
81+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
82+
83+
git diff HEAD~1
84+
85+
cat <<EOF
86+
A new commit and tag has been created. Look at the above diff and verify the contents. If everything looks good you can push to master straight away.
87+
88+
If there are any mistakes now is the time to correct them. Make any changes which are required then update the tag by running:
89+
90+
git add <files>
91+
git commit --amend -a -m "Release ${VERSION}"
92+
git tag -f -a ${VERSION} -m "Version ${VERSION} of libsbp."
93+
94+
Once you have fixed everything you can push to master
95+
96+
Once pushed prepare for the next release by running ./scripts/prep_for_next_release.sh
97+
EOF

scripts/get_release_version.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python
2+
import sys
3+
4+
major, minor, patch = sys.argv[1].split(".")[:3]
5+
if "-" in patch:
6+
patch = patch.split("-")[0]
7+
print(f"{major}.{minor}.{int(patch) + 1}")

scripts/merge_changelogs.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
import re
3+
import sys
4+
from datetime import datetime
5+
6+
with open("DRAFT_CHANGELOG.md", "r") as f:
7+
draft = f.readlines()
8+
9+
# The first 4 lines are just the title and "unreleased" headers which we will recreate later
10+
draft = draft[4:]
11+
12+
# 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
13+
assert draft[0].startswith("[Full Changelog]")
14+
15+
for i in range(1, len(draft)):
16+
if draft[i].startswith("## [v"):
17+
draft = draft[: i - 1]
18+
break
19+
20+
proposed = [
21+
f"## [{sys.argv[1]}](https://github.com/swift-nav/libsbp/tree/{sys.argv[1]}) ({datetime.today().strftime('%Y-%m-%d')})\n",
22+
"\n",
23+
]
24+
25+
# Strip out anything which looks like a Jira ticket number
26+
for i in range(len(draft)):
27+
proposed.append(re.sub(r"\\\[[A-Z]*-[0-9]*\\\](?=[^(])", r"", draft[i]))
28+
proposed.append("\n")
29+
30+
print("Proposed new changelog section")
31+
print("\n".join(proposed))
32+
33+
with open("CHANGELOG.md", "r") as f:
34+
changelog = f.readlines()
35+
36+
with open("CHANGELOG.md", "w") as f:
37+
# Keep the first 2 lines from the original changelog
38+
f.writelines(changelog[0:2])
39+
40+
# Then the new section
41+
f.writelines(proposed)
42+
43+
# Then the rest of the original
44+
f.writelines(changelog[2:])

scripts/prep_for_next_release.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
DOCKER_IMAGE=swiftnav/libsbp-build:2023-12-19
6+
RUN_DOCKER="docker run -it --rm -v $PWD:/mnt/workspace -t ${DOCKER_IMAGE}"
7+
VERSION=$(./scripts/get_release_version.py $(git describe --match 'v*' --always --tags))
8+
9+
git diff --exit-code >/dev/null 2>&1
10+
if [ $? -ne 0 ]; then
11+
echo "Working directory is not clean. Remove any and all changes before running this command"
12+
exit 1
13+
fi
14+
15+
echo "Creating initial commit"
16+
git commit --allow-empty -m "prep for next release #no_auto_pr"
17+
18+
echo "Building python"
19+
${RUN_DOCKER} make gen-python
20+
21+
echo "Updating commit"
22+
git add .
23+
git commit --amend -a -m "prep for next release #no_auto_pr"
24+
25+
echo "Building language bindings"
26+
${RUN_DOCKER} make gen-java gen-javascript gen-protobuf
27+
${RUN_DOCKER} make gen-c gen-haskell gen-javascript gen-rust
28+
29+
echo "Updating commit"
30+
git add .
31+
git commit --amend -a -m "prep for next release #no_auto_pr"
32+
33+
echo "Rebuilding javascript"
34+
${RUN_DOCKER} make gen-javascript
35+
${RUN_DOCKER} make gen-javascript
36+
37+
echo "Updating commit"
38+
git add .
39+
git commit --amend -a -m "prep for next release #no_auto_pr"
40+
41+
echo "Buliding kaitai"
42+
${RUN_DOCKER} make gen-kaitai
43+
44+
echo "Updating commit"
45+
git add .
46+
git commit --amend -a -m "prep for next release #no_auto_pr"
47+
48+
git diff HEAD~1
49+
50+
cat <<EOF
51+
A new commit and tag has been created. Look at the above diff and verify the contents. If everything looks good you can push to master straight away.
52+
53+
If there are any mistakes now is the time to correct them. Make any changes which are required then update the tag by running:
54+
55+
git add <files>
56+
git commit --amend -a -m "prep for next release #no_auto_pr"
57+
58+
Once you have fixed everything you can push to master
59+
EOF

0 commit comments

Comments
 (0)