feat: Add git-hooks.nix
This commit is contained in:
parent
91613e1d65
commit
d1fe524333
6 changed files with 80 additions and 13 deletions
11
.flake8
11
.flake8
|
@ -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
|
|
||||||
|
|
15
.forgejo/workflows/pre-commit.yaml
Normal file
15
.forgejo/workflows/pre-commit.yaml
Normal 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
1
.gitignore
vendored
|
@ -21,3 +21,4 @@ media/
|
||||||
# VSCode
|
# VSCode
|
||||||
.vscode/
|
.vscode/
|
||||||
.direnv
|
.direnv
|
||||||
|
.pre-commit-config.yaml
|
||||||
|
|
25
default.nix
25
default.nix
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
29
workflows/pre-commit.nix
Normal 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"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue