Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/latexmk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ jobs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
- run: make test-download
- run: wget -O molot-regular.ttf https://www.yegor256.com/fonts/molot/molot-regular.ttf
- run: make test-download test-assets molot-regular.ttf logo.svg palette.tex
- uses: yegor256/latexmk-action@0.20.0
with:
opts: -pdf
opts: -pdf brand-book.tex
debs: fonts-noto-core fonts-noto-extra fonts-paratype
depends: DEPENDS.txt
- uses: actions/upload-artifact@v7
Expand Down
35 changes: 32 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
.SHELLFLAGS=-e -o pipefail -c
.ONESHELL:
SHELL=bash
.PHONY: all test test-download clean
.PHONY: all test test-download test-assets clean FORCE

all: brand-book.pdf

test: test-download brand-book.pdf
test: test-download test-assets brand-book.pdf
texsc brand-book.tex
texqc brand-book

test-assets:
bash test-assets.sh

test-download:
bash test-font-download.sh Makefile

Expand All @@ -21,8 +24,34 @@ molot-regular.ttf:
wget -O "$$tmp" https://www.yegor256.com/fonts/molot/$@
mv "$$tmp" "$@"

brand-book.pdf: brand-book.tex molot-regular.ttf .latexmkrc
logo.svg: FORCE
temp=$$(mktemp "$@.XXXXXX")
trap 'rm -f "$${temp}"' EXIT
wget --quiet -O "$${temp}" https://www.zerocracy.com/svg/logo.svg
if ! cmp -s "$${temp}" "$@"; then
mv "$${temp}" "$@"
fi

palette.css: FORCE
temp=$$(mktemp "$@.XXXXXX")
trap 'rm -f "$${temp}"' EXIT
wget --quiet -O "$${temp}" https://www.zerocracy.com/css/palette.css
if ! cmp -s "$${temp}" "$@"; then
mv "$${temp}" "$@"
fi

palette.tex: palette.css Makefile
temp=$$(mktemp "$@.XXXXXX")
trap 'rm -f "$${temp}"' EXIT
grep -oE '\.[a-zA-Z0-9_-]+\{color:.[0-9a-fA-F]+' < "$<" | sed -E 's/\.([a-zA-Z0-9_-]+)\{color:.([0-9a-fA-F]+)/\\definecolor{\1}{HTML}{\2}/' > "$${temp}"
if ! cmp -s "$${temp}" "$@"; then
mv "$${temp}" "$@"
fi

brand-book.pdf: brand-book.tex molot-regular.ttf .latexmkrc logo.svg palette.tex
latexmk -pdf -latexoption=-interaction=nonstopmode -latexoption=-halt-on-error $<

FORCE:

clean:
git clean -dfX
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ To build it, just run:
make
```

Make refreshes `logo.svg` and `palette.css` from the Zerocracy website and
generates `palette.tex` before checking whether the PDF needs rebuilding.
Unchanged files keep their timestamps.

You need to have
[`latexmk`](https://ctan.org/pkg/latexmk),
[`inkscape`](https://inkscape.org/),
Expand All @@ -34,3 +38,5 @@ Ruby, and the
[`texsc`](https://rubygems.org/gems/texsc)
and
[`texqc`](https://rubygems.org/gems/texqc) gems.

The asset refresh regressions can also run without LaTeX: `make test-assets`.
4 changes: 0 additions & 4 deletions brand-book.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
\usepackage{booktabs}
\usepackage{csquotes}
\usepackage{textcomp}
\usepackage{iexec}
\iexec[quiet,log]{wget -nc --quiet https://www.zerocracy.com/svg/logo.svg}
\usepackage{href-ul}
\usepackage{svg}
\usepackage{multicol}
Expand All @@ -19,8 +17,6 @@
\usepackage{hyperref}
\hypersetup{colorlinks=true,allcolors=blue}
\usepackage{xcolor}
\iexec[quiet,log]{wget --quiet --no-clobber https://www.zerocracy.com/css/palette.css}
\iexec{grep -oE '\\.[a-zA-Z0-9_-]+\\\{color:.[0-9a-fA-F]+' < palette.css | sed -E 's/\\.([a-zA-Z0-9_-]+)\\\{color:.([0-9a-fA-F]+)/\\\\definecolor\{\\1\}\{HTML\}\{\\2\}/' > palette.tex}
\input{palette.tex}
\usepackage{graphicx}
\newfontfamily\molotFont{Molot}[
Expand Down
127 changes: 127 additions & 0 deletions test-assets.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env bash
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 Zerocracy
# SPDX-License-Identifier: MIT
set -euo pipefail

root=$(cd "$(dirname "$0")" && pwd)
fixture=$(mktemp -d)
trap 'rm -rf "${fixture}"' EXIT
cp "${root}/Makefile" "${fixture}/Makefile"
mkdir "${fixture}/bin"
cat > "${fixture}/bin/wget" <<'WGET'
#!/usr/bin/env bash
set -euo pipefail
output=''
while [ "$#" -gt 0 ]; do
case "$1" in
-O) output=$2; shift 2 ;;
--quiet) shift ;;
https://*) url=$1; shift ;;
*) exit 2 ;;
esac
done
asset=${url##*/}
printf '%s\n' "${asset}" >> downloads.txt
if [ "${FAIL_DOWNLOAD:-}" = "${asset}" ]; then
printf 'partial download' > "${output}"
exit 8
fi
case "${asset}" in
logo.svg|palette.css) cp "${REMOTE}/${asset}" "${output}" ;;
molot-regular.ttf) printf 'test font' > "${output}" ;;
*) exit 2 ;;
esac
WGET
cat > "${fixture}/bin/latexmk" <<'LATEXMK'
#!/usr/bin/env bash
set -euo pipefail
source=${!#}
printf '%s\n' "${source}" >> builds.txt
cat logo.svg palette.tex > "${source%.tex}.pdf"
LATEXMK
chmod +x "${fixture}/bin/wget" "${fixture}/bin/latexmk"
export PATH="${fixture}/bin:${PATH}"
export REMOTE="${fixture}/remote"
mkdir "${REMOTE}"
cd "${fixture}"
pdfs=(brand-book.pdf)
touch molot-regular.ttf
touch -t 200001010000 .latexmkrc

check_pdfs() {
cat logo.svg palette.tex > expected.pdf
for pdf in "${pdfs[@]}"; do
cmp expected.pdf "${pdf}"
done
}

printf 'old logo' > logo.svg
printf '.steel{color:#010203}\n' > palette.css
printf '\\definecolor{steel}{HTML}{010203}\n' > palette.tex
touch -t 200001010000 logo.svg palette.css palette.tex molot-regular.ttf Makefile
for pdf in "${pdfs[@]}"; do
touch -t 200001010000 "${pdf%.pdf}.tex"
printf 'old PDF' > "${pdf}"
touch -t 200001010001 "${pdf}"
done
printf 'first remote logo' > "${REMOTE}/logo.svg"
printf '.steel{color:#A1b2C3}\n.red{color:#112233}\n' > "${REMOTE}/palette.css"
make --no-print-directory -j2 all
cmp "${REMOTE}/logo.svg" logo.svg
printf '\\definecolor{steel}{HTML}{A1b2C3}\n\\definecolor{red}{HTML}{112233}\n' > expected.tex
cmp expected.tex palette.tex
check_pdfs
test "$(wc -l < builds.txt)" -eq "${#pdfs[@]}"
test "$(grep -c '^logo.svg$' downloads.txt)" -eq 1
test "$(grep -c '^palette.css$' downloads.txt)" -eq 1

for asset in logo.svg palette.css palette.tex; do
touch -r "${asset}" "${asset}.timestamp"
done
make --no-print-directory all
for asset in logo.svg palette.css palette.tex; do
test ! "${asset}" -nt "${asset}.timestamp"
test ! "${asset}.timestamp" -nt "${asset}"
done
test "$(wc -l < builds.txt)" -eq "${#pdfs[@]}"

printf '.steel{color:#445566}\n' > "${REMOTE}/palette.css"
make --no-print-directory all
printf '\\definecolor{steel}{HTML}{445566}\n' > expected.tex
cmp expected.tex palette.tex
check_pdfs
test "$(wc -l < builds.txt)" -eq "$((2 * ${#pdfs[@]}))"
printf 'updated remote logo' > "${REMOTE}/logo.svg"
make --no-print-directory all
check_pdfs
test "$(wc -l < builds.txt)" -eq "$((3 * ${#pdfs[@]}))"

for asset in logo.svg palette.css; do
if FAIL_DOWNLOAD=${asset} make --no-print-directory all; then
echo "A failed ${asset} download must fail the build" >&2
exit 1
fi
cmp "${REMOTE}/${asset}" "${asset}"
check_pdfs
test "$(wc -l < builds.txt)" -eq "$((3 * ${#pdfs[@]}))"
test -z "$(find . -name "${asset}.??????" -print)"
done

printf 'invalid palette' > "${REMOTE}/palette.css"
if make --no-print-directory all; then
echo 'A palette without color definitions must fail the build' >&2
exit 1
fi
cmp expected.tex palette.tex
check_pdfs
test "$(wc -l < builds.txt)" -eq "$((3 * ${#pdfs[@]}))"
test -z "$(find . -name 'palette.tex.??????' -print)"

printf '.steel{color:#445566}\n' > "${REMOTE}/palette.css"
rm logo.svg palette.css palette.tex molot-regular.ttf
make --no-print-directory molot-regular.ttf logo.svg palette.tex
cmp "${REMOTE}/logo.svg" logo.svg
cmp expected.tex palette.tex
test -s molot-regular.ttf
test "$(wc -l < builds.txt)" -eq "$((3 * ${#pdfs[@]}))"
echo 'PASS: remote assets refresh, unchanged content skips rebuild, failures preserve generated output, CI assets prepare without LaTeX'
Loading