From 0cc5b28a6263347b336709d1bb86cd1f594815d3 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Tue, 16 Apr 2024 07:53:31 -0700 Subject: [PATCH] feat(ci): check for barcodebuddy updates --- .github/workflows/flake-update.yml | 52 ++++++++++++++++++++++++++++++ ci/flake-cron.nix | 45 +++++++++++++++++++++++++- nixos/base/nix.nix | 3 +- packages/barcodebuddy.nix | 3 +- 4 files changed, 100 insertions(+), 3 deletions(-) diff --git a/.github/workflows/flake-update.yml b/.github/workflows/flake-update.yml index fb08a2ae..d1e00287 100644 --- a/.github/workflows/flake-update.yml +++ b/.github/workflows/flake-update.yml @@ -4,6 +4,58 @@ env: CI_CONFIG: ./ci/flake-cron.nix CI_PLATFORM: gh-actions jobs: + barcodebuddy-update: + name: barcodebuddy update check + runs-on: ubuntu-latest + steps: + - id: checkout + name: git clone + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: false + - id: nix-install + name: nix install + uses: arcnmx/ci/actions/nix/install@v0.7 + - id: ci-dirty + name: nix test dirty + uses: arcnmx/ci/actions/nix/run@v0.7 + with: + attrs: ci.job.barcodebuddy-update.run.test + command: ci-build-dirty + quiet: false + stdout: ${{ runner.temp }}/ci.build.dirty + - id: ci-test + name: nix test build + uses: arcnmx/ci/actions/nix/run@v0.7 + with: + attrs: ci.job.barcodebuddy-update.run.test + command: ci-build-realise + ignore-exit-code: true + quiet: false + stdin: ${{ runner.temp }}/ci.build.dirty + - env: + CI_EXIT_CODE: ${{ steps.ci-test.outputs.exit-code }} + id: ci-summary + name: nix test results + uses: arcnmx/ci/actions/nix/run@v0.7 + with: + attrs: ci.job.barcodebuddy-update.run.test + command: ci-build-summarise + quiet: false + stdin: ${{ runner.temp }}/ci.build.dirty + stdout: ${{ runner.temp }}/ci.build.cache + - env: + CACHIX_SIGNING_KEY: ${{ secrets.CACHIX_SIGNING_KEY }} + id: ci-cache + if: always() + name: nix test cache + uses: arcnmx/ci/actions/nix/run@v0.7 + with: + attrs: ci.job.barcodebuddy-update.run.test + command: ci-build-cache + quiet: false + stdin: ${{ runner.temp }}/ci.build.cache ci-check: name: flake-update check runs-on: ubuntu-latest diff --git a/ci/flake-cron.nix b/ci/flake-cron.nix index 3ca5abe9..9f5e32a3 100644 --- a/ci/flake-cron.nix +++ b/ci/flake-cron.nix @@ -6,6 +6,7 @@ }: with lib; let gitBranch = "main"; + pkgs = channels.nixpkgs; in { name = "flake-update"; @@ -67,7 +68,49 @@ in { nixpkgs.path = "${channels.nixfiles.inputs.nixpkgs}"; }; - jobs.flake-update = { + jobs = { + flake-update = { + }; + barcodebuddy-update = { + ci.gh-actions.name = "barcodebuddy update check"; + tasks.check = let + barcodebuddy-check = let + lock = importJSON ../flake.lock; + inherit (lock.nodes) barcodebuddy; + inherit (barcodebuddy.original) ref; + impure = toString builtins.currentTime or channels.nixfiles.inputs.sourceInfo.lastModified; + outputHashAlgo = "sha256"; + outputHash = builtins.hashString outputHashAlgo "${ref}!${impure}\n"; + in pkgs.runCommand "barcodebuddy-check-${ref}" { + inherit outputHash outputHashAlgo impure ref; + outputHashMode = "flat"; + preferLocalBuild = true; + allowSubstitutes = false; + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "NIX_CURL_FLAGS" ]; + nativeBuildInputs = with pkgs.buildPackages; [ curl jq ]; + inherit (barcodebuddy.original) owner repo; + query = "sort_by(.tag_name) | [.[]|select(.prerelease==false and .draft==false)] | .[-1].tag_name"; + meta.displayName = "barcodebuddy ${ref} outdated"; + } '' + BB_RELEASES=$(curl \ + --insecure \ + -fSsL \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/$owner/$repo/releases" + ) + BB_LATEST=$(jq -r "$query" - <<< "$BB_RELEASES") + if [[ $BB_LATEST = $ref ]]; then + echo "barcodebuddy-$ref up-to-date" >&2 + else + echo "barcodebuddy-$ref out of date, found version $BB_LATEST" >&2 + fi + printf '%s!%s\n' "$BB_LATEST" "$impure" > $out + ''; + in { + inputs = [ barcodebuddy-check ]; + cache.enable = false; + }; + }; }; ci.gh-actions.checkoutOptions = { diff --git a/nixos/base/nix.nix b/nixos/base/nix.nix index 5d165a53..26b962a8 100644 --- a/nixos/base/nix.nix +++ b/nixos/base/nix.nix @@ -9,6 +9,7 @@ inherit (gensokyo-zone.lib) mkAlmostDefault; inherit (lib.modules) mkIf mkDefault; inherit (lib.attrsets) optionalAttrs; + inherit (lib.trivial) importJSON; hasSops = options ? sops; in { config = { @@ -19,7 +20,7 @@ in { nix = { registry = let - lock = builtins.fromJSON (builtins.readFile ../../flake.lock); + lock = importJSON ../../flake.lock; mapFlake = name: let node = lock.nodes.${name}; in { diff --git a/packages/barcodebuddy.nix b/packages/barcodebuddy.nix index a09bbe9d..ec9a889f 100644 --- a/packages/barcodebuddy.nix +++ b/packages/barcodebuddy.nix @@ -5,7 +5,8 @@ ... }: let inherit (lib.strings) removePrefix; - lock = builtins.fromJSON (builtins.readFile ../flake.lock); + inherit (lib.trivial) importJSON; + lock = importJSON ../flake.lock; inherit (lock.nodes) barcodebuddy; in stdenvNoCC.mkDerivation { pname = "barcodebuddy";