tests #3168
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: tests | |
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: make check-tabs-and-spaces | |
linelength: | |
name: Style check (Line length) | |
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 scripts | |
run: make base | |
- name: Check the line length | |
run: make check-line-length | |
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 | |
- linelength | |
- shellcheck | |
- luacheck | |
- markdownlint | |
- pytype | |
strategy: | |
fail-fast: true | |
matrix: | |
texlive: | |
- 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: | |
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: | |
- 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: ${{ github.event_name == 'pull_request_target' && 'self-hosted' || 'ubuntu-latest' }} | |
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 | |
printf '%s\n' 'Hello *Markdown*! $a_x + b_x = c_x$' | bash -c 'time markdown-cli texMathDollars=true' 1>stdout 2>stderr | |
test "$(cat stdout)" = '\markdownRendererDocumentBegin | |
Hello \markdownRendererEmphasis{Markdown}! \markdownRendererInlineMath{a_x + b_x = c_x}\markdownRendererDocumentEnd' # Check that the output is correct. | |
grep 'real\s*0m[01]' stderr # Check that the command finishes in less than a second. | |
- 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: | |
- 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: | |
- 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 }}" |