-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
53 lines (44 loc) · 1.49 KB
/
release.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
# This script creates a tag for the repository and pushes it to the remote
# repository. The remote repository is configured to trigger a GitHub Actions
# workflow when a new tag is pushed, which will create a release on GitHub
# using the tag.
# Usage: ./release <version-number> ["Optional tag commit message"]
# Check for the correct number of input parameters
if [ "$#" -lt 1 ]; then
echo "Error: Incorrect number of arguments."
echo "Usage: $0 <version-number> [\"tag commit message\"]"
echo "Example: $0 v1.0.1 \"Initial release\""
exit 1
fi
# Define the tag
TAG="release_$1"
# Check if the tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Error: Tag $TAG already exists."
# Ask user if they want to replace the existing tag
read -p "Do you want to replace the existing tag? (y/n) " answer
case $answer in
[Yy]* )
# Delete the tag locally
git tag -d "$TAG"
# Delete the tag from the remote
git push origin --delete "$TAG"
;;
* )
echo "Operation aborted."
exit 1
;;
esac
fi
# Create the annotated tag
if [ -z "$2" ]; then
# If no message is provided, open the editor to allow the user to enter a message
git tag -a "$TAG"
else
# If a message is provided, use it directly
git tag -a "$TAG" -m "$2"
fi
# Push the tag to the remote repository
git push origin "$TAG"
echo "Tag $TAG created and pushed successfully."