This repository has been archived by the owner on Dec 28, 2023. It is now read-only.
generated from wildtechgarden/module-starter-hugo-wtg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
228 lines (228 loc) · 10.1 KB
/
action.yml
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
---
# yamllint disable rule:key-ordering rule:line-length
# cspell:ignore webp peaceiris hugomod hugoresources Lastmod CACHEDIR ENABLEMISSINGTRANSLATIONPLACEHOLDERS TDEWOLFF KEEPCOMMENTS RESOURCEDIR Zgotmpl hahahugo
name: Build & audit for Hugo
author: Wild Tech 'Garden'
description: Checkout, build, and audit a Hugo site
branding:
color: blue
icon: thumbs-up
inputs:
base-url:
description: Set baseURL for the build
# Only required for deployment or building an artifact
required: false
build-for-downstream:
description: Build for use by another action or step (aka bundle)
required: true
default: "false"
checkout-fetch-depth:
description: |
Fetch depth\: Use 0 to fetch all history if using .GitInfo or .Lastmod
required: true
default: "0"
checkout-submodules:
description: |
Fetch git submodules\: false, true, or recursive
required: true
default: "false"
code-directory:
description: Directory under which repo and modules will live
required: true
default: ${{ github.workspace }}/code
config-file:
description: Alternate configuration file to use for site (may be a comma-separated list of files, relative to the 'source' dir)
required: true
default: hugo.toml
do-minify-audit:
description: If present, minify site using --minify before audit
required: false
do-minify-bundle:
description: If present, minify site using --minify during last build
required: false
hugo-cache-directory:
description: |
Where to place the Hugo module cache, under the code-directory
required: true
default: hugo_cache
hugo-env:
description: Hugo environment (production, development, etc)
required: true
default: production
hugo-extended:
description: Hugo Extended
required: true
default: "true"
hugo-version:
description: Hugo Version
required: true
default: latest
image-formats:
description: Image formats to include in resource hash key
required: true
default: "['webp', 'svg', 'png', 'jpg', 'jpeg','gif', 'tiff', 'tif', 'bmp']"
include-drafts-audit:
description: Include pages marked as 'draft' during audit
required: true
default: "true"
include-future-audit:
description: Include pages with a publishDate in the future during audit
required: true
default: "true"
include-drafts-bundle:
description: |
Include pages marked as 'draft' during 'bundle' (for another stage)'
required: true
default: "false"
include-future-bundle:
description: |
Include pages with a publishDate in the future during 'bundle' (for
another stage)
required: true
default: "false"
output-directory:
description: Location of the site output by Hugo, relative to the workspace
required: true
default: public
repo-directory:
description: Where to checkout the repo, under the code-directory
required: true
default: repo
source-directory:
description: Where the source for the site lives, within the repo
required: false
upload-site-as:
description: Artifact to create containing the Hugo site
required: false
upload-site-filename:
description: Filename for tarball of site to upload to artifact
required: true
default: hugo-site.tar
upload-site-retention:
description: Retention period in days for Hugo site artifact
required: true
default: "1"
use-lfs:
description: Use LFS when checking out out repo
required: true
default: "false"
runs:
using: composite
steps:
- uses: actions/checkout@v4
with:
fetch-depth: ${{ inputs.checkout-fetch-depth }}
lfs: ${{ inputs.use-lfs }}
path: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}
submodules: ${{ inputs.submodules }}
- name: Install Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: ${{ inputs.hugo-version }}
extended: ${{ inputs.hugo-extended }}
- name: Hugo modules cache
uses: actions/cache@v3
env:
modules-hash: ${{ hashFiles(format('{0}/{1}', inputs.code-directory, '/**/go.sum')) }}
with:
path: ${{ inputs.code-directory}}/${{ inputs.hugo-cache-directory }}
key: ${{ runner.os }}-hugomod-${{ env.modules-hash }}
restore-keys: |
${{ runner.os }}-hugomod-
- name: Pull Hugo modules before calculating resources
shell: bash
env:
CONFIG_FILE: ${{ inputs.config-file }}
HUGO_CACHEDIR: ${{ inputs.code-directory }}/${{ inputs.hugo-cache-directory }}
SOURCE_DIRECTORY: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/${{ inputs.source-directory }}
run: hugo mod tidy ${CONFIG_FILE:+--config $CONFIG_FILE} --source ${SOURCE_DIRECTORY}
- name: Create resources manifest
env:
HUGO_CACHEDIR: ${{ inputs.code-directory }}/${{ inputs.hugo-cache-directory }}
IMAGE_PATHS: ${{ join(fromJSON(inputs.image-formats), ''' -o -name ''*.') }}
SOURCE_DIRECTORY: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/${{ inputs.source-directory }}
shell: bash
run: |
echo "resources_hash=$(echo $(find ${HUGO_CACHEDIR} ${SOURCE_DIRECTORY} -path '**assets/**')$(find ${SOURCE_DIRECTORY}/content -name '*.${{ env.IMAGE_PATHS }}') | sort | sha256sum - | cut -f1 -d' ')" >> $GITHUB_ENV
- name: Hugo resources cache
uses: actions/cache@v3
with:
path: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/resources
key: ${{ runner.os }}-hugoresources-${{ env.resources_hash }}
restore-keys: |
${{ runner.os }}-hugoresources-
${{ runner.os }}-hugoresources
- name: Build site so it is suitable for auditing
shell: bash
env:
CONFIG_FILE: ${{ inputs.config-file }}
DO_MINIFY: ${{ inputs.do-minify-audit }}
HUGO_CACHEDIR: ${{ inputs.code-directory }}/${{ inputs.hugo-cache-directory }}
HUGO_ENABLEMISSINGTRANSLATIONPLACEHOLDERS: "true"
HUGO_ENV: ${{ inputs.hugo-env }}
HUGO_MINIFY_TDEWOLFF_HTML_KEEPCOMMENTS: "true"
HUGO_RESOURCEDIR: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/resources
INCLUDE_DRAFTS: ${{ inputs.include-drafts-audit }}
INCLUDE_FUTURE: ${{ inputs.include-future-audit }}
OUTPUT_DIRECTORY: ${{ github.workspace }}/${{ inputs.output-directory }}
SOURCE_DIRECTORY: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/${{ inputs.source-directory }}
BASEURL: ${{ inputs.base-url }}
run: |
if [ -n "$CONFIG_FILE" ]; then CONFIG_FILE="--config ""$CONFIG_FILE"; fi
rm -rf "${OUTPUT_DIRECTORY}"
if [ "$DO_MINIFY" == "true" ]; then DO_MINIFY="--minify"; else unset DO_MINIFY; fi
if [ "$INCLUDE_DRAFTS" == "true" ]; then INCLUDE_DRAFTS="--buildDrafts"; else unset INCLUDE_DRAFTS; fi
if [ "$INCLUDE_FUTURE" == "true" ]; then INCLUDE_FUTURE="--buildFuture"; else unset INCLUDE_FUTURE; fi
hugo ${CONFIG_FILE} --environment "${HUGO_ENV}" --source "${SOURCE_DIRECTORY}" --destination "${OUTPUT_DIRECTORY}" --gc --cleanDestinationDir ${DO_MINIFY} ${INCLUDE_DRAFTS} ${INCLUDE_FUTURE} ${BASEURL:+-b $BASEURL}
if [ ! -s "$OUTPUT_DIRECTORY"/index.html ]; then echo "Missing output"; exit 1; fi
- name: Audit site for missed Hugo issues (step 1)
shell: bash
env:
OUTPUT_DIRECTORY: ${{ github.workspace }}/${{ inputs.output-directory }}
run: if ! grep -iIrnE '<\!-- raw HTML omitted -->|ZgotmplZ|hahahugo|\[i18n\]|\(<nil>\)|\(<nil>\)' ${OUTPUT_DIRECTORY} >hugo-audit.log; then RET=$?; fi; if test "$RET" = "2"; then echo "not ok"; exit 1; fi
- name: Audit site for missed Hugo issues (step 2)
shell: bash
env:
OUTPUT_DIRECTORY: ${{ github.workspace }}/${{ inputs.output-directory }}
run: if test -s hugo-audit.log; then RET2=2; { { grep -iIvE 'grep(.+(-- raw HTML omitted --|ZgotmplZ|hahahugo|\\\[i18n\\\]|\\\(<nil>\\\)|\\\(<nil>\\\))+)' hugo-audit.log; RET2=$?; } || true; }; if test "$RET2" != "1"; then echo "not ok"; exit 1; fi; else echo "ok"; exit 0; fi
- name: Build site omitting information needed only to audit
if: inputs.upload-site-as || inputs.build-for-downstream == 'true'
shell: bash
env:
CONFIG_FILE: ${{ inputs.config-file }}
DO_MINIFY: ${{ inputs.do-minify-bundle }}
HUGO_CACHEDIR: ${{ inputs.code-directory }}/${{ inputs.hugo-cache-directory }}
HUGO_ENABLEMISSINGTRANSLATIONPLACEHOLDERS: "false"
HUGO_ENV: ${{ inputs.hugo-env }}
HUGO_MINIFY_TDEWOLFF_HTML_KEEPCOMMENTS: "false"
HUGO_RESOURCEDIR: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/resources
INCLUDE_DRAFTS: ${{ inputs.include-drafts-bundle }}
INCLUDE_FUTURE: ${{ inputs.include-future-bundle }}
OUTPUT_DIRECTORY: ${{ github.workspace }}/${{ inputs.output-directory }}
SOURCE_DIRECTORY: ${{ inputs.code-directory }}/${{ inputs.repo-directory }}/${{ inputs.source-directory }}
BASEURL: ${{ inputs.base-url }}
run: |
rm -rf "${OUTPUT_DIRECTORY}"
if [ -n "$CONFIG_FILE" ]; then CONFIG_FILE="--config ""$CONFIG_FILE"; fi
if [ "$DO_MINIFY" == "true" ]; then DO_MINIFY="--minify"; else unset DO_MINIFY; fi
if [ "$INCLUDE_DRAFTS" == "true" ]; then INCLUDE_DRAFTS="--buildDrafts"; else unset INCLUDE_DRAFTS; fi
if [ "$INCLUDE_FUTURE" == "true" ]; then INCLUDE_FUTURE="--buildFuture"; else unset INCLUDE_FUTURE; fi
hugo ${CONFIG_FILE} --environment "${HUGO_ENV}" --source "${SOURCE_DIRECTORY}" --destination "${OUTPUT_DIRECTORY}" --gc --cleanDestinationDir ${DO_MINIFY} ${INCLUDE_DRAFTS} ${INCLUDE_FUTURE} ${BASEURL:+-b $BASEURL}
if [ ! -s "$OUTPUT_DIRECTORY"/index.html ]; then echo "Missing output"; exit 1; fi
- name: Tar site for upload as artifact
if: inputs.upload-site-as
shell: bash
env:
BASE_DIRECTORY: ${{ github.workspace }}
OUTPUT_DIRECTORY: ${{ inputs.output-directory }}
UPLOAD_FILENAME: ${{ inputs.upload-site-filename }}
run: tar -C "${BASE_DIRECTORY}" -cf "${UPLOAD_FILENAME}" "${OUTPUT_DIRECTORY}"
- name: Upload site as an artifact
uses: actions/upload-artifact@v3
if: inputs.upload-site-as
with:
name: ${{ inputs.upload-site-as }}
path: hugo-site.tar
if-no-files-found: error
retention-days: ${{ inputs.upload-site-retention }}
...