-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrelease_github.sh
executable file
·54 lines (41 loc) · 1.34 KB
/
release_github.sh
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
#!/bin/bash
# Exit on error
set -e
# Check if required commands are installed
if ! command -v mvn &> /dev/null; then
echo "Error: Maven (mvn) is not installed."
exit 1
fi
if ! command -v gh &> /dev/null; then
echo "Error: GitHub CLI (gh) is not installed."
exit 1
fi
# Get the version from Maven
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
# Ensure version is not empty
if [[ -z "$VERSION" ]]; then
echo "Error: Failed to retrieve project version."
exit 1
fi
# Check if the release already exists on GitHub
if gh release view "$VERSION" &> /dev/null; then
echo "Release $VERSION already exists. Deleting..."
gh release delete "$VERSION" --yes
fi
# Check if the tag exists locally
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Tag $VERSION exists locally."
# Check if the tag exists on GitHub
if git ls-remote --tags origin | grep -q "refs/tags/$VERSION"; then
echo "Tag $VERSION exists on GitHub. Deleting..."
git push --delete origin "$VERSION"
fi
echo "Recreating tag $VERSION..."
git tag -d "$VERSION"
fi
# Create and push the tag again
git tag "$VERSION"
git push origin "$VERSION"
# Create a new release
gh release create "$VERSION" --title "Version $VERSION" --notes "New Version Release"
echo "GitHub release $VERSION created successfully!"