From 829e83af9c942ffbba32cf78c4275bf06d79f0ff Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 30 Dec 2024 12:16:26 +0100 Subject: [PATCH] feat: Add local workflow --- .forgejo/workflows/pre-commit.yaml | 12 ++++++ REUSE.toml | 2 +- default.nix | 66 +++++++++++++++++++++++------- 3 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 .forgejo/workflows/pre-commit.yaml diff --git a/.forgejo/workflows/pre-commit.yaml b/.forgejo/workflows/pre-commit.yaml new file mode 100644 index 0000000..2ba0ff4 --- /dev/null +++ b/.forgejo/workflows/pre-commit.yaml @@ -0,0 +1,12 @@ +jobs: + pre-push: + runs-on: nix + steps: + - uses: actions/checkout@v3 + - name: Run pre-commit on all files + run: nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage + pre-push --show-diff-on-failure' +name: Run pre-commit on all files +'on': +- pull_request +- push diff --git a/REUSE.toml b/REUSE.toml index dd915b3..485719e 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -2,7 +2,7 @@ version = 1 [[annotations]] SPDX-FileCopyrightText = "NONE" SPDX-License-Identifier = "CC0-1.0" -path = [".envrc", ".gitignore", "shell.nix"] +path = [".envrc", ".forgejo/workflows/*.yaml", ".gitignore", "shell.nix"] precedence = "closest" [[annotations]] diff --git a/default.nix b/default.nix index 647709e..ad3e003 100644 --- a/default.nix +++ b/default.nix @@ -8,7 +8,9 @@ }: let - inherit (pkgs) lib mkShell; + inherit (pkgs) mkShell; + + inherit (pkgs.lib) evalModules getExe recursiveUpdate; inherit (pkgs.lib.fileset) gitTracked toSource; @@ -52,6 +54,7 @@ let generatedPaths = [ ".envrc" + ".forgejo/workflows/*.yaml" ".gitignore" "shell.nix" ]; @@ -65,24 +68,11 @@ let } ]; }; -in - -{ - devShell = mkShell { - name = "nix-actions.dev"; - - packages = git-checks.enabledPackages; - - shellHook = builtins.concatStringsSep "\n" [ - git-checks.shellHook - reuse.shellHook - ]; - }; install = { src, ... }@config: let - project = lib.evalModules { + project = evalModules { modules = [ ./modules { @@ -107,6 +97,52 @@ in }; }; + workflows = install { + src = ./.; + + buildCheck = false; + + workflows.pre-commit = { + name = "Run pre-commit on all files"; + on = [ + "pull_request" + "push" + ]; + + jobs.pre-push = { + runs-on = "nix"; + steps = [ + { uses = "actions/checkout@v3"; } + { + name = "Run pre-commit on all files"; + run = "nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage pre-push --show-diff-on-failure'"; + } + ]; + }; + }; + }; +in + +{ + devShell = mkShell { + name = "nix-actions.dev"; + + packages = git-checks.enabledPackages; + + shellHook = builtins.concatStringsSep "\n" [ + git-checks.shellHook + reuse.shellHook + workflows.shellHook + ]; + + passthru.pre-commit = mkShell { + name = "pre-commit"; + inherit (git-checks) shellHook; + }; + }; + + inherit install; + lib = rec { expr = repr: "\${{ ${repr} }}"; secret = name: expr "secrets.${name}";