-
-
Notifications
You must be signed in to change notification settings - Fork 1
268 lines (238 loc) · 7.83 KB
/
jekyll-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
---
name: Build Jekyll
on:
workflow_call:
inputs:
site_artifact:
description: 'Artifact name to download'
required: false
default: ''
type: string
extract_archive:
description: |
Name of nested archive to extract. In some cases you may want to upload a zip of files to reduce
upload size and time. If you do this, you must specify the name of the archive to extract.
required: false
default: ''
type: string
config_file:
description: 'Configuration file to use, relative to the site source directory'
required: false
default: '_config.yml'
type: string
target_branch:
description: 'Branch to deploy to. Branch must already exist.'
required: false
default: 'gh-pages'
type: string
clean_gh_pages:
description: 'Clean gh-pages before deploying'
required: false
default: true
type: boolean
theme_ref:
description: 'Branch, tag, or commit SHA of the theme repository to use'
required: false
default: 'master'
type: string
base_url:
description: |
Base URL of the site. With default option, the root will come from LizardByte.github.io (app.lizardbyte.dev).
This is useful to re-use the theme config and many assets from that site; but requires you to prefix other
assets with `/<RepoName>` (e.g. `/MyRepo/assets/img/my-image.png`).
If this is set to `_auto`, the workflow will determine this value automatically.
required: false
default: ''
type: string
secrets:
GH_BOT_EMAIL:
description: 'Email address of the bot account'
required: true
GH_BOT_NAME:
description: 'Name of the bot account'
required: true
GH_BOT_TOKEN:
description: 'Personal access token of the bot account'
required: true
jobs:
build:
name: Build Jekyll
runs-on: ubuntu-latest
steps:
- name: Input validation
run: |
error=false
if [ "${{ inputs.site_artifact }}" == 'site' ]; then
echo "Artifact name cannot be 'site'"
error=true
fi
if [ "$error" = true ]; then
exit 1
fi
- name: Checkout theme
uses: actions/checkout@v4
with:
repository: LizardByte/LizardByte.github.io
ref: ${{ github.repository == 'LizardByte/LizardByte.github.io' && github.ref || inputs.theme_ref }}
submodules: recursive
path: theme
- name: Download input artifact
if: ${{ inputs.site_artifact != '' }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.site_artifact }}
path: project
- name: Extract archive
if: ${{ inputs.site_artifact != '' && inputs.extract_archive != '' }}
working-directory: project
run: |
case "${{ inputs.extract_archive }}" in
*.tar.gz|*.tgz)
tar -xzf ${{ inputs.extract_archive }} -C .
;;
*.tar)
tar -xf ${{ inputs.extract_archive }} -C .
;;
*.zip)
7z x ${{ inputs.extract_archive }} -o.
;;
*)
echo "Unsupported archive format"
exit 1
;;
esac
rm -f ${{ inputs.extract_archive }}
- name: Setup project
if: ${{ github.repository == 'LizardByte/LizardByte.github.io' }}
run: |
mkdir -p ./project
cp -RT ./theme/ ./project/
rm -rf ./project/third-party
- name: Create site
env:
TMPDIR: /home/runner/work/tmp
run: |
mkdir -p ${TMPDIR}
base_dirs=(
./theme/third-party/beautiful-jekyll
./theme
)
targets=(
*.gemspec
_data
_includes
_layouts
_sass
assets
404.html
_config_theme.yml
favicon.ico
feed.xml
Gemfile
staticman.yml
tags.html
)
for base_dir in "${base_dirs[@]}"; do
for target in "${targets[@]}"; do
if [ -e "$base_dir/$target" ]; then
cp -rf "$base_dir/$target" ${TMPDIR}/
fi
done
done
# copy project directory, they should only come from the project repo
cp -RTf ./project/ ${TMPDIR}/
# remove the workspace
cd ..
rm -rf ${GITHUB_WORKSPACE}
# move the temporary directory to the workspace
mv ${TMPDIR} ${GITHUB_WORKSPACE}
cd ${GITHUB_WORKSPACE}
# debug contents recursively
ls -Ra
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
- name: Install dependencies
run: |
bundle install
- name: Setup Pages
id: configure-pages
uses: actions/configure-pages@v5
- name: Setup CI config
run: |
config_file="_config_ci.yml"
echo "---" > $config_file
if [ "${{ inputs.base_url }}" == '_auto' ]; then
echo "baseurl: '${{ steps.configure-pages.outputs.base_path }}'" >> $config_file
else
echo "baseurl: '${{ inputs.base_url }}'" >> $config_file
fi
cat $config_file
- name: Build site
env:
JEKYLL_ENV: production
JEKYLL_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PAGES_REPO_NWO: ${{ github.repository }}
run: |
# if inputs.config_file exists
config_files="_config_ci.yml,_config_theme.yml"
if [ -e "${{ inputs.config_file }}" ]; then
cat ${{ inputs.config_file }}
config_files="${config_files},${{ inputs.config_file }}"
fi
bundle exec jekyll build --future --config ${config_files}
- name: Prepare Artifacts # uploading artifacts may fail if not zipped due to very large quantity of files
shell: bash
run: |
7z a _site.zip ./_site/*
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: site
path: _site.zip
if-no-files-found: error
include-hidden-files: true
retention-days: 1
deploy:
name: Deploy to Pages
if: >-
(github.event_name == 'push' && github.ref == 'refs/heads/master') ||
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch')
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: ${{ inputs.target_branch }}
path: gh-pages
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of the personal token
fetch-depth: 0 # otherwise, will fail to push refs to dest repo
- name: Clean
if: ${{ inputs.clean_gh_pages }}
run: |
# empty contents of gh-pages
rm -f -r ./gh-pages/*
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: site
path: gh-pages
- name: Setup gh-pages
working-directory: gh-pages
run: |
7z x _site.zip -o.
rm _site.zip
touch .nojekyll
- name: Deploy to gh-pages
uses: actions-js/[email protected]
with:
github_token: ${{ secrets.GH_BOT_TOKEN }}
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
directory: gh-pages
branch: ${{ inputs.target_branch }}
force: false
message: "Deploy site from ${{ github.sha }}"