-
-
Notifications
You must be signed in to change notification settings - Fork 6
273 lines (251 loc) · 9.73 KB
/
build.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
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
name: build
on:
schedule:
- cron: '*/30 * * * *'
issue_comment:
types: [created]
workflow_dispatch:
push:
branches:
- '*'
concurrency:
group: "docker"
cancel-in-progress: false
env:
PLATFORMS: linux/amd64,linux/arm64
IMAGE_OWNER: hugomods
IMAGE_NAME: hugo
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
build-and-push-image:
strategy:
fail-fast: false
matrix:
version: ['', 'reg-']
prefix: ['', 'base-', 'go-', 'go-git-', 'node-', 'node-git-', 'node-lts-', 'exts-', 'git-']
# Tags placeholders:
# 0: the image owner.
# 1: the image name.
# 2: the Hugo version without leading v.
# 3: regular (reg-) or extended (empty string) indicator.
include:
- version: ''
extended: true
- version: ''
prefix: ''
dockerfile: Dockerfile
tags: |
{0}/{1}:latest
{0}/{1}:{2}
ghcr.io/{0}/{1}:latest
ghcr.io/{0}/{1}:{2}
- version: 'reg-'
prefix: ''
dockerfile: Dockerfile
tags: |
{0}/{1}:reg
{0}/{1}:reg-{2}
ghcr.io/{0}/{1}:reg
ghcr.io/{0}/{1}:reg-{2}
- prefix: base-
dockerfile: Dockerfile-base
tags: |
{0}/{1}:{3}base
{0}/{1}:{3}base-{2}
ghcr.io/{0}/{1}:{3}base
ghcr.io/{0}/{1}:{3}base-{2}
- prefix: git-
dockerfile: Dockerfile-git
tags: |
{0}/{1}:{3}git
{0}/{1}:{3}git-{2}
ghcr.io/{0}/{1}:{3}git
ghcr.io/{0}/{1}:{3}git-{2}
- prefix: go-
dockerfile: Dockerfile-go
tags: |
{0}/{1}:{3}go
{0}/{1}:{3}go-{2}
ghcr.io/{0}/{1}:{3}go
ghcr.io/{0}/{1}:{3}go-{2}
- prefix: go-git-
dockerfile: Dockerfile-go-git
tags: |
{0}/{1}:{3}go-git
{0}/{1}:{3}go-git-{2}
ghcr.io/{0}/{1}:{3}go-git
ghcr.io/{0}/{1}:{3}go-git-{2}
- prefix: node-
dockerfile: Dockerfile-node
tags: |
{0}/{1}:{3}node
{0}/{1}:{3}node-{2}
ghcr.io/{0}/{1}:{3}node
ghcr.io/{0}/{1}:{3}node-{2}
- prefix: node-git-
dockerfile: Dockerfile-node-git
tags: |
{0}/{1}:{3}node-git
{0}/{1}:{3}node-git-{2}
ghcr.io/{0}/{1}:{3}node-git
ghcr.io/{0}/{1}:{3}node-git-{2}
- prefix: node-lts-
dockerfile: Dockerfile-node-lts
tags: |
{0}/{1}:{3}node-lts
{0}/{1}:{3}node-lts-{2}
ghcr.io/{0}/{1}:{3}node-lts
ghcr.io/{0}/{1}:{3}node-lts-{2}
- prefix: exts-
dockerfile: Dockerfile-exts
tags: |
{0}/{1}:{3}exts
{0}/{1}:{3}exts-{2}
ghcr.io/{0}/{1}:{3}exts
ghcr.io/{0}/{1}:{3}exts-{2}
runs-on: ubuntu-latest
if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' || github.event.issue.number == 3 }}
steps:
- name: Fetch latest Hugo release
id: release
run: curl https://api.github.com/repos/gohugoio/hugo/releases/latest -s | jq .tag_name -r | awk '{print "version="substr($1,2)}' >> $GITHUB_OUTPUT
- name: Check if the image exists
if: steps.release.outputs.version != 'ull'
id: check
run: |
if [[ "${{ github.event.head_commit.message }}" == *"[build]"* ]]; \
then echo "exists=false"; \
else curl -s \
-- url https://hub.docker.com/v2/namespaces/${{ env.IMAGE_OWNER }}/repositories/${{ env.IMAGE_NAME }}/tags/${{ matrix.version }}${{ matrix.prefix }}${{ steps.release.outputs.version }} \
| jq 'has("name")' \
| awk '{print "exists="$1}'; \
fi \
>> $GITHUB_OUTPUT;
# Checkout the main repository.
- name: Checkout repository
if: steps.check.outputs.exists == 'false'
uses: actions/checkout@v4
# Checkout the Hugo repository for building.
- name: Checkout Hugo repository
if: steps.check.outputs.exists == 'false'
uses: actions/checkout@v4
with:
repository: gohugoio/hugo
ref: v${{ steps.release.outputs.version }}
path: ./docker/hugo/src
- name: Build meta
id: build_meta
if: steps.check.outputs.exists == 'false'
run: |
echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
cd ./docker/hugo/src && echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: LDFLAGS
id: ldflags
if: steps.check.outputs.exists == 'false'
run: |
echo "hash=-X github.com/gohugoio/hugo/common/hugo.commitHash=${{ steps.build_meta.outputs.hash }}" >> $GITHUB_OUTPUT
echo "builddate=-X github.com/gohugoio/hugo/common/hugo.buildDate=${{ steps.build_meta.outputs.date }}" >> $GITHUB_OUTPUT
echo "vendor=-X github.com/gohugoio/hugo/common/hugo.vendorInfo=hugomods" >> $GITHUB_OUTPUT
- name: Set up QEMU
if: steps.check.outputs.exists == 'false'
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Set up Docker Buildx
if: steps.check.outputs.exists == 'false'
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.PLATFORMS }}
- name: Login to Docker Hub
if: steps.check.outputs.exists == 'false'
uses: docker/login-action@v3
with:
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: steps.check.outputs.exists == 'false'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and export to Docker
if: steps.check.outputs.exists == 'false'
uses: docker/build-push-action@v5
with:
load: true
context: docker/hugo
file: docker/hugo/${{ matrix.dockerfile }}
tags: hugomods/hugo:test
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS="${{ steps.ldflags.outputs.hash }} ${{ steps.ldflags.outputs.builddate }} ${{ steps.ldflags.outputs.vendor }}"
HUGO_VERSION=v${{ steps.release.outputs.version }}
HUGO_EXTENDED=${{ matrix.extended }}
- name: Test site build
if: steps.check.outputs.exists == 'false'
run: |
docker run --rm -v $PWD/site:/src hugomods/hugo:test hugo
env:
IMAGE_PREFIX: ${{ matrix.prefix }}
- name: Test Extra Markdown Handlers
if: steps.check.outputs.exists == 'false' &&
contains(fromJson('["exts-"]'), matrix.prefix)
run: |
docker run --rm -v $PWD/site:/src hugomods/hugo:test hugo --config config.yaml,config-markdown-handlers.yaml
env:
IMAGE_PREFIX: ${{ matrix.prefix }}
- name: Check Git installation
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "git-", "node-git-", "go-git-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test git version
- name: Test site build with --enableGitInfo
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "git-", "node-git-", "go-git-", "exts-"]'), matrix.prefix)
run: >-
docker run --rm
-v $PWD/site:/src
hugomods/hugo:test
/bin/sh -c "git init &&
git add -A &&
git config --global user.email "[email protected]" &&
git config --global user.name "HugoMods" &&
git commit -m 'Test commit' &&
hugo --enableGitInfo"
- name: Check Go installation
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "go-", "go-git-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test go version
- name: Check Node.js and NPM installation
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["", "node-", "node-git-", "node-lts-", "exts-"]'), matrix.prefix)
run: docker run --rm hugomods/hugo:test node -v && npm version
- name: Check PostCSS, PurgeCSS, Autoprefixer and RTLCSS
if: |
steps.check.outputs.exists == 'false' &&
contains(fromJson('["exts-"]'), matrix.prefix)
run: >-
docker run --rm
-v $PWD/tests/postcss:/src
hugomods/hugo:test
postcss ./main.css
- name: Build and push
if: ${{ steps.check.outputs.exists == 'false' && env.BRANCH_NAME == 'main' }}
uses: docker/build-push-action@v5
with:
push: true
context: docker/hugo
platforms: ${{ env.PLATFORMS }}
file: docker/hugo/${{ matrix.dockerfile }}
tags: ${{ format(matrix.tags, env.IMAGE_OWNER, env.IMAGE_NAME, steps.release.outputs.version, matrix.version) }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
LDFLAGS="${{ steps.ldflags.outputs.hash }} ${{ steps.ldflags.outputs.builddate }} ${{ steps.ldflags.outputs.vendor }}"
HUGO_VERSION=v${{ steps.release.outputs.version }}
HUGO_EXTENDED=${{ matrix.extended }}