Skip to content

Commit 1a5b5b0

Browse files
committed
Add small release script to help me out next time
Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com>
1 parent 5643cfd commit 1a5b5b0

1 file changed

Lines changed: 115 additions & 0 deletions

File tree

scripts/release.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Parse arguments
6+
DRY_RUN=false
7+
VERSION=""
8+
9+
while [[ $# -gt 0 ]]; do
10+
case $1 in
11+
--dry-run)
12+
DRY_RUN=true
13+
shift
14+
;;
15+
*)
16+
VERSION=$1
17+
shift
18+
;;
19+
esac
20+
done
21+
22+
if [[ "$VERSION" == v* ]]; then
23+
echo "Error: Version should not start with 'v'. Please provide version like '1.2.3' instead of 'v1.2.3'."
24+
exit 1
25+
fi
26+
27+
if [ -z "$VERSION" ]; then
28+
echo "Usage: $0 [--dry-run] <version>"
29+
echo ""
30+
echo "Options:"
31+
echo " --dry-run Show what would be done without making any changes"
32+
exit 1
33+
fi
34+
35+
MAJOR_VERSION=$(echo "$VERSION" | cut -d. -f1)
36+
37+
if [ "$DRY_RUN" = true ]; then
38+
echo "=== DRY RUN MODE ==="
39+
echo "No changes will be made to files or git repository"
40+
echo ""
41+
fi
42+
43+
# --- Update CHANGELOG.md ---
44+
CHANGELOG_FILE="CHANGELOG.md"
45+
REPO_URL="https://github.com/douglascamata/setup-docker-macos-action"
46+
# Get the previous version from the [Unreleased] link in the changelog.
47+
PREVIOUS_VERSION=$(grep '\[Unreleased\]:' "$CHANGELOG_FILE" | sed -E 's/.*compare\/(.*)\.\.\.HEAD/\1/')
48+
CURRENT_DATE=$(date +%Y-%m-%d)
49+
50+
if [ "$DRY_RUN" = true ]; then
51+
echo "[DRY RUN] Would update CHANGELOG.md:"
52+
echo " - Current version: $PREVIOUS_VERSION"
53+
echo " - New version: v$VERSION"
54+
echo " - Date: $CURRENT_DATE"
55+
echo " - Would add: ## [v$VERSION] - $CURRENT_DATE"
56+
echo " - Would update [Unreleased] link to compare from v$VERSION"
57+
echo " - Would add [v$VERSION] link: $REPO_URL/compare/$PREVIOUS_VERSION...v$VERSION"
58+
else
59+
echo "Updating CHANGELOG.md for new version v$VERSION..."
60+
61+
# Use awk to update the changelog in place.
62+
# It's more robust and readable than sed for this task.
63+
awk \
64+
-v version="v$VERSION" \
65+
-v date="$CURRENT_DATE" \
66+
-v previous_version="$PREVIOUS_VERSION" \
67+
-v repo_url="$REPO_URL" \
68+
'
69+
# Find the "Unreleased" header and add the new version header below it.
70+
/## \[Unreleased\]/ {
71+
print "## [Unreleased]"
72+
print ""
73+
printf("## [%s] - %s\n", version, date)
74+
next
75+
}
76+
# Find the "Unreleased" link definition at the bottom of the file.
77+
/\[Unreleased\]:/ {
78+
# Update the "Unreleased" link to compare from the new version to HEAD.
79+
sub(previous_version "...", version "...")
80+
print
81+
# Add the link definition for the new version, comparing the last two versions.
82+
printf("[%s]: %s/compare/%s...%s\n", version, repo_url, previous_version, version)
83+
next
84+
}
85+
# Print all other lines as-is.
86+
{ print }
87+
' "$CHANGELOG_FILE" > "$CHANGELOG_FILE.tmp" && mv "$CHANGELOG_FILE.tmp" "$CHANGELOG_FILE"
88+
89+
echo "CHANGELOG.md has been updated."
90+
echo "Please review the changes before proceeding."
91+
read -p "Proceed with commit? (y/n) " -n 1 -r
92+
git add "$CHANGELOG_FILE"
93+
git commit -m "Prepare changelog for v$VERSION"
94+
fi
95+
echo
96+
97+
# --- Tagging ---
98+
if [ "$DRY_RUN" = true ]; then
99+
echo "[DRY RUN] Would create the following tags:"
100+
echo " - v$VERSION"
101+
echo " - v$MAJOR_VERSION (force update)"
102+
echo "[DRY RUN] Would push tags to remote"
103+
else
104+
echo "The following tags will be created: v$VERSION, v$MAJOR_VERSION"
105+
echo "The tags will NOT be pushed automatically."
106+
read -p "Are you sure? (y/n) " -n 1 -r
107+
echo
108+
if [[ $REPLY =~ ^[Yy]$ ]]
109+
then
110+
git tag "v$VERSION"
111+
git tag -f "v$MAJOR_VERSION"
112+
echo "Tags v$VERSION, v$MAJOR_VERSION prepared. Don't forget to review tags and commits before pushing them."
113+
echo "You can push the tags with: git push --tags -f"
114+
fi
115+
fi

0 commit comments

Comments
 (0)