-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·86 lines (72 loc) · 2 KB
/
deploy.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
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
#!/bin/bash
# Set error handling
set -e
log_message() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Function to generate commit message based on git status
generate_commit_message() {
local changes=$(git status --short)
echo "sync changes: $(echo "$changes" | head -n 3 | sed 's/^/\n- /')"
}
# Change to the repository directory
cd "$HOME/repos/notes" || {
log_message "ERROR: Could not change to repository directory"
exit 1
}
# Activate virtual environment
if [ -z "$VIRTUAL_ENV" ]; then
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate || {
log_message "ERROR: Failed to activate virtual environment"
exit 1
}
log_message "Virtual environment activated"
else
log_message "ERROR: Virtual environment not found"
exit 1
fi
fi
# Check if git repository exists
if [ ! -d .git ]; then
log_message "ERROR: Not a git repository"
exit 1
fi
# Execute deployment steps
log_message "Starting deployment process"
# Run clean script
if ! python scripts/clean.py; then
log_message "ERROR: Clean script failed"
exit 1
fi
log_message "Clean script completed successfully"
# Run build script
if ! python scripts/build.py . site; then
log_message "ERROR: Build script failed"
exit 1
fi
log_message "Build script completed successfully"
# Check if there are any changes to commit
if [ -z "$(git status --porcelain)" ]; then
log_message "No changes to commit"
exit 0
fi
# Add all changes
if ! git add .; then
log_message "ERROR: Failed to stage changes"
exit 1
fi
# Generate commit message and commit
commit_message=$(generate_commit_message)
if ! git commit -m "$commit_message"; then
log_message "ERROR: Failed to commit changes"
exit 1
fi
log_message "Committed changes with message: $commit_message"
# Push changes
if ! git push; then
log_message "ERROR: Failed to push changes"
exit 1
fi
log_message "Successfully pushed changes"
log_message "Deployment completed successfully"