File tree Expand file tree Collapse file tree 2 files changed +75
-10
lines changed
Expand file tree Collapse file tree 2 files changed +75
-10
lines changed Original file line number Diff line number Diff line change @@ -45,16 +45,29 @@ if [[ -z "$current_version" ]]; then
4545fi
4646
4747DRY_RUN=false
48- if [[ " ${1-} " == " --dry-run" ]]; then
49- DRY_RUN=true
50- shift
51- fi
52-
53- # Allow --dry-run --help to show usage
54- if [[ " ${1-} " == " -h" || " ${1-} " == " --help" ]]; then
55- usage
56- exit 0
57- fi
48+ while [[ $# -gt 0 ]]; do
49+ case " $1 " in
50+ --dry-run)
51+ DRY_RUN=true
52+ shift
53+ ;;
54+ -h|--help)
55+ usage
56+ exit 0
57+ ;;
58+ --)
59+ shift
60+ break
61+ ;;
62+ -* )
63+ usage
64+ exit 1
65+ ;;
66+ * )
67+ break
68+ ;;
69+ esac
70+ done
5871
5972if [[ $# -gt 1 ]]; then
6073 usage
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ usage () {
5+ cat << 'EOF '
6+ Usage: tools/tag-release.sh <version>
7+
8+ Creates an annotated git tag "v<version>".
9+
10+ Requirements:
11+ - Clean working tree (no staged/unstaged/untracked changes)
12+ - Tag must not already exist
13+
14+ Examples:
15+ tools/tag-release.sh 0.9.1
16+ EOF
17+ }
18+
19+ require_bin () {
20+ if ! command -v " $1 " > /dev/null 2>&1 ; then
21+ echo " error: $1 is required" >&2
22+ exit 1
23+ fi
24+ }
25+
26+ if [[ " ${1-} " == " -h" || " ${1-} " == " --help" || $# -ne 1 ]]; then
27+ usage
28+ exit 0
29+ fi
30+
31+ require_bin git
32+
33+ version=" $1 "
34+ tag=" v${version} "
35+
36+ if ! [[ " $version " =~ ^[0-9]+\. [0-9]+\. [0-9]+$ ]]; then
37+ echo " error: invalid version format: $version (expected MAJOR.MINOR.PATCH)" >&2
38+ exit 1
39+ fi
40+
41+ if [[ -n " $( git status --porcelain --untracked-files=all) " ]]; then
42+ echo " error: working tree is not clean; commit/stash changes before tagging" >&2
43+ exit 1
44+ fi
45+
46+ if git rev-parse -q --verify " refs/tags/${tag} " > /dev/null; then
47+ echo " error: tag ${tag} already exists" >&2
48+ exit 1
49+ fi
50+
51+ git tag -a " ${tag} " -m " Release ${tag} "
52+ echo " Created tag ${tag} "
You can’t perform that action at this time.
0 commit comments