Skip to content

Commit 4a32c80

Browse files
author
Jochum van der Ploeg
authored
chore: add release and retag script (#298)
1 parent 0a3200f commit 4a32c80

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

tool/release_ready.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
3+
# Ensures that the package is ready for a release.
4+
#
5+
# Will update the version.dart file and update the CHANGELOG.md.
6+
#
7+
# Set it up for a new version:
8+
# `./release_ready.sh <version>
9+
10+
currentBranch=$(git symbolic-ref --short -q HEAD)
11+
if [[ ! $currentBranch == "main" ]]; then
12+
echo "Releasing is only supported on the main branch."
13+
exit 1
14+
fi
15+
16+
# Get information
17+
old_version=$(git for-each-ref --count=2 --format "%(refname:short)" --sort=-creatordate refs/tags | tail -n +2 | cut -c 2-)
18+
19+
if [ -z "$old_version" ]; then
20+
echo "Current version was not resolved."
21+
exit 1
22+
fi
23+
24+
# Get new version
25+
new_version="$1";
26+
27+
if [[ "$new_version" == "" ]]; then
28+
echo "No new version supplied, please provide one"
29+
exit 1
30+
fi
31+
32+
if [[ "$new_version" == "$old_version" ]]; then
33+
echo "Current version is $old_version, can't update."
34+
exit 1
35+
fi
36+
37+
# Retrieving all the commits in the current directory since the last tag.
38+
previousTag="v${old_version}"
39+
raw_commits="$(git log --pretty=format:"%s" --no-merges --reverse $previousTag..HEAD -- .)"
40+
markdown_commits=$(echo "$raw_commits" | sed -En "s/\(#([0-9]+)\)/([#\1](https:\/\/github.com\/VeryGoodOpenSource\/very_good_workflows\/pull\/\1))/p")
41+
42+
if [[ "$markdown_commits" == "" ]]; then
43+
echo "No commits since last tag, can't update."
44+
exit 0
45+
fi
46+
commits=$(echo "$markdown_commits" | sed -En "s/^/- /p")
47+
48+
if grep -q v$new_version "CHANGELOG.md"; then
49+
echo "CHANGELOG already contains version $new_version."
50+
exit 1
51+
fi
52+
53+
# Add a new version entry with the found commits to the CHANGELOG.md.
54+
echo "# ${new_version} \n\n ${commits}\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
55+
echo "CHANGELOG generated, validate entries here: $(pwd)/CHANGELOG.md"
56+
57+
echo "Creating git branch for ver_good_cli@$new_version"
58+
git checkout -b "chore/$new_version" > /dev/null
59+
60+
git add pubspec.yaml CHANGELOG.md
61+
62+
echo ""
63+
echo "Run the following command if you wish to commit the changes:"
64+
echo "git commit -m \"chore: v$new_version\""

tool/retag_v2.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# Updates the "v2" tag to point to a newer release.
4+
# To be executed whenever a new 1.x tag is created.
5+
# Usage: ./retag_v2.sh <newer-existing-version>
6+
7+
currentBranch=$(git symbolic-ref --short -q HEAD)
8+
if [[ ! $currentBranch == "main" ]]; then
9+
echo "Re-tagging is only supported on the main branch."
10+
exit 1
11+
fi
12+
13+
# Get new version
14+
new_version="$1";
15+
16+
if [[ "$new_version" == "" ]]; then
17+
echo "No new version supplied, please provide one"
18+
exit 1
19+
fi
20+
21+
git tag -d v2 && git tag v2 v$new_version && git push origin --delete v2 && git push origin v2

0 commit comments

Comments
 (0)