-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish.sh
More file actions
executable file
·150 lines (133 loc) · 4.69 KB
/
publish.sh
File metadata and controls
executable file
·150 lines (133 loc) · 4.69 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# ServerHub Release Publisher
# Bumps version and creates a new release tag
# Copyright (c) Nikolaos Protopapas. All rights reserved.
# Licensed under the MIT License.
set -e
# Parse arguments
BUMP_TYPE="patch"
FORCE=false
while [[ $# -gt 0 ]]; do
case $1 in
--force|-f)
FORCE=true
shift
;;
major|minor|patch)
BUMP_TYPE="$1"
shift
;;
*)
echo "Error: Invalid argument '$1'"
echo "Usage: $0 [major|minor|patch] [--force]"
echo ""
echo "Examples:"
echo " $0 # Bump patch version (default)"
echo " $0 patch # Bump patch version (1.0.0 -> 1.0.1)"
echo " $0 minor # Bump minor version (1.0.0 -> 1.1.0)"
echo " $0 major # Bump major version (1.0.0 -> 2.0.0)"
echo " $0 patch --force # Skip confirmation prompt"
exit 1
;;
esac
done
# Check for uncommitted changes
if ! git diff-index --quiet HEAD --; then
echo "Error: You have uncommitted changes. Commit or stash them first."
git status --short
exit 1
fi
# Check for unpushed commits
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
UPSTREAM_BRANCH=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "")
if [ -z "$UPSTREAM_BRANCH" ]; then
echo "Warning: No upstream branch configured for '$CURRENT_BRANCH'"
read -p "Continue anyway? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
else
LOCAL_COMMIT=$(git rev-parse HEAD)
REMOTE_COMMIT=$(git rev-parse "$UPSTREAM_BRANCH")
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
UNPUSHED=$(git log "$UPSTREAM_BRANCH..HEAD" --oneline 2>/dev/null | wc -l)
if [ "$UNPUSHED" -gt 0 ]; then
echo "Error: You have $UNPUSHED unpushed commit(s) on '$CURRENT_BRANCH'"
echo ""
git log "$UPSTREAM_BRANCH..HEAD" --oneline
echo ""
echo "Push your commits first: git push"
exit 1
fi
fi
fi
# Get latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Remove 'v' prefix and parse version
VERSION="${LATEST_TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Validate version format
if [[ ! "$MAJOR" =~ ^[0-9]+$ ]] || [[ ! "$MINOR" =~ ^[0-9]+$ ]] || [[ ! "$PATCH" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid version format in tag '$LATEST_TAG'"
echo "Expected format: v0.0.0"
exit 1
fi
# Bump version based on type
case "$BUMP_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
NEW_TAG="v$NEW_VERSION"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Creating new release: $NEW_TAG"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " Previous: $LATEST_TAG"
echo " New: $NEW_TAG"
echo " Type: $BUMP_TYPE"
echo ""
# Confirm
if [ "$FORCE" = false ]; then
read -p "Create and push tag '$NEW_TAG'? [y/N] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 0
fi
fi
# Create and push tag
echo ""
echo "Creating tag $NEW_TAG..."
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
echo "Pushing tag to origin..."
git push origin "$NEW_TAG"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✓ Release $NEW_TAG published!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "GitHub Actions will now:"
echo " 1. Build self-contained binaries (linux-x64, linux-arm64)"
echo " 2. Package widgets"
echo " 3. Create GitHub Release"
echo ""
echo "Watch progress at:"
echo " https://github.com/nickprotop/ServerHub/actions"
echo ""
echo "Release will be available at:"
echo " https://github.com/nickprotop/ServerHub/releases/tag/$NEW_TAG"