Skip to content

Commit

Permalink
Build all years in the github pipeline (#148)
Browse files Browse the repository at this point in the history
Alter `flake.nix` and GitHub Actions to automatically build all years
from 2025 to 2030 in the cloud when commits are made.
  • Loading branch information
kudrykv authored Jan 20, 2025
2 parents f3f1da6 + fb892d5 commit c46e7f6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 35 deletions.
33 changes: 17 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: "Build 2023"
name: "Build all PDFs"
on:
pull_request:
push:
jobs:
build:
build-pdfs:
runs-on: ubuntu-latest
strategy:
matrix:
build-output: ["pdf-all", "pdf-next"]
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v19
- name: Build PDFs
run: nix build
- name: Copy PDFs
run: cp result/*.pdf .
- name: Output PDFs
uses: actions/upload-artifact@v3
with:
name: result
path: ./*.pdf
if-no-files-found: error

- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v19
- name: Build PDFs
run: nix build .#${{ matrix.build-output }}
- name: Copy PDFs
run: cp result/*.pdf .
- name: Output PDFs
uses: actions/upload-artifact@v3
with:
name: result
path: ./*.pdf
if-no-files-found: error
77 changes: 58 additions & 19 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
;
})
];

in
rec
{
Expand All @@ -65,27 +66,65 @@
] ++ goDeps ++ texDeps;
};

defaultPackage = pdfs;
defaultPackage = packages.pdf-next;

pdfs = pkgs.stdenv.mkDerivation
{
name = "pdfs";
# Minimal set of dependencies to build the pdfs
# Latex, "rev" and the built plannergen binary
buildInputs = texDeps ++ [ plannergen ];
PLANNER_YEAR = 2023;
src = "${self}";
buildCommand = ''
cp -r $src/* .
patchShebangs .
chmod -R 770 *
chmod +x *.sh
PLANNERGEN_BINARY=plannergen eval $PWD/build.sh
mkdir $out
cp *.pdf $out/.
'';
};
packages =
let
# Next year, as a string
next-year = builtins.readFile (
pkgs.stdenv.mkDerivation {
name = "current-year";
buildInputs = [ pkgs.coreutils ];
buildCommand = ''
date -d "+1 year" +%Y > $out
'';
});

# List of years to always build
build-years = [
"2025"
"2026"
"2027"
"2028"
"2029"
"2030"
];

# Function that, given a year, builds a pdf for it
make-PDF = year: pkgs.stdenv.mkDerivation
{
name = "pdfs";
# Minimal set of dependencies to build the pdfs:
# Latex and the built plannergen binary
buildInputs = texDeps ++ [ plannergen ];
src = "${self}";
buildCommand = ''
cp -r $src/* .
patchShebangs .
chmod -R 770 *
chmod +x *.sh
PLANNERGEN_BINARY=plannergen eval $PWD/build.sh ${year}
mkdir $out
cp *.pdf $out/.
'';
};

list-of-pdfs = map (y: { name = "pdf-${y}"; value = make-PDF y; }) build-years;
in
builtins.listToAttrs list-of-pdfs
// {
# Append next year's pdf which is the default output
pdf-next = make-PDF next-year;

# Also output all pdfs in the same derivation for the GitHub action
pdf-all = pkgs.stdenv.mkDerivation {
name = "all-pdfs";
buildCommand = ''
mkdir $out
cp -r ${builtins.concatStringsSep " " (map (x: "${x.value}/*" ) list-of-pdfs)} $out/.
'';
};
};
}
);
}

0 comments on commit c46e7f6

Please sign in to comment.