-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha.cli
executable file
·114 lines (89 loc) · 2.7 KB
/
a.cli
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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# setup hooks
setup() {
for i in commit checkout merge; do
cp hooks/post-commit .git/hooks/post-$i
chmod +x .git/hooks/post-$i
done
echo "Hooks setup successfully."
git checkout
if ! test -f .git/gitHeadInfo.gin; then
cp .git/gitHeadInfo.gin gitHeadLocal.gin
git add gitHeadLocal.gin
git commit -m "Created gitHeadLocal.gin for initial setup"
fi
}
# Function to create a release
create_release() {
VERSION=$1
if [ -z "$VERSION" ]; then
echo "Usage: $0 create vx.y.z"
exit 1
fi
# check if the tag already exists
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Error: Tag $VERSION already exists."
exit 1
fi
# check the format of the version number
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?$ ]]; then
echo "Error: Version number should be in the format vx.y.z or vx.y.z-pre.a."
exit 1
fi
# Tag the repository with the provided version
git tag -a "$VERSION" -m "Release $VERSION"
# Checkout the tag to trigger post-commit hook to update gitinfo2 info file
git checkout
# show the reltag line of .git/gitHeadInfo.gin
grep reltag .git/gitHeadInfo.gin
cp .git/gitHeadInfo.gin gitHeadLocal.gin
git add gitHeadLocal.gin
git commit -m "Updated gitHeadLocal.gin for release $VERSION"
git tag -f -a "$VERSION" -m "Release $VERSION"
# Push the changes and the tags
git push origin main --follow-tags
echo "Release $VERSION created and pushed successfully."
}
# Function to list releases
list_releases() {
git tag --sort=-creatordate | head -n $1
}
# Function to delete a release
delete_release() {
VERSION=$1
if [ -z "$VERSION" ]; then
echo "Usage: $0 delete vx.y.z"
exit 1
fi
# Delete the tag locally
git tag -d "$VERSION"
# Delete the tag remotely
#git push origin --delete "$VERSION"
echo "Release $VERSION deleted successfully."
}
# Main script logic
case "$1" in
setup)
setup
;;
create)
create_release "$2"
;;
list)
list_releases "${2:-5}"
;;
delete)
delete_release "$2"
;;
*)
echo "Usage: $0 {setup|create|list|delete} [version]"
echo " setup : Setup hooks for commit, checkout, and merge"
echo " create : Create a new release with the provided version"
echo " list : List all existing releases"
echo " delete : Delete the release with the provided version"
echo " version : Optional argument specifying the version for create and delete commands"
exit 1
;;
esac