-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·73 lines (57 loc) · 2.21 KB
/
release.sh
File metadata and controls
executable file
·73 lines (57 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# Release script to create tags and manage Caddy module releases.
# This script follows semantic versioning and interacts with GitHub.
# It requires git, gh, and brew to be installed.
set -o nounset # Exit on unset variable
set -o errexit # Exit on error
set -o errtrace # Trace errors through functions
set -o pipefail # Catch errors in pipelines
#set -o xtrace # Enable command tracing (for debugging)
# Function to check if required commands are installed
check_command() {
if ! command -v "$1" >/dev/null; then
echo "Error: The \"$1\" command must be installed." >&2
exit 1
fi
}
# Check for required commands
for cmd in git gh brew; do
check_command "$cmd"
done
# Check if version argument is provided
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <version>" >&2
exit 1
fi
# Validate the provided version using semver regex
version_regex='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$'
if [[ ! $1 =~ $version_regex ]]; then
echo "Invalid version number: $1. Please follow semantic versioning (e.g., 1.2.3)." >&2
exit 1
fi
# Define version from argument
VERSION="$1"
# Ensure we are on the 'main' branch
echo "Switching to 'main' branch..."
git checkout main
git pull
# Commit changes (if any) and prepare for release
echo "Committing changes for version $VERSION..."
git commit -S -a -m "chore: prepare release $VERSION" || echo "No changes to commit."
# Create and sign the tag
echo "Creating tag $VERSION..."
git tag -s -m "Version $VERSION" "$VERSION"
# Push tags to remote
echo "Pushing tag $VERSION to remote..."
git push --follow-tags
# Get the previous tag based on semantic versioning
tags=$(git tag --list --sort=-version:refname '[0-9]*\.[0-9]*\.[0-9]*')
previous_tag=$(awk 'NR==2 {print; exit}' <<<"${tags}")
if [[ -z "$previous_tag" ]]; then
echo "Error: Unable to find a previous tag." >&2
exit 1
fi
# Create a new GitHub release with the generated notes
echo "Creating GitHub release for $VERSION..."
gh release create --generate-notes --latest --notes-start-tag "${previous_tag}" --verify-tag "$VERSION"
echo "Release $VERSION created successfully."