-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump-version
More file actions
executable file
·121 lines (102 loc) · 3.65 KB
/
bump-version
File metadata and controls
executable file
·121 lines (102 loc) · 3.65 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
set -e
# Purpose: Bump version, create git tag, and optionally push to remotes
# Usage: ./bump-version <new-version> [--push]
# Example: ./bump-version 1.0.5
# ./bump-version 1.0.5 --push
#
# This script:
# 1. Updates the VERSION file
# 2. Updates the spec file Version: line
# 3. Updates debian/changelog (if dch is available)
# 4. Commits the changes
# 5. Creates a git tag (vX.Y.Z format)
# 6. (with --push) Pushes commits and tags to origin and github
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
VERSION_FILE="$SCRIPT_DIR/VERSION"
SPEC_FILE="$SCRIPT_DIR/ionis-apps.spec"
DEB_CHANGELOG="$SCRIPT_DIR/debian/changelog"
usage() {
printf "Usage: %s <new-version> [--push]\n" "$(basename "$0")"
printf "\n"
printf "Options:\n"
printf " <new-version> Version in X.Y.Z format (e.g., 1.0.5)\n"
printf " --push Push commits and tags to origin and github\n"
printf "\n"
printf "Examples:\n"
printf " %s 1.0.5 # Bump version only\n" "$(basename "$0")"
printf " %s 1.0.5 --push # Bump version and push to remotes\n" "$(basename "$0")"
printf "\n"
printf "Current version: %s\n" "$(cat "$VERSION_FILE" 2>/dev/null || echo 'unknown')"
}
# Parse arguments
NEW_VERSION=""
DO_PUSH=false
for arg in "$@"; do
case "$arg" in
--push|-p)
DO_PUSH=true
;;
--help|-h)
usage
exit 0
;;
*)
if [[ -z "$NEW_VERSION" ]]; then
NEW_VERSION="$arg"
else
printf "Error: Unexpected argument '%s'\n" "$arg" >&2
usage
exit 1
fi
;;
esac
done
if [[ -z "$NEW_VERSION" ]]; then
usage
exit 1
fi
# Validate version format (X.Y.Z)
if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
printf "Error: Version must be in X.Y.Z format (e.g., 1.0.5)\n" >&2
exit 1
fi
# Update VERSION file
printf "%s\n" "$NEW_VERSION" > "$VERSION_FILE"
printf "Updated VERSION to %s\n" "$NEW_VERSION"
# Update spec file Version: line
if [[ -f "$SPEC_FILE" ]]; then
sed -i "s/^Version:.*$/Version: ${NEW_VERSION}/" "$SPEC_FILE"
printf "Updated spec file to %s\n" "$NEW_VERSION"
fi
# Update debian/changelog (if dch is available)
if command -v dch >/dev/null 2>&1 && [[ -f "$DEB_CHANGELOG" ]]; then
dch -v "${NEW_VERSION}-1" -D noble "New upstream release ${NEW_VERSION}"
printf "Updated debian/changelog to %s-1\n" "$NEW_VERSION"
fi
# Stage and commit
git add "$VERSION_FILE" "$SPEC_FILE"
[[ -f "$DEB_CHANGELOG" ]] && git add "$DEB_CHANGELOG"
git commit -m "v${NEW_VERSION}: version bump"
# Create tag
git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}"
printf "\nVersion bump complete!\n"
printf " VERSION file: %s\n" "$NEW_VERSION"
printf " Spec file: %s\n" "$NEW_VERSION"
printf " Git tag: v%s\n" "$NEW_VERSION"
# Push if requested
if [[ "$DO_PUSH" == true ]]; then
printf "\nPushing to remotes...\n"
printf " Pushing to origin main... "
git push origin main && printf "OK\n" || { printf "FAILED\n"; exit 1; }
printf " Pushing to github main... "
git push github main && printf "OK\n" || { printf "FAILED\n"; exit 1; }
printf " Pushing tags to origin... "
git push origin --tags && printf "OK\n" || { printf "FAILED\n"; exit 1; }
printf " Pushing tags to github... "
git push github --tags && printf "OK\n" || { printf "FAILED\n"; exit 1; }
printf "\nRelease v%s pushed to both remotes!\n" "$NEW_VERSION"
else
printf "\nTo push: git push origin main && git push github main && git push --tags\n"
printf "Or run: %s %s --push\n" "$(basename "$0")" "$NEW_VERSION"
fi