-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·105 lines (77 loc) · 2.17 KB
/
entrypoint.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash -l
# Exit when any command fails
set -e
# Keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# Trap right before exiting
trap 'catch $? $LINENO' EXIT
catch() {
# If last exit code was erroneous
if [ "$1" != "0" ]; then
echo "${last_command} command failed with exit code $1."
fi
}
# Check whether the current working tree is the same as what git is tracking
# Put in function so doesn't activate traps
check_is_same() {
git --no-pager diff --exit-code --quiet
echo $?
return
}
#Setup git username/password
git config --global user.email "[email protected]"
git config --global user.name "Github-Action"
# Setup repo workspace
mkdir -p repo
cd repo
# If SSH key not set, use token
if [ -z "$2" ]
then
#Add extra http header telling Github what our auth token is
git config --global http.https://github.com/.extraheader "$3"
# Clone using HTTPS
git clone https://GithubAction:[email protected]/$1.git .
else
# SSH key set so use it
# Setup SSH
mkdir -p ~/.ssh -m 700
echo $2 > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
#echo "SSH ID:"
#cat ~/.ssh/id_rsa
eval "$(ssh-agent)"
ssh-add ~/.ssh/id_rsa
ssh-add -l -E sha256
# Clone using SSH
git clone [email protected]:$1 .
fi
# Debug info about repo contents
echo "Contents:"
ls -al
# Create build dir outside repo and cd to it
mkdir -p ../build
cd ../build
# Build docs, assuming the CMakeLists.txt is using CMinx
cmake ../repo -DBUILD_DOCS=ON
make docs
# rsync built docs into repo
cd ../repo
git checkout $5 #Checkout selected docs branch
rsync -a ../build/docs/html/* ./
# If working directory is different from git's tracking
if [ ! "$(check_is_same)" -eq 0 ]
then
echo "Github Pages needs updating."
# Add working tree to index, log status
git add .
git status
echo "Should we push? $4"
if [[ $4 =~ y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON ]]
then
# DANGER AREA!
# These commands modify the repo.
echo "Pushing..."
git commit -m "[Bot] Update gh-pages"
git push
fi
fi