Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
hugo: circleci/hugo@1.4.0
Use hugo
elements in your existing workflows and jobs.
"An example of building a Hugo site, testing with HTML Proofer, and deployng it. Here the Hugo source is in a subdirectory called 'src'. The deploy job is empty and serves as an example. Instead of the 'ls' command, you'd want to deploy the files using whatever tools you're used to."
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
version: '2.1'
orbs:
hugo: circleci/hugo@1.3.1
jobs:
deploy:
docker:
- image: cimg/base
steps:
- attach_workspace:
at: my-site
- run: ls -lah my-site
workflows:
main:
jobs:
- hugo/build:
html-proofer: true
source: src/
version: 0.141.0
- deploy:
filters:
branches:
only: master
requires:
- hugo/build
"The simplest example of using the Hugo orb."
1
2
3
4
5
6
7
8
9
version: '2.1'
orbs:
hugo: circleci/hugo@1.3.1
workflows:
main:
jobs:
- hugo/build:
html-proofer: true
version: 0.141.0
Build a site with Hugo.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
destination | Path to where Hugo outputs generated site. Relative to `source`. | No | public | string |
html-proofer | Whether or not to test the outputted HTML with HTML Proofer. | No | true | boolean |
htmlproofer-http-status-ignore | An array of numbers representing status codes to ignore. | No | '''''' | string |
htmlproofer-timeframe | A string representing the caching timeframe. The format is `[0-9]+[mhd]` where `m` stands for month, `h` for hours and `d` for days. | No | '''1h''' | string |
htmlproofer-url-ignore | An array of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored. | No | '''''' | string |
hugo-env | Set the value of HUGO_ENV prior to running Hugo. | No | production | string |
hugo-extra-flags | Additional flags to pass when running Hugo (e.g. -DF). | No | '' | string |
persist-to-workspace | Whether to persist generated files to a CircleCI Workspace. This uses `parameters.source` as root and `parameters.publishdir` as the path. | No | true | boolean |
source | Path to Hugo root relative to working_directory. | No | . | string |
version | Hugo version to use. Defaults to latest. | No | latest | string |
Runs HTML Proofer on 'path' to check for html errors. Ruby and the `html-proofer` gem must already be installed to use.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
allow-hash-href | If `true`, ignores the `href= | No | true | boolean |
allow-missing-href | If `true`, does not flag `a` tags missing `href` (this is the default for HTML5). | No | false | boolean |
alt-ignore | A comma-separated list of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore | No | '' | string |
as-links | Assumes that `PATH` is a comma-separated array of links to check. | No | false | boolean |
assume-extension | Automatically add extension (e.g. `.html`) to file paths, to allow extensionless URLs (as supported by Jekyll 3 and GitHub Pages) (default: `false`). | No | false | boolean |
check-external-hash | Checks whether external hashes exist (even if the webpage exists). This slows the checker down (default: `false`). | No | false | boolean |
check-favicon | Enables the favicon checker (default: `false`). | No | false | boolean |
check-html | Enables HTML validation errors from Nokogiri (default: `false`). | No | false | boolean |
check-img-http | Fails an image if it's marked as `http` (default: `false`). | No | false | boolean |
check-opengraph | Enables the Open Graph checker (default: `false`). | No | false | boolean |
check-sri | Check that `<link>` and `<script>` external resources do use SRI (default: `false`). | No | false | boolean |
checks-to-ignore | An array of Strings indicating which checks you'd like to not perform. | No | '''''' | string |
directory-index-file | Sets the file to look for when a link refers to a directory. (default: `index.html`) | No | index.html | string |
disable-external | If `true`, does not run the external link checker, which can take a lot of time (default: `false`) | No | false | boolean |
empty-alt-ignore | If `true`, ignores images with empty alt tags | No | true | boolean |
enforce-https | Fails a link if it's not marked as `https` (default: `false`). | No | false | boolean |
error-sort | Defines the sort order for error output. Can be `:path`, `:desc`, or `:status`. | No | '' | string |
extension | The extension of your HTML files including the dot. (default: `.html`) | No | '''.html''' | string |
external_only | Only checks problems with external references | No | false | boolean |
file-ignore | A comma-separated list of Strings or RegExps containing file paths that are safe to ignore | No | '''''' | string |
http-status-ignore | A comma-separated list of numbers representing status codes to ignore. | No | '''''' | string |
internal-domains | A comma-separated list of Strings containing domains that will be treated as internal urls. | No | '''''' | string |
log-level | Sets the logging level, as determined by Yell. One of `:debug`, `:info`, `:warn`, `:error`, or `:fatal`. (default: `:info`) | No | info | string |
only-4xx | Only reports errors for links that fall within the 4xx status code range | No | false | boolean |
path | Path to generated files relative to working_directory. | Yes | - | string |
report-eof-tags | Ignore `check_html` errors associated with malformed tags (default: `false`) | No | false | boolean |
report-invalid-tags | Ignore `check_html` errors associated with unknown markup (default: `false`) | No | false | boolean |
report-mismatched-tags | Ignore `check_html` errors associated with mismatched tags (default: `false`) | No | false | boolean |
report-missing-doctype | Ignore `check_html` errors associated with missing or out-of-order `DOCTYPE` (default: `false`) | No | false | boolean |
report-missing-names | Ignore `check_html` errors associated with missing entities (default: `false`) | No | false | boolean |
report-script-embeds | Ignore `check_html` errors associated with `script`s (default: `false`) | No | false | boolean |
storage-dir | Directory where to store the cache log (default: "tmp/.htmlproofer") | No | '''tmp/.htmlproofer''' | string |
timeframe | A string representing the caching timeframe. The format is `[0-9]+[mhd]` where `m` stands for month, `h` for hours and `d` for days. | No | '''1h''' | string |
typhoeus-config | JSON-formatted string of Typhoeus config. Will override the html-proofer defaults. | No | '''{}''' | string |
url-ignore | A comma-separated list of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored | No | '''''' | string |
url-swap | A comma-separated list containing key-value pairs of `RegExp => String`. It transforms URLs that match `RegExp` into `String` via `gsub`. The escape sequences `:` should be used to produce literal `:`s. | No | '''''' | string |
Builds with Hugo a static site located at 'source'. The default is '.'.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
destination | Path to where Hugo outputs generated site. Relative to `source`. | No | public | string |
extra-flags | Additional flags to pass when running Hugo (e.g. -DF). | No | '' | string |
hugo-env | Set the value of HUGO_ENV prior to running Hugo. | No | production | string |
source | Path to Hugo root relative to working_directory. | No | . | string |
Install the Hugo binary into your build.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
extended | Install the Hugo extended binary? | No | true | boolean |
install-location | Location where the hugo binary should be installed. | No | /usr/local/bin | string |
version | The Hugo version. | Yes | - | string |
The cibuilds/hugo Docker image.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
hugo_version | Specifies the hugo version to install | No | 0.142.0 | string |
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
Common CircleCI tasks for installing and using Hugo.
Supports the Docker executor (Linux OS with libc) and the macOS executor.
Includes a `cibuilds` executor image with Hugo and html-proofer
pre-installed.
display:
home_url: https://gohugo.io/
source_url: https://github.com/CircleCI-Public/hugo-orb/
orbs:
detect: circleci/os-detect@0.3.0
commands:
html-proofer:
description: Runs HTML Proofer on 'path' to check for html errors. Ruby and the `html-proofer` gem must already be installed to use.
parameters:
allow-hash-href:
default: true
description: If `true`, ignores the `href=
type: boolean
allow-missing-href:
default: false
description: If `true`, does not flag `a` tags missing `href` (this is the default for HTML5).
type: boolean
alt-ignore:
default: ""
description: A comma-separated list of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore
type: string
as-links:
default: false
description: Assumes that `PATH` is a comma-separated array of links to check.
type: boolean
assume-extension:
default: false
description: 'Automatically add extension (e.g. `.html`) to file paths, to allow extensionless URLs (as supported by Jekyll 3 and GitHub Pages) (default: `false`).'
type: boolean
check-external-hash:
default: false
description: 'Checks whether external hashes exist (even if the webpage exists). This slows the checker down (default: `false`).'
type: boolean
check-favicon:
default: false
description: 'Enables the favicon checker (default: `false`).'
type: boolean
check-html:
default: false
description: 'Enables HTML validation errors from Nokogiri (default: `false`).'
type: boolean
check-img-http:
default: false
description: 'Fails an image if it''s marked as `http` (default: `false`).'
type: boolean
check-opengraph:
default: false
description: 'Enables the Open Graph checker (default: `false`).'
type: boolean
check-sri:
default: false
description: 'Check that `<link>` and `<script>` external resources do use SRI (default: `false`).'
type: boolean
checks-to-ignore:
default: ''''''
description: An array of Strings indicating which checks you'd like to not perform.
type: string
directory-index-file:
default: index.html
description: 'Sets the file to look for when a link refers to a directory. (default: `index.html`)'
type: string
disable-external:
default: false
description: 'If `true`, does not run the external link checker, which can take a lot of time (default: `false`)'
type: boolean
empty-alt-ignore:
default: true
description: If `true`, ignores images with empty alt tags
type: boolean
enforce-https:
default: false
description: 'Fails a link if it''s not marked as `https` (default: `false`).'
type: boolean
error-sort:
default: ""
description: Defines the sort order for error output. Can be `:path`, `:desc`, or `:status`.
type: string
extension:
default: '''.html'''
description: 'The extension of your HTML files including the dot. (default: `.html`)'
type: string
external_only:
default: false
description: Only checks problems with external references
type: boolean
file-ignore:
default: ''''''
description: A comma-separated list of Strings or RegExps containing file paths that are safe to ignore
type: string
http-status-ignore:
default: ''''''
description: A comma-separated list of numbers representing status codes to ignore.
type: string
internal-domains:
default: ''''''
description: A comma-separated list of Strings containing domains that will be treated as internal urls.
type: string
log-level:
default: info
description: 'Sets the logging level, as determined by Yell. One of `:debug`, `:info`, `:warn`, `:error`, or `:fatal`. (default: `:info`)'
type: string
only-4xx:
default: false
description: Only reports errors for links that fall within the 4xx status code range
type: boolean
path:
description: Path to generated files relative to working_directory.
type: string
report-eof-tags:
default: false
description: 'Ignore `check_html` errors associated with malformed tags (default: `false`)'
type: boolean
report-invalid-tags:
default: false
description: 'Ignore `check_html` errors associated with unknown markup (default: `false`)'
type: boolean
report-mismatched-tags:
default: false
description: 'Ignore `check_html` errors associated with mismatched tags (default: `false`)'
type: boolean
report-missing-doctype:
default: false
description: 'Ignore `check_html` errors associated with missing or out-of-order `DOCTYPE` (default: `false`)'
type: boolean
report-missing-names:
default: false
description: 'Ignore `check_html` errors associated with missing entities (default: `false`)'
type: boolean
report-script-embeds:
default: false
description: 'Ignore `check_html` errors associated with `script`s (default: `false`)'
type: boolean
storage-dir:
default: '''tmp/.htmlproofer'''
description: 'Directory where to store the cache log (default: "tmp/.htmlproofer")'
type: string
timeframe:
default: '''1h'''
description: A string representing the caching timeframe. The format is `[0-9]+[mhd]` where `m` stands for month, `h` for hours and `d` for days.
type: string
typhoeus-config:
default: '''{}'''
description: JSON-formatted string of Typhoeus config. Will override the html-proofer defaults.
type: string
url-ignore:
default: ''''''
description: A comma-separated list of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored
type: string
url-swap:
default: ''''''
description: A comma-separated list containing key-value pairs of `RegExp => String`. It transforms URLs that match `RegExp` into `String` via `gsub`. The escape sequences `:` should be used to produce literal `:`s.
type: string
steps:
- run:
command: "#!/usr/bin/env bash\n\nPATH_TO_FILES=$(eval \"echo $ORB_EVAL_PATH\")\nALT_IGNORE=$(eval \"echo $ORB_EVAL_ALT_IGNORE\")\nDIRECTORY_INDEX_FILE=$(eval \"echo $ORB_EVAL_DIRECTORY_INDEX_FILE\")\nCHECKS_TO_IGNORE=$(eval \"echo $ORB_EVAL_CHECKS_TO_IGNORE\")\nEXTENSION=$(eval \"echo $ORB_EVAL_EXTENSION\")\nFILE_IGNORE=$(eval \"echo $ORB_EVAL_FILE_IGNORE\")\nHTTPS_STATUS=$(eval \"echo $ORB_EVAL_HTTPS_STATUS\")\nINTERNAL_DOMAINS=$(eval \"echo $ORB_EVAL_INTERNAL_DOMAINS\")\nSTORAGE_DIR=$(eval \"echo $ORB_EVAL_STORAGE_DIR\")\nURL_IGNORE=$(eval \"echo $ORB_EVAL_URL_IGNORE\")\nURL_SWAP=$(eval \"echo $ORB_EVAL_URL_SWAP\")\n\n# # flattened key value list of boolean parameters and their corresponding flags\ncheck_flags=(\"$ORB_VAL_MISSING_HREF\" --allow-missing-href\n \"$ORB_VAL_HASH_HREF\" --allow-hash-href\n \"$ORB_VAL_AS_LINKS\" --as-links\n \"$ORB_VAL_ASSUME_EXTENSION\" --assume-extension\n \"$ORB_VAL_EXTERNAL_HASH\" --check-external-hash\n \"$ORB_VAL_CHECK_FAVICON\" --check-favicon\n \"$ORB_VAL_CHECK_HTML\" --check-html\n \"$ORB_VAL_CHECK_IMG_HTTP\" --check-img-http\n \"$ORB_VAL_CHECK_OPENGRAPH\" --check-opengraph\n \"$ORB_VAL_CHECK_SRI\" --check-sri\n \"$ORB_VAL_DISABLE_EXTERNAL\" --disable-external\n \"$ORB_VAL_EMPTY_ALT_IGNORE\" --empty-alt-ignore\n \"$ORB_VAL_ENFORCE_HTTPS\" --enforce-https\n \"$ORB_VAL_EXTERNAL_ONLY\" --external_only\n \"$ORB_VAL_INVALID_TAGS\" --report-invalid-tags\n \"$ORB_VAL_MISSING_NAMES\" --report-missing-names\n \"$ORB_VAL_SCRIPT_EMBEDS\" --report-script-embeds\n \"$ORB_VAL_MISSING_DOCTYPE\" --rareport-missing-doctype\n \"$ORB_VAL_EOF_TAGS\" --report-eof-tags\n \"$ORB_VAL_MISMATCHED_TAGS\" --report-mismatched-tags\n \"$ORB_VAL_ONLY_FOURX\" --only-4xx)\n\nflags=()\n\n# evaluate boolean parameters and assign flag if set \nfor (( i = 0; i < ${#check_flags[@]} / 2; i++ )); do\n real_index=$((i * 2))\n flag_enabled=${check_flags[$real_index]}\n\n if [ \"$flag_enabled\" = 1 ]; then\n # add the flag to the array \n arg_index=$((real_index + 1))\n flags+=(\"${check_flags[$arg_index]} true\")\n fi\ndone\n\nif [ \"$ORB_VAL_ERRORT_SORT\" = 1 ]; then\n flags+=(--error-sort \"$ORB_VAL_ERRORT_SORT\")\nfi\n\nset -x\nhtmlproofer \"$PATH_TO_FILES\" \\\n --alt-ignore \"$ALT_IGNORE\" \\\n --checks-to-ignore \"$CHECKS_TO_IGNORE\" \\\n --directory-index-file \"$DIRECTORY_INDEX_FILE\" \\\n --extension \"$EXTENSION\" \\\n --file-ignore \"$FILE_IGNORE\" \\\n --http-status-ignore \"$HTTPS_STATUS\" \\\n --internal-domains \"$INTERNAL_DOMAINS\" \\\n --log-level \"$ORB_VAL_LOG_LEVEL\" \\\n --storage-dir \"$STORAGE_DIR\" \\\n --timeframe \"$ORB_VAL_TIMEFRAME\" \\\n --typhoeus-config \"$ORB_VAL_TYPHOEUS_CFG\" \\\n --url-ignore \"$URL_IGNORE\" \\\n --url-swap \"$URL_SWAP\" \\\n \"${flags[@]}\"\nset -x\n"
environment:
ORB_EVAL_ALT_IGNORE: << parameters.alt-ignore >>
ORB_EVAL_CHECKS_TO_IGNORE: << parameters.checks-to-ignore >>
ORB_EVAL_DIRECTORY_INDEX_FILE: << parameters.directory-index-file >>
ORB_EVAL_EXTENSION: << parameters.extension >>
ORB_EVAL_FILE_IGNORE: << parameters.file-ignore >>
ORB_EVAL_HTTPS_STATUS: << parameters.http-status-ignore >>
ORB_EVAL_INTERNAL_DOMAINS: << parameters.internal-domains >>
ORB_EVAL_PATH: << parameters.path >>
ORB_EVAL_STORAGE_DIR: << parameters.storage-dir >>
ORB_EVAL_URL_IGNORE: << parameters.url-ignore >>
ORB_EVAL_URL_SWAP: << parameters.url-swap >>
ORB_VAL_AS_LINKS: << parameters.as-links >>
ORB_VAL_ASSUME_EXTENSION: << parameters.assume-extension >>
ORB_VAL_CHECK_FAVICON: << parameters.check-favicon >>
ORB_VAL_CHECK_HTML: << parameters.check-html >>
ORB_VAL_CHECK_IMG_HTTP: << parameters.check-img-http >>
ORB_VAL_CHECK_OPENGRAPH: << parameters.check-opengraph >>
ORB_VAL_CHECK_SRI: << parameters.check-sri >>
ORB_VAL_DISABLE_EXTERNAL: << parameters.disable-external >>
ORB_VAL_EMPTY_ALT_IGNORE: << parameters.empty-alt-ignore >>
ORB_VAL_ENFORCE_HTTPS: << parameters.enforce-https >>
ORB_VAL_EOF_TAGS: << parameters.report-eof-tags >>
ORB_VAL_ERROR_SORT: << parameters.error-sort >>
ORB_VAL_EXTERNAL_HASH: << parameters.check-external-hash >>
ORB_VAL_EXTERNAL_ONLY: << parameters.external_only >>
ORB_VAL_HASH_HREF: << parameters.allow-hash-href >>
ORB_VAL_INVALID_TAGS: << parameters.report-invalid-tags >>
ORB_VAL_LOG_LEVEL: << parameters.log-level >>
ORB_VAL_MISMATCHED_TAGS: << parameters.report-mismatched-tags >>
ORB_VAL_MISSING_DOCTYPE: << parameters.report-missing-doctype >>
ORB_VAL_MISSING_HREF: << parameters.allow-missing-href >>
ORB_VAL_MISSING_NAMES: << parameters.report-missing-names >>
ORB_VAL_ONLY_FOURXX: << parameters.only-4xx >>
ORB_VAL_SCRIPT_EMBEDS: << parameters.report-script-embeds >>
ORB_VAL_TIMEFRAME: << parameters.timeframe >>
ORB_VAL_TYPHOEUS_CFG: << parameters.typhoeus-config >>
name: Test generated website with HTML Proofer.
hugo-build:
description: Builds with Hugo a static site located at 'source'. The default is '.'.
parameters:
destination:
default: public
description: Path to where Hugo outputs generated site. Relative to `source`.
type: string
extra-flags:
default: ""
description: Additional flags to pass when running Hugo (e.g. -DF).
type: string
hugo-env:
default: production
description: Set the value of HUGO_ENV prior to running Hugo.
type: string
source:
default: .
description: Path to Hugo root relative to working_directory.
type: string
steps:
- run:
command: |
#!/usr/bin/env bash
ORB_EVAL_SOURCE=$(eval echo "${ORB_EVAL_SOURCE}")
ORB_EVAL_DESTINATION=$(eval echo "${ORB_EVAL_DESTINATION}")
ORB_EVAL_HUGO_ENV=$(eval echo "${ORB_EVAL_HUGO_ENV}")
ORB_EVAL_HUGO_EXTRA_FLAGS=$(eval echo "${ORB_EVAL_HUGO_EXTRA_FLAGS}")
export HUGO_ENV="${ORB_EVAL_HUGO_ENV}"
hugo build -s "${ORB_EVAL_SOURCE}" -d "${ORB_EVAL_DESTINATION}" "${ORB_EVAL_HUGO_EXTRA_FLAGS}"
environment:
ORB_EVAL_DESTINATION: << parameters.destination >>
ORB_EVAL_HUGO_ENV: << parameters.hugo-env >>
ORB_EVAL_HUGO_EXTRA_FLAGS: << parameters.extra-flags >>
ORB_EVAL_SOURCE: << parameters.source >>
name: Build with Hugo
install:
description: Install the Hugo binary into your build.
parameters:
extended:
default: true
description: Install the Hugo extended binary?
type: boolean
install-location:
default: /usr/local/bin
description: Location where the hugo binary should be installed.
type: string
version:
description: The Hugo version.
type: string
steps:
- detect/init
- run:
command: |
#!/usr/bin/env bash
ORB_EVAL_INSTALL_LOCATION=$(eval echo "${ORB_EVAL_INSTALL_LOCATION}")
case $OSD_FAMILY in
linux)
OS=Linux-64bit
PKG_EXT=tar.gz
;;
darwin)
OS=darwin-universal
PKG_EXT=tar.gz
;;
*)
echo "Unsupported operating system."
exit 1
;;
esac
# If we're in Alpine, install additional compatibility packages.
if [[ $OSD_ID == "alpine" ]]; then
apk add build-base curl libcurl libc6-compat libxml2-dev libxslt-dev
fi
if [ "${ORB_VAL_EXTENDED}" = 1 ]; then
HUGO_EXTENDED="_extended"
else
HUGO_EXTENDED=""
fi
HUGO_URL=https://github.com/gohugoio/hugo/releases/download/v${ORB_VAL_VERSION}/hugo${HUGO_EXTENDED}_${ORB_VAL_VERSION}_${OS}.${PKG_EXT}
curl --fail -sSL "$HUGO_URL" -o hugo-archive 2>/dev/null
# If the download fails...
if $SUDO tar -xzf hugo-archive -C "${ORB_EVAL_INSTALL_LOCATION}" hugo 2>/dev/null; then
echo "Hugo succesfully installed."
else
if [[ ! "${ORB_VAL_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Failed to install. The version number ${ORB_VAL_VERSION} is not a full valid SemVer version."
else
echo "Please choose a valid version from the Hugo tags page, without the leading 'v': https://github.com/gohugoio/hugo/tags"
echo "The download URL that failed was: ${HUGO_URL}"
fi
exit 1
fi
environment:
ORB_EVAL_INSTALL_LOCATION: << parameters.install-location >>
ORB_VAL_EXTENDED: << parameters.extended >>
ORB_VAL_VERSION: << parameters.version >>
name: Install Hugo
executors:
default:
description: The cibuilds/hugo Docker image.
docker:
- image: cibuilds/hugo:<< parameters.hugo_version >>
parameters:
hugo_version:
default: 0.142.0
description: Specifies the hugo version to install
type: string
jobs:
build:
description: Build a site with Hugo.
executor:
hugo_version: << parameters.version >>
name: default
parameters:
destination:
default: public
description: Path to where Hugo outputs generated site. Relative to `source`.
type: string
html-proofer:
default: true
description: Whether or not to test the outputted HTML with HTML Proofer.
type: boolean
htmlproofer-http-status-ignore:
default: ''''''
description: An array of numbers representing status codes to ignore.
type: string
htmlproofer-timeframe:
default: '''1h'''
description: A string representing the caching timeframe. The format is `[0-9]+[mhd]` where `m` stands for month, `h` for hours and `d` for days.
type: string
htmlproofer-url-ignore:
default: ''''''
description: An array of Strings or RegExps containing URLs that are safe to ignore. It affects all HTML attributes. Note that non-HTTP(S) URIs are always ignored.
type: string
hugo-env:
default: production
description: Set the value of HUGO_ENV prior to running Hugo.
type: string
hugo-extra-flags:
default: ""
description: Additional flags to pass when running Hugo (e.g. -DF).
type: string
persist-to-workspace:
default: true
description: Whether to persist generated files to a CircleCI Workspace. This uses `parameters.source` as root and `parameters.publishdir` as the path.
type: boolean
source:
default: .
description: Path to Hugo root relative to working_directory.
type: string
version:
default: latest
description: Hugo version to use. Defaults to latest.
type: string
steps:
- checkout
- run:
command: |-
#!/usr/bin/env bash
if [ -f ".gitmodules" ]; then
git submodule sync
git submodule update --init --recursive
fi
name: Checkout Submodules if Needed
- hugo-build:
destination: << parameters.destination >>
extra-flags: << parameters.hugo-extra-flags >>
source: << parameters.source >>
- when:
condition: << parameters.html-proofer >>
steps:
- html-proofer:
http-status-ignore: << parameters.htmlproofer-http-status-ignore >>
path: << parameters.source >>/<< parameters.destination >>
timeframe: << parameters.htmlproofer-timeframe >>
url-ignore: << parameters.htmlproofer-url-ignore >>
- when:
condition: << parameters.persist-to-workspace >>
steps:
- persist_to_workspace:
paths:
- << parameters.destination >>
root: << parameters.source >>
examples:
build-and-deploy:
description: |
"An example of building a Hugo site, testing with HTML Proofer, and deployng it. Here the Hugo source is in a subdirectory called 'src'. The deploy job is empty and serves as an example. Instead of the 'ls' command, you'd want to deploy the files using whatever tools you're used to."
usage:
version: "2.1"
orbs:
hugo: circleci/hugo@1.3.1
jobs:
deploy:
docker:
- image: cimg/base
steps:
- attach_workspace:
at: my-site
- run: ls -lah my-site
workflows:
main:
jobs:
- hugo/build:
html-proofer: true
source: src/
version: 0.141.0
- deploy:
filters:
branches:
only: master
requires:
- hugo/build
build-and-test:
description: |
"The simplest example of using the Hugo orb."
usage:
version: "2.1"
orbs:
hugo: circleci/hugo@1.3.1
workflows:
main:
jobs:
- hugo/build:
html-proofer: true
version: 0.141.0