-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.sh
executable file
·81 lines (62 loc) · 1.42 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
#!/usr/bin/env bash
# ref: https://github.com/jekyll/jekyll
set -eu # Exit on error or unset variable
PAGES_BRANCH="gh-pages"
SITE_DIR="_output"
_backup_dir="$(mktemp -d)"
init() {
# Check if the script is running in a GitHub Actions environment
if [[ -z ${GITHUB_ACTION+x} ]]; then
echo "ERROR: Not allowed to deploy outside of the GitHub Action environment."
exit 1
fi
}
build() {
# clean
if [[ -d $SITE_DIR ]]; then
rm -rf "$SITE_DIR"
fi
# Run the Ruby script to generate the output
bundle exec ruby "./scaffold.rb"
}
setup_gh() {
if [[ -z $(git branch -av | grep "$PAGES_BRANCH") ]]; then
git checkout -b "$PAGES_BRANCH"
else
git checkout "$PAGES_BRANCH"
fi
}
backup() {
mv "$SITE_DIR"/* "$_backup_dir"
mv .git "$_backup_dir"
if [[ -f CNAME ]]; then
mv CNAME "$_backup_dir"
fi
}
flush() {
rm -rf ./*
rm -rf .[^.] .??*
shopt -s dotglob nullglob
mv "$_backup_dir"/* .
}
deploy() {
# Configure Git user for the commit
git config --global user.name "ZhgChgLiBot"
git config --global user.email "[email protected]"
# Reset the current HEAD to prepare for new commits
git update-ref -d HEAD
git add -A
git commit -m "[Automation] Site update No.${GITHUB_RUN_NUMBER}"
# Push the new branch to the remote repository
git push -u origin "$PAGES_BRANCH" --force
}
main() {
init
build
setup_gh
backup
flush
deploy
}
# Execute the main function
main