-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-deploy
More file actions
executable file
·116 lines (100 loc) · 2.42 KB
/
git-deploy
File metadata and controls
executable file
·116 lines (100 loc) · 2.42 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
#!/bin/sh
# File: git-pub
# Function to prompt for input
prompt() {
local var_name=$1
local prompt_text=$2
local input
while true; do
# Use `readline` to enable navigation with arrow keys
read -e -p "$prompt_text: " input
if [ -n "$input" ]; then
eval "$var_name=\"$input\""
break
else
echo "Error: the field cannot be empty."
fi
done
}
# Function to prompt for optional input
prompt_optional() {
local var_name=$1
local prompt_text=$2
local input
# Use `readline` to enable navigation with arrow keys
read -e -p "$prompt_text (Press enter to skip): " input
eval "$var_name=\"$input\""
}
# Function to convert input to uppercase
to_uppercase() {
echo "$1" | tr '[:lower:]' '[:upper:]'
}
# Prompt for the commit type
prompt COMMIT_TYPE "Enter the commit type (FIX, UPDATE, ADD, PARTIAL)"
COMMIT_TYPE=$(to_uppercase "$COMMIT_TYPE")
# Prompt for the task number (optional)
prompt_optional TASK_NUMBER "Enter the task number (if present)"
# Prompt for the commit title
prompt COMMIT_TITLE "Enter the commit title"
# Prompt for the commit body (optional)
prompt_optional COMMIT_BODY "Enter the commit body"
# Mapping of icons for each commit type
get_icon() {
case $1 in
FIX) echo "🔧";;
UPDATE) echo "🔄";;
ADD) echo "➕";;
PARTIAL) echo "✳️";;
*) echo ""; # Default empty if no match
esac
}
ICON=$(get_icon "$COMMIT_TYPE")
# Detect package manager
if [ -f "yarn.lock" ]; then
PM="yarn"
elif [ -f "package-lock.json" ]; then
PM="npm"
else
echo "Error: No yarn.lock or package-lock.json found to determine package manager."
exit 1
fi
# Install dependencies
if [ "$PM" = "yarn" ]; then
if ! yarn install; then
echo "Yarn install failed"
exit 1
fi
else
if ! npm install; then
echo "NPM install failed"
exit 1
fi
fi
# Build project
if [ "$PM" = "yarn" ]; then
if ! yarn build; then
echo "Yarn build failed"
exit 1
fi
else
if ! npm run build; then
echo "NPM build failed"
exit 1
fi
fi
# Execute git add and check the result
if ! git add .; then
echo "Git add failed"
exit 1
fi
# Execute git commit with the formatted message and check the result
if ! git commit -m "[$COMMIT_TYPE] $ICON | $TASK_NUMBER $COMMIT_TITLE" -m "$COMMIT_BODY" -m "DEPLOY"; then
echo "Git commit failed"
exit 1
fi
# Execute git push and check the result
if ! git push; then
echo "Git push failed"
exit 1
fi
echo "Push successful"