Skip to content

Commit

Permalink
Use Nix for building PDFs. (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol authored Feb 25, 2022
1 parent ff05f34 commit bfe7a1f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 64 deletions.
101 changes: 51 additions & 50 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,50 @@ jobs:
strategy:
matrix:
sources:
- input: ctfp-print.tex
output: ctfp-print.pdf
- input: ctfp-reader.tex
output: ctfp-reader.pdf
- input: ctfp-print-scala.tex
output: ctfp-print-scala.pdf
- input: ctfp-reader-scala.tex
output: ctfp-reader-scala.pdf
- input: ctfp-reader-ocaml.tex
output: ctfp-reader-ocaml.pdf
- input: ctfp-print-ocaml.tex
output: ctfp-print-ocaml.pdf
- input: ctfp-reader-reason.tex
output: ctfp-reader-reason.pdf
- input: ctfp-print-reason.tex
output: ctfp-print-reason.pdf
- input: ctfp
output:
reader: category-theory-for-programmers.pdf
print: category-theory-for-programmers-print.pdf
- input: ctfp-scala
output:
reader: category-theory-for-programmers-scala.pdf
print: category-theory-for-programmers-print-scala.pdf
- input: ctfp-reason
output:
reader: category-theory-for-programmers-reason.pdf
print: category-theory-for-programmers-print-reason.pdf
- input: ctfp-ocaml
output:
reader: category-theory-for-programmers-ocaml.pdf
print: category-theory-for-programmers-print-ocaml.pdf

steps:
- name: Set up Git repository
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Create necessary build file (version.tex)
run: |
echo -n -e "\\\newcommand{\OPTversion}{$(git rev-parse --short HEAD)}" > src/version.tex
- name: Install Nix
uses: cachix/install-nix-action@v16

- name: Build documents using LaTeX (${{ matrix.sources.input }})
uses: xu-cheng/latex-action@v2
with:
working_directory: src
latexmk_use_xelatex: true
root_file: ${{ matrix.sources.input }}
latexmk_shell_escape: true

- name: Upload build assets (${{ matrix.sources.output }})
- name: Build ${{ matrix.sources.input }}
run: |
nix build .#${{ matrix.sources.input }}
mkdir -p out
cp -ar ./result/* out/
- name: Upload build assets (${{ matrix.sources.output.print }})
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.sources.output }}
path: src/${{ matrix.sources.output }}
name: ctfp
path: out/*

release:
name: "Create Github tag/pre-release"
runs-on: ubuntu-latest
needs: [dependencies,build]
needs: [dependencies, build]
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
Expand All @@ -85,39 +86,39 @@ jobs:
assets:
name: Upload release assets
runs-on: ubuntu-latest
needs: [dependencies,release]
needs: [dependencies, release]
strategy:
matrix:
assets:
- source: ctfp-print.pdf
destination: category-theory-for-programmers--print--
- source: ctfp-reader.pdf
destination: category-theory-for-programmers--
- source: ctfp-print-scala.pdf
destination: category-theory-for-programmers--print--scala--
- source: ctfp-reader-scala.pdf
destination: category-theory-for-programmers--reader--scala--
- source: ctfp-print-ocaml.pdf
destination: category-theory-for-programmers--print--ocaml--
- source: ctfp-reader-ocaml.pdf
destination: category-theory-for-programmers--reader--ocaml--
- source: ctfp-print-reason.pdf
destination: category-theory-for-programmers--print--reason--
- source: ctfp-reader-reason.pdf
destination: category-theory-for-programmers--reader--reason--
- source: category-theory-for-programmers-print.pdf
destination: category-theory-for-programmers--print
- source: category-theory-for-programmers.pdf
destination: category-theory-for-programmers
- source: category-theory-for-programmers-print-scala.pdf
destination: category-theory-for-programmers--print--scala
- source: category-theory-for-programmers-scala.pdf
destination: category-theory-for-programmers--reader--scala
- source: category-theory-for-programmers-print-ocaml.pdf
destination: category-theory-for-programmers--print--ocaml
- source: category-theory-for-programmers-ocaml.pdf
destination: category-theory-for-programmers--reader--ocaml
- source: category-theory-for-programmers-print-reason.pdf
destination: category-theory-for-programmers--print--reason
- source: category-theory-for-programmers-reason.pdf
destination: category-theory-for-programmers--reader--reason
steps:
- name: Download build assets (${{ matrix.assets.source }})
uses: actions/download-artifact@v2
with:
name: ${{ matrix.assets.source }}
path: ${{ matrix.assets.source }}
name: ctfp
path: ctfp

- name: Upload release assets (${{ matrix.assets.destination }}${{ needs.dependencies.outputs.version }}.pdf)
- name: Upload release assets (${{ matrix.assets.destination }}--${{ needs.dependencies.outputs.version }}.pdf)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ${{ matrix.assets.source }}/${{ matrix.assets.source }}
asset_name: ${{ matrix.assets.destination }}${{ needs.dependencies.outputs.version }}.pdf
asset_path: ctfp/${{ matrix.assets.source }}
asset_name: ${{ matrix.assets.destination }}--${{ needs.dependencies.outputs.version }}.pdf
asset_content_type: application/pdf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ src/.dotty-ide-disabled
venv/*
.DS_Store
src/.metals
out/
19 changes: 10 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
description = "Category Theory for Programmers";

inputs.nixpkgs.url = "nixpkgs/nixos-20.03";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
inputs.utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, utils }: utils.lib.eachDefaultSystem (system: let
Expand Down Expand Up @@ -129,11 +129,14 @@
editions = [ null "scala" "ocaml" "reason" ];

in {
# Nix build
packages = lib.listToAttrs (map (edition: {
name = mkPackageName edition;
value = mkPackage false edition;
}) editions);

defaultPackage = self.packages.${system}.ctfp;

devShell = mkPackage true null;
});
}
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import
(
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}
).shellNix
8 changes: 4 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

DIR := $(shell pwd)
GIT_VER := $(shell git describe --tags --always --long | tr -d '\n')
OUTPUT_DIR := ../out/$(GIT_VER)
OUTPUT_DIR := ../out

OUTPUT = category-theory-for-programmers

Expand Down Expand Up @@ -33,7 +33,7 @@ OCAMLPDF:=$(OCAMLTEXFILES:.tex=.pdf)
# ReasonML PDF file to make
REASONPDF:=$(REASONTEXFILES:.tex=.pdf)

# Other PDF files for the CTFP book
# Other PDF files for the CTFP book
TOPPDFFILES:=$(TOPTEXFILES:.tex=.pdf)

# Configuration files
Expand All @@ -47,7 +47,7 @@ TEXFILES = $(TOPTEXFILES) $(SCALATEXFILES) $(OCAMLTEXFILES) $(REASONTEXFILES) $(
default: suffix=''
default: out-dir $(DEFAULTPDF) # todo cover

all: clean default scala ocaml
all: clean default scala ocaml reason

scala: suffix='-scala'
scala: clean out-dir version.tex $(SCALAPDF)
Expand Down Expand Up @@ -81,5 +81,5 @@ clean:
if which latexmk > /dev/null 2>&1 ; then latexmk -CA; fi
rm -rf ../out

clean-minted:
clean-minted:
rm -rf _minted-*

0 comments on commit bfe7a1f

Please sign in to comment.