-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-pages-reset.sh
executable file
·67 lines (52 loc) · 1.65 KB
/
gh-pages-reset.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
#!/usr/bin/env bash
set -e
set -o pipefail
set -x
UPDATE_MODE=${UPDATE_MODE:-reset}
SCRIPT_NAME=$(basename $0)
case $UPDATE_MODE in
reset)
echo "$SCRIPT_NAME: executed with [UPDATE_MODE=$UPDATE_MODE]"
;;
merge)
echo "$SCRIPT_NAME: executed with [UPDATE_MODE=$UPDATE_MODE]"
;;
*)
echo "$SCRIPT_NAME: skipping because invalid UPDATE_MODE value. Accepted values are 'reset' or 'merge'"
exit 1
;;
esac
if [[ -z $GITHUB_TOKEN ]]; then
echo "$SCRIPT_NAME: skipping because GITHUB_TOKEN env. variable is not set"
exit 1
fi
git config user.email "slicerbot@slicer.org"
git config user.name "Slicer Bot"
pushURL=https://$GITHUB_TOKEN@github.com/Slicer/preview.apidocs.slicer.org
git config --add remote.origin.pushURL $pushURL
echo "$SCRIPT_NAME: added 'remote.origin.pushURL' with GITHUB_TOKEN"
SOURCE_BRANCH=gh-pages-reset
TARGET_BRANCH=gh-pages
if [[ $UPDATE_MODE == "reset" ]]; then
git checkout main
git fetch origin $SOURCE_BRANCH
git branch -D $SOURCE_BRANCH || true
git checkout -b $SOURCE_BRANCH FETCH_HEAD
git push origin $SOURCE_BRANCH:$TARGET_BRANCH --force
push_exit_code=$?
elif [[ $UPDATE_MODE == "merge" ]]; then
git checkout main
git fetch origin +refs/heads/*:refs/remotes/origin/*
git checkout -b $TARGET_BRANCH origin/$TARGET_BRANCH
git merge origin/$SOURCE_BRANCH --log --no-ff
git push origin $TARGET_BRANCH:$TARGET_BRANCH
push_exit_code=$?
else
echo "$SCRIPT_NAME: skipping because invalid UPDATE_MODE [$UPDATE_MODE]"
exit 1
fi
if [[ ! $push_exit_code -eq 0 ]]; then
echo "$SCRIPT_NAME: skipping because push command failed"
exit $push_exit_code
fi
echo "$SCRIPT_NAME: $TARGET_BRANCH successfully $UPDATE_MODE"