forked from jgm/lunamark
-
Notifications
You must be signed in to change notification settings - Fork 31
354 lines (354 loc) · 12.3 KB
/
main.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
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
name: test & publish
on:
push:
branches:
- main
paths-ignore:
- '**/README.md'
- 'CHANGES.md'
- 'contributions/*'
- '.github/**/*'
- 'experiments/**/*'
pull_request_target:
workflow_dispatch:
inputs:
runTests:
description: Run tests
required: true
default: true
type: boolean
schedule:
- cron: '30 4 * * MON'
env:
DEBIAN_FRONTEND: noninteractive
DOCKER_DEV_IMAGE: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.draft == true }}
jobs:
spacecheck:
name: Style check (Tabs and spaces)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Check for tabs and trailing spaces
run: |
! grep -n -P '\t|\s+$' markdown.dtx
shellcheck:
name: Style check (Bash)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Run ShellCheck
uses: ludeeus/[email protected]
env:
SHELLCHECK_OPTS: -e SC1091
luacheck:
name: Style check (Lua)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install additional packages
run: |
set -ex
sudo apt -qy update
sudo apt -qy install --no-install-recommends git latexmk lua-check make texlive-xetex
- name: Extract Lua scripts
run: make base
- name: Run luacheck
run: luacheck *.lua
markdownlint:
name: Style check (Markdown)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install additional packages
run: |
set -ex
sudo apt -qy update
sudo apt -qy install --no-install-recommends git latexmk lua-check make texlive-xetex
- name: Extract user manual
run: make markdown-transcluded.md
- name: Run MarkdownLint
uses: nosborn/[email protected]
with:
files: .
config_file: .markdownlint.yaml
flake8:
name: Style check (Python)
runs-on: ubuntu-latest
container:
image: python:3.10
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install additional packages
run: |
set -ex
pip install -U pip wheel setuptools
pip install flake8
- name: Run Flake8
run: flake8 tests/test.py
pytype:
name: Type check (Python)
needs:
- flake8
runs-on: ubuntu-latest
container:
image: python:3.10
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install additional packages
run: |
set -ex
pip install -U pip wheel setuptools
pip install -r tests/requirements.txt
pip install pytype libcst==1.2.0
- name: Run Pytype
run: pytype tests/test.py
build-docker-image:
name: Build Docker image
needs:
- spacecheck
- shellcheck
- luacheck
- markdownlint
- pytype
strategy:
fail-fast: true
matrix:
texlive:
- TL2022-historic
- TL2023-historic
- latest
# Only test latest TeX Live in pull requests.
is_pr:
- ${{ github.event_name == 'pull_request_target' }}
exclude:
- { is_pr: true }
include:
- { texlive: latest }
outputs:
TL2022-historic: ${{ steps.temporary-tags.outputs.TL2022-historic }}
TL2023-historic: ${{ steps.temporary-tags.outputs.TL2023-historic }}
latest: ${{ steps.temporary-tags.outputs.latest }}
runs-on: ubuntu-latest
permissions:
packages: write
env:
DOCKER_TEXLIVE_TAG: ${{ matrix.texlive }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
- name: Build Docker image
run: make docker-image
- name: Login to GitHub Packages
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Publish Docker image with a temporary tag
run: make docker-push-temporary-tag
- name: Store the temporary tag
id: temporary-tags
run: |
set -ex
TEMPORARY_TAG="$(make docker-print-temporary-tag)"
echo "${{ matrix.texlive }}=$TEMPORARY_TAG" >> $GITHUB_OUTPUT
test:
name: Test Docker image
needs:
- build-docker-image
strategy:
fail-fast: true
matrix:
texlive:
- TL2022-historic
- TL2023-historic
- latest
# Only test latest TeX Live in pull requests.
is_pr:
- ${{ github.event_name == 'pull_request_target' }}
exclude:
- { is_pr: true }
include:
- { texlive: latest }
runs-on: self-hosted
container:
image: ghcr.io/witiko/markdown:${{ needs.build-docker-image.outputs[matrix.texlive] }}
if: ${{ !contains(inputs.runTests, 'false') }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
- name: Set safe Git directory
# This should have been done by the previous step.
# See also: <https://github.com/actions/checkout/issues/915>.
run: |
git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Test Lua command-line interface
run: |
set -ex
RESULT="$(printf '%s\n' 'Hello *Markdown*! $a_x + b_x = c_x$' | markdown-cli hybrid=true underscores=false)"
test "$RESULT" = '\markdownRendererDocumentBegin
Hello \markdownRendererEmphasis{Markdown}! $a_x + b_x = c_x$\markdownRendererDocumentEnd'
- name: Run tests
if: matrix.texlive == 'latest' || github.event_name != 'pull_request_target' || github.event.pull_request.draft == false
run: make FAIL_FAST=${{ github.event_name == 'pull_request_target' }} test
publish-docker-image:
name: Publish Docker image
needs:
- build-docker-image
- test
strategy:
fail-fast: true
matrix:
texlive:
- TL2022-historic
- TL2023-historic
- latest
# Only test latest TeX Live in pull requests.
is_pr:
- ${{ github.event_name == 'pull_request_target' }}
exclude:
- { is_pr: true }
include:
- { texlive: latest }
runs-on: ubuntu-latest
if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main' && always() && (needs.test.result == 'success' || needs.test.result == 'skipped')
env:
DOCKER_TEXLIVE_TAG: ${{ matrix.texlive }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Publish Docker image
run: make docker-push-release-tag
publish-artefacts:
name: Publish artefacts and create a prerelease
needs:
- build-docker-image
- test
strategy:
fail-fast: true
matrix:
texlive:
- TL2022-historic
- TL2023-historic
- latest
# Only test latest TeX Live in pull requests.
is_pr:
- ${{ github.event_name == 'pull_request_target' }}
exclude:
- { is_pr: true }
include:
- { texlive: latest }
runs-on: ubuntu-latest
permissions:
contents: write
container:
image: ghcr.io/witiko/markdown:${{ needs.build-docker-image.outputs[matrix.texlive] }}
if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/main' && always() && (needs.test.result == 'success' || needs.test.result == 'skipped')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build distribution archives
if: matrix.texlive == 'latest'
run: |
set -ex
chown -R root:root .
make dist gh-pages
- name: Upload artifact markdown.tds.zip
if: matrix.texlive == 'latest'
uses: actions/upload-artifact@v4
with:
name: markdown.tds.zip
path: markdown.tds.zip
- name: Upload artifact markdown.ctan.zip
if: matrix.texlive == 'latest'
uses: actions/upload-artifact@v4
with:
name: markdown.ctan.zip
path: markdown.ctan.zip
- name: Upload artifact markdown.zip
if: matrix.texlive == 'latest'
uses: actions/upload-artifact@v4
with:
name: markdown.zip
path: markdown.zip
- name: Upload artifact markdown.pdf
if: matrix.texlive == 'latest'
uses: actions/upload-artifact@v4
with:
name: markdown.pdf
path: markdown.pdf
- name: Publish user manual
if: matrix.texlive == 'latest'
uses: crazy-max/ghaction-github-pages@v4
with:
target_branch: gh-pages
build_dir: gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create a prerelease
if: matrix.texlive == 'latest'
uses: marvinpinto/action-automatic-releases@latest
with:
title: The latest version
automatic_release_tag: latest
prerelease: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
files: |
markdown.tds.zip
markdown.ctan.zip
markdown.zip
markdown.pdf
automerge:
name: Automatically merge pull request
needs:
- test
runs-on: ubuntu-latest
permissions:
contents: write
if: github.event_name == 'pull_request_target' && github.event.pull_request.draft == false && always() && (needs.test.result == 'success' || needs.test.result == 'skipped')
steps:
- name: Automatically merge pull request
uses: pascalgn/[email protected]
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"