-
Notifications
You must be signed in to change notification settings - Fork 1
/
gh-pages-squash.sh
executable file
·61 lines (46 loc) · 1.49 KB
/
gh-pages-squash.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
#!/usr/bin/env bash
set -e
set -o pipefail
set -x
UPDATE_MODE=${UPDATE_MODE:-squash}
SCRIPT_NAME=$(basename $0)
case $UPDATE_MODE in
squash)
echo "$SCRIPT_NAME: executed with [UPDATE_MODE=$UPDATE_MODE]"
;;
*)
echo "$SCRIPT_NAME: skipping because invalid UPDATE_MODE value. Accepted values are 'squash'"
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 "[email protected]"
git config user.name "Slicer Bot"
pushURL=https://[email protected]/Slicer/apidocs.slicer.org
git config --add remote.origin.pushURL $pushURL
echo "$SCRIPT_NAME: added 'remote.origin.pushURL' with GITHUB_TOKEN"
TARGET_BRANCH=gh-pages
if [[ $UPDATE_MODE == "squash" ]]; then
git fetch origin $TARGET_BRANCH
git branch -D $TARGET_BRANCH || true
git checkout -b $TARGET_BRANCH FETCH_HEAD
first_commit=$(git rev-list --max-parents=0 HEAD)
git reset --soft $first_commit
git commit --amend -m "Slicer apidocs squashed
It was automatically generated by the script ``$SCRIPT_NAME`` [1]
[1] https://github.com/Slicer/apidocs.slicer.org/blob/main/$SCRIPT_NAME
"
git push origin $TARGET_BRANCH --force
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"