2
2
set -e
3
3
4
4
# REQUIRED ENVIRONMENT VARIABLES (for subprojects)
5
- github_workflow=$( echo " $GITHUB_WORKFLOW " | tr -d " '" )
6
- site_artifact=$( echo " $SITE_ARTIFACT " | tr -d " '" )
5
+ github_workflow=$( echo " ${ GITHUB_WORKFLOW:- } " | tr -d " '" )
6
+ site_artifact=$( echo " ${ SITE_ARTIFACT:- } " | tr -d " '" )
7
7
8
8
# OPTIONAL ENVIRONMENT VARIABLES (for subprojects)
9
- config_file=$( echo " $CONFIG_FILE " | tr -d " '" )
10
- extract_archive=$( echo " $EXTRACT_ARCHIVE " | tr -d " '" )
11
- github_timeout=$ GITHUB_TIMEOUT
12
- theme_ref=$ THEME_REF
9
+ config_file=$( echo " ${ CONFIG_FILE:- _config.yml} " | tr -d " '" )
10
+ extract_archive=$( echo " ${ EXTRACT_ARCHIVE:- } " | tr -d " '" )
11
+ github_timeout=" ${ GITHUB_TIMEOUT:- 10} "
12
+ theme_ref=" ${ THEME_REF:- master} "
13
13
14
14
# From ReadTheDocs
15
- git_sha=$READTHEDOCS_GIT_COMMIT_HASH
16
- github_url=$READTHEDOCS_GIT_CLONE_URL
15
+ git_sha=${ READTHEDOCS_GIT_COMMIT_HASH}
16
+ github_url=${ READTHEDOCS_GIT_CLONE_URL}
17
17
18
- if [[ $github_url == git@* ]]; then
18
+ if [[ ${ github_url} == git@* ]]; then
19
19
# SSH URL format: [email protected] :user/repo.git
20
- github_user=$( echo " $github_url " | cut -d: -f2 | cut -d/ -f1)
21
- github_repo=$( echo " $github_url " | cut -d/ -f2 | sed ' s/\.git$//' )
20
+ github_user=$( echo " ${ github_url} " | cut -d: -f2 | cut -d/ -f1)
21
+ github_repo=$( echo " ${ github_url} " | cut -d/ -f2 | sed ' s/\.git$//' )
22
22
else
23
23
# HTTPS URL format: https://github.com/user/repo
24
- github_user=$( echo " $github_url " | cut -d/ -f4)
25
- github_repo=$( echo " $github_url " | cut -d/ -f5 | sed ' s/\.git$//' )
24
+ github_user=$( echo " ${ github_url} " | cut -d/ -f4)
25
+ github_repo=$( echo " ${ github_url} " | cut -d/ -f5 | sed ' s/\.git$//' )
26
26
fi
27
27
28
28
export PAGES_REPO_NWO=" ${github_user} /${github_repo} "
29
29
30
- # if timeout is not set then default to 10 minutes
31
- if [ -z " $github_timeout " ]; then
32
- github_timeout=10
33
- fi
34
-
35
- # if config file is not set then default to _config.yml
36
- if [ -z " $config_file " ]; then
37
- config_file=" _config.yml"
38
- fi
39
-
40
- # if theme ref is not set then default to master
41
- if [ -z " $theme_ref " ]; then
42
- theme_ref=" master"
43
- fi
44
-
45
- echo " git sha: $git_sha "
46
- echo " github url: $github_url "
47
- echo " github user: $github_user "
48
- echo " github repo: $github_repo "
30
+ echo " git sha: ${git_sha} "
31
+ echo " github url: ${github_url} "
32
+ echo " github user: ${github_user} "
33
+ echo " github repo: ${github_repo} "
49
34
50
35
# set default directories
51
36
project_dir=" ."
52
37
theme_dir=" ."
53
38
54
39
# if not the theme project then we need to clone the theme with submodules
55
40
sub_project=" false"
56
- if [ " $READTHEDOCS_PROJECT " != " lizardbyte-gh-pages-main" ]; then
41
+ if [ " ${ READTHEDOCS_PROJECT} " != " lizardbyte-gh-pages-main" ]; then
57
42
sub_project=" true"
58
- echo " Building a subproject: $READTHEDOCS_PROJECT "
59
- echo " github workflow: $github_workflow "
60
- echo " site artifact: $site_artifact "
61
- echo " github timeout: $github_timeout "
62
- echo " extract archive: $extract_archive "
63
- echo " config file: $config_file "
64
- echo " theme ref: $theme_ref "
43
+ echo " Building a subproject: ${ READTHEDOCS_PROJECT} "
44
+ echo " github workflow: ${ github_workflow} "
45
+ echo " site artifact: ${ site_artifact} "
46
+ echo " github timeout: ${ github_timeout} "
47
+ echo " extract archive: ${ extract_archive} "
48
+ echo " config file: ${ config_file} "
49
+ echo " theme ref: ${ theme_ref} "
65
50
66
51
start_time=$( date +%s)
67
52
max_time=$(( start_time + 60 * github_timeout))
68
53
sleep_interval=10
69
54
70
55
# fail if the workflow is not set
71
- if [ -z " $github_workflow " ]; then
56
+ if [ -z " ${ github_workflow} " ]; then
72
57
echo " github_workflow is not set"
73
58
exit 1
74
59
fi
75
60
76
61
# fail if the site artifact is not set
77
- if [ -z " $site_artifact " ]; then
62
+ if [ -z " ${ site_artifact} " ]; then
78
63
echo " site_artifact is not set"
79
64
exit 1
80
65
fi
@@ -90,75 +75,75 @@ if [ "$READTHEDOCS_PROJECT" != "lizardbyte-gh-pages-main" ]; then
90
75
git submodule update --init --recursive
91
76
popd
92
77
93
- encoded_workflow=$( echo " $ github_workflow" | sed ' s/ /%20/g ' )
78
+ encoded_workflow=" ${ github_workflow// /% 20} "
94
79
check_api_url=" https://api.github.com/repos/${github_user} /${github_repo} /commits/${git_sha} /check-runs?check_name=${encoded_workflow} "
95
- echo " Check API URL: $check_api_url "
80
+ echo " Check API URL: ${ check_api_url} "
96
81
97
82
# Wait for check runs to be available
98
83
count=1
99
84
while true ; do
100
85
current_time=$( date +%s)
101
- if [ $ current_time -gt $max_time ]; then
86
+ if [ " ${ current_time} " -gt ${ max_time} ]; then
102
87
echo " Timeout waiting for check runs"
103
88
exit 1
104
89
fi
105
- echo " Checking check runs: $count "
90
+ echo " Checking check runs: ${ count} "
106
91
107
- response=$( curl -s -H " Accept: application/vnd.github.v3+json" " $check_api_url " )
108
- check_runs=$( echo " $response " | jq -r ' .check_runs' )
109
- check_run_count=$( echo " $check_runs " | jq -r ' length' )
92
+ response=$( curl -s -H " Accept: application/vnd.github.v3+json" " ${ check_api_url} " )
93
+ check_runs=$( echo " ${ response} " | jq -r ' .check_runs' )
94
+ check_run_count=$( echo " ${ check_runs} " | jq -r ' length' )
110
95
111
- echo " Check runs count: $check_run_count "
96
+ echo " Check runs count: ${ check_run_count} "
112
97
113
- if [ " $check_run_count " -gt 0 ]; then
114
- check_run=$( echo " $check_runs " | jq -r ' .[0]' )
115
- check_job_id=$( echo " $check_run " | jq -r ' .id' )
116
- check_run_html_url=$( echo " $check_run " | jq -r ' .html_url' )
117
- echo " Check job id: $check_job_id "
118
- echo " Check run URL: $check_run_html_url "
98
+ if [ " ${ check_run_count} " -gt 0 ]; then
99
+ check_run=$( echo " ${ check_runs} " | jq -r ' .[0]' )
100
+ check_job_id=$( echo " ${ check_run} " | jq -r ' .id' )
101
+ check_run_html_url=$( echo " ${ check_run} " | jq -r ' .html_url' )
102
+ echo " Check job id: ${ check_job_id} "
103
+ echo " Check run URL: ${ check_run_html_url} "
119
104
break
120
105
fi
121
106
122
107
echo " Waiting for check runs to be available..."
123
- sleep $sleep_interval
108
+ sleep ${ sleep_interval}
124
109
count=$(( count + 1 ))
125
110
done
126
111
127
112
# get the run id from the html url
128
113
# e.g. https://github.com/LizardByte/LizardByte.github.io/actions/runs/13687305039/job/38273540489
129
- check_run_id=$( echo " $check_run_html_url " | cut -d/ -f8)
130
- echo " Check run id: $check_run_id "
114
+ check_run_id=$( echo " ${ check_run_html_url} " | cut -d/ -f8)
115
+ echo " Check run id: ${ check_run_id} "
131
116
132
117
# wait for the check run to complete, cancelled, timed out, etc.
133
118
check_run_api_url=" https://api.github.com/repos/${github_user} /${github_repo} /actions/runs/${check_run_id} "
134
- echo " Check run API URL: $check_run_api_url "
119
+ echo " Check run API URL: ${ check_run_api_url} "
135
120
136
121
count=1
137
122
while true ; do
138
123
current_time=$( date +%s)
139
- if [ $ current_time -gt $max_time ]; then
124
+ if [ " ${ current_time} " -gt ${ max_time} ]; then
140
125
echo " Timeout waiting for check runs"
141
126
exit 1
142
127
fi
143
- echo " Checking check run status: $count "
128
+ echo " Checking check run status: ${ count} "
144
129
145
- check_run_response=$( curl -s -H " Accept: application/vnd.github.v3+json" " $check_run_api_url " )
130
+ check_run_response=$( curl -s -H " Accept: application/vnd.github.v3+json" " ${ check_run_api_url} " )
146
131
147
- check_run_status=$( echo " $check_run_response " | jq -r ' .status' )
148
- check_run_conclusion=$( echo " $check_run_response " | jq -r ' .conclusion' )
132
+ check_run_status=$( echo " ${ check_run_response} " | jq -r ' .status' )
133
+ check_run_conclusion=$( echo " ${ check_run_response} " | jq -r ' .conclusion' )
149
134
150
- echo " Check run status: $check_run_status "
151
- if [ " $check_run_status " == " completed" ]; then
135
+ echo " Check run status: ${ check_run_status} "
136
+ if [ " ${ check_run_status} " == " completed" ]; then
152
137
break
153
138
fi
154
139
155
140
echo " Waiting for check run to complete..."
156
- sleep $sleep_interval
141
+ sleep ${ sleep_interval}
157
142
count=$(( count + 1 ))
158
143
done
159
144
160
145
# if not successful then exit
161
- if [ " $check_run_conclusion " != " success" ]; then
146
+ if [ " ${ check_run_conclusion} " != " success" ]; then
162
147
echo " Check run did not complete successfully"
163
148
exit 1
164
149
fi
@@ -167,29 +152,29 @@ if [ "$READTHEDOCS_PROJECT" != "lizardbyte-gh-pages-main" ]; then
167
152
artifact_url=" https://nightly.link/${github_user} /${github_repo} /actions/runs/${check_run_id} /${site_artifact} "
168
153
169
154
# download and extract the ZIP artifact
170
- curl -sL " $artifact_url " -o " ${project_dir} /artifact.zip"
155
+ curl -sL " ${ artifact_url} " -o " ${project_dir} /artifact.zip"
171
156
7z x " ${project_dir} /artifact.zip" -o" ${project_dir} "
172
157
rm " ${project_dir} /artifact.zip"
173
158
174
159
# if there is a name provided for extract_artifact, then we will extract the nested archive
175
- if [ -n " $extract_archive " ]; then
160
+ if [ -n " ${ extract_archive} " ]; then
176
161
pushd " ${project_dir} "
177
- case " $extract_archive " in
162
+ case " ${ extract_archive} " in
178
163
* .tar.gz|* .tgz)
179
- tar -xzf " $extract_archive " -C .
164
+ tar -xzf " ${ extract_archive} " -C .
180
165
;;
181
166
* .tar)
182
- tar -xf " $extract_archive " -C .
167
+ tar -xf " ${ extract_archive} " -C .
183
168
;;
184
169
* .zip)
185
- 7z x " $extract_archive " -o.
170
+ 7z x " ${ extract_archive} " -o.
186
171
;;
187
172
* )
188
173
echo " Unsupported archive format"
189
174
exit 1
190
175
;;
191
176
esac
192
- rm -f " $extract_archive "
177
+ rm -f " ${ extract_archive} "
193
178
popd
194
179
fi
195
180
fi
@@ -220,8 +205,8 @@ targets=(
220
205
221
206
for base_dir in " ${base_dirs[@]} " ; do
222
207
for target in " ${targets[@]} " ; do
223
- if [ -e " $base_dir / $ target" ]; then
224
- cp -rf " $base_dir / $ target" " ${TMPDIR} /"
208
+ if [ -e " ${ base_dir} / ${ target} " ]; then
209
+ cp -rf " ${ base_dir} / ${ target} " " ${TMPDIR} /"
225
210
fi
226
211
done
227
212
done
@@ -233,31 +218,31 @@ cd "${TMPDIR}"
233
218
234
219
gem install bundle
235
220
bundle install
236
- echo " baseurl: $READTHEDOCS_VERSION " > _config_rtd.yml
221
+ echo " baseurl: ${ READTHEDOCS_VERSION} " > _config_rtd.yml
237
222
echo " _config_rtd.yml:"
238
223
cat _config_rtd.yml
239
224
echo " _config_theme.yml:"
240
225
cat _config_theme.yml
241
226
242
227
config_files=_config_rtd.yml,_config_theme.yml
243
- if [ -n " $config_file " ] && [ -e " $config_file " ]; then
244
- config_files=" ${config_files} ,$config_file "
245
- echo " config file: $config_file "
246
- cat " $config_file "
228
+ if [ -n " ${ config_file} " ] && [ -e " ${ config_file} " ]; then
229
+ config_files=" ${config_files} ,${ config_file} "
230
+ echo " config file: ${ config_file} "
231
+ cat " ${ config_file} "
247
232
fi
248
233
249
234
bundle exec jekyll build \
250
235
--future \
251
- --config $ config_files \
236
+ --config " ${ config_files} " \
252
237
--destination " ${READTHEDOCS_OUTPUT} html"
253
238
254
239
# mimic gh-pages
255
- if [ " $sub_project " == " true" ]; then
240
+ if [ " ${ sub_project} " == " true" ]; then
256
241
mkdir -p " ${READTHEDOCS_OUTPUT} html/${github_repo} /assets"
257
242
cp -RTf " ${READTHEDOCS_OUTPUT} html/assets" " ${READTHEDOCS_OUTPUT} html/${github_repo} /assets"
258
243
fi
259
244
260
245
echo " Build finished"
261
246
echo " Output directory: ${READTHEDOCS_OUTPUT} html"
262
247
echo " Listing output directory:"
263
- ls -Ra " $READTHEDOCS_OUTPUT "
248
+ ls -Ra " ${ READTHEDOCS_OUTPUT} "
0 commit comments