feat: Add git-hooks.nix
All checks were successful
Run pre-commit on all files / pre-commit (push) Successful in 20s
Run pre-commit on all files / pre-commit (pull_request) Successful in 20s
Check for missing migrations / migrations_check (pull_request) Successful in 1m35s

This commit is contained in:
Tom Hubrecht 2025-01-12 11:12:55 +01:00
parent 91613e1d65
commit d1fe524333
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc
6 changed files with 80 additions and 13 deletions

11
.flake8
View file

@ -8,14 +8,3 @@ ignore =
E731, E731,
# line break before binary operator (not PEP8-compliant) # line break before binary operator (not PEP8-compliant)
W503 W503
[isort]
# For black compat: https://github.com/ambv/black#how-black-wraps-lines
combine_as_imports = true
default_section = THIRDPARTY
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = bda,bds,clubs,cof,events,gestioncof,kfet,petitscours,shared
line_length = 88
multi_line_output = 3
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

View file

@ -0,0 +1,15 @@
jobs:
pre-commit:
runs-on: nix
steps:
- uses: actions/checkout@v3
- name: Check stage pre-commit
run: nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage
pre-commit --show-diff-on-failure'
- name: Check stage pre-push
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':
- push
- pull_request

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ media/
# VSCode # VSCode
.vscode/ .vscode/
.direnv .direnv
.pre-commit-config.yaml

View file

@ -7,7 +7,13 @@ let
### ###
# Pkgs configuration # Pkgs configuration
inherit (pkgs.lib) mapAttrs' nameValuePair removeSuffix; inherit (pkgs.lib)
genAttrs
mapAttrs
mapAttrs'
nameValuePair
removeSuffix
;
nix-pkgs = import sources.nix-pkgs { inherit pkgs; }; nix-pkgs = import sources.nix-pkgs { inherit pkgs; };
kat-pkgs = import sources.kat-pkgs { inherit pkgs; }; kat-pkgs = import sources.kat-pkgs { inherit pkgs; };
@ -50,11 +56,20 @@ let
) )
) (builtins.readDir ./workflows); ) (builtins.readDir ./workflows);
}; };
git-hooks = (import sources.git-hooks).run {
src = ./.;
hooks = genAttrs [ "black" "isort" "commitizen" ] (_: {
enable = true;
});
};
in in
{ {
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
shellHook = '' shellHook = ''
${git-hooks.shellHook}
${workflows.shellHook} ${workflows.shellHook}
if [ ! -d .static ]; then if [ ! -d .static ]; then
mkdir .static mkdir .static
@ -104,6 +119,12 @@ in
] ]
)) ))
pkgs.npins pkgs.npins
]; ] ++ git-hooks.enabledPackages;
passthru = mapAttrs (name: value: pkgs.mkShell (value // { inherit name; })) {
pre-commit.shellHook = git-hooks.shellHook;
};
}; };
preferLocalBuild = true;
} }

View file

@ -1,5 +1,17 @@
{ {
"pins": { "pins": {
"git-hooks": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "cachix",
"repo": "git-hooks.nix"
},
"branch": "master",
"revision": "a5a961387e75ae44cc20f0a57ae463da5e959656",
"url": "https://github.com/cachix/git-hooks.nix/archive/a5a961387e75ae44cc20f0a57ae463da5e959656.tar.gz",
"hash": "0pfpiz3z2l5l3h9ml1z75zn11jbq2qhb1ph8jn277ds6x8dl0mnw"
},
"kat-pkgs": { "kat-pkgs": {
"type": "Git", "type": "Git",
"repository": { "repository": {

29
workflows/pre-commit.nix Normal file
View file

@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{ ... }:
{
name = "Run pre-commit on all files";
on = [
"push"
"pull_request"
];
jobs.pre-commit = {
runs-on = "nix";
steps =
[ { uses = "actions/checkout@v3"; } ]
++ (builtins.map
(stage: {
name = "Check stage ${stage}";
run = "nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage ${stage} --show-diff-on-failure'";
})
[
"pre-commit"
"pre-push"
]
);
};
}