File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,32 +13,56 @@ set -eu
1313PAGES_BRANCH=" gh-pages"
1414
1515_no_branch=false
16+ _backup_dir=" $( mktemp -d) "
1617
17- if [[ -z $( git branch -av | grep " $PAGES_BRANCH " ) ]]; then
18- _no_branch=true
19- git checkout -b " $PAGES_BRANCH "
20- else
21- git checkout " $PAGES_BRANCH "
22- fi
18+ init () {
19+ if [[ -z $( git branch -av | grep " $PAGES_BRANCH " ) ]]; then
20+ _no_branch=true
21+ git checkout -b " $PAGES_BRANCH "
22+ else
23+ git checkout " $PAGES_BRANCH "
24+ fi
25+ }
2326
24- mv _site ../
25- mv .git ../
27+ backup () {
28+ mv _site " $_backup_dir "
29+ mv .git " $_backup_dir "
2630
27- rm -rf ./*
28- rm -rf .[^.] .??*
31+ # When adding custom domain from Github website,
32+ # the CANME only exist on `gh-pages` branch
33+ if [[ -f CNAME ]]; then
34+ mv CNAME " $_backup_dir "
35+ fi
36+ }
2937
30- mv ../_site/* .
31- mv ../.git .
38+ flush () {
39+ rm -rf ./*
40+ rm -rf .[^.] .??*
3241
33- git config --global user.name " GitHub Actions"
34- git config --global user.email " 41898282+github-actions[bot]@users.noreply.github.com"
42+ shopt -s dotglob nullglob
43+ mv " $_backup_dir " /* .
44+ }
3545
36- git update-ref -d HEAD
37- git add -A
38- git commit -m " [Automation] Site update No. ${GITHUB_RUN_NUMBER} "
46+ deoply () {
47+ git config --global user.name " GitHub Actions "
48+ git config --global user.email " 41898282+github-actions[bot]@users.noreply.github.com "
3949
40- if [[ $_no_branch = true ]]; then
41- git push -u origin $PAGES_BRANCH
42- else
43- git push -f
44- fi
50+ git update-ref -d HEAD
51+ git add -A
52+ git commit -m " [Automation] Site update No.${GITHUB_RUN_NUMBER} "
53+
54+ if [[ $_no_branch = true ]]; then
55+ git push -u origin " $PAGES_BRANCH "
56+ else
57+ git push -f
58+ fi
59+ }
60+
61+ main () {
62+ init
63+ backup
64+ flush
65+ deoply
66+ }
67+
68+ main
You can’t perform that action at this time.
0 commit comments