From fb892d5553e92940c904b5e86b12a89527a2ae14 Mon Sep 17 00:00:00 2001 From: Charles Baynham Date: Fri, 17 Jan 2025 12:17:47 +0000 Subject: [PATCH] Build all years in the github pipeline Also provide individual years as nix outputs, for local building using e.g. `nix build .#pdf-2025` --- .github/workflows/build.yml | 33 ++++++++-------- flake.nix | 77 ++++++++++++++++++++++++++++--------- 2 files changed, 75 insertions(+), 35 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9b61ef5b..09c7bdc5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/flake.nix b/flake.nix index 6a92db38..e18029f9 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,7 @@ ; }) ]; + in rec { @@ -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/. + ''; + }; + }; } ); }