Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .conform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ policies:
- style
- test
scopes:
- extra
- github
- gitlab
- job
Expand Down
56 changes: 55 additions & 1 deletion dev/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
};

perSystem =
{ pkgs, ... }:
{ config, pkgs, ... }:
{
pre-commit.check.enable = false;
pre-commit.settings.hooks = {
Expand Down Expand Up @@ -117,6 +117,60 @@
};
};

checks.git-hooks =
let
inherit (config.pre-commit.settings) hooks;
gh = hooks.first-ci-kit-gen-github-actions;
gl = hooks.first-ci-kit-gen-gitlab-ci;

tests = {
"github-actions: default pipelines" = {
check = gh.settings.pipelines.default == ".github/workflows/ci.yaml";
};

"gitlab-ci: default pipelines" = {
check = gl.settings.pipelines.default == ".gitlab-ci.yml";
};

"github-actions: hook name" = {
check = gh.name == "generate-github-actions";
};

"gitlab-ci: hook name" = {
check = gl.name == "generate-gitlab-ci";
};

"github-actions: pass_filenames is false" = {
check = !gh.pass_filenames;
};

"gitlab-ci: pass_filenames is false" = {
check = !gl.pass_filenames;
};
};
in
pkgs.runCommand "test-git-hooks" { } (
''
set -e
''
+ lib.concatStrings (
lib.mapAttrsToList (
name:
{ check }:
if check then
""
else
''
echo "FAILED: ${name}"
exit 1
''
) tests
)
+ ''
echo "All git-hooks tests passed" > $out
''
);

packages.module-docs = pkgs.callPackage ../packages/module-docs {
moduleRoot = ../module;
};
Expand Down
80 changes: 42 additions & 38 deletions extra/git-hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ let
}:
let
writePipelineGenerator =
{ name, hook }:
{ backend, pipelines }:
pkgs.writeShellApplication {
name = "generate-${name}";
name = "generate-${backend}";
runtimeInputs = [ pkgs.yq-go ];
text = ''
out="$(nix build --extra-experimental-features 'nix-command flakes' \
--print-out-paths \
.#ci-pipeline-${name}-${hook.settings.pipeline}
)"
text =
let
generatePipeline = name: outputPath: ''
out="$(nix build --extra-experimental-features 'nix-command flakes' \
--print-out-paths \
.#ci-pipeline-${backend}-${name}
)"

mkdir -p "$(dirname "${hook.settings.outputPath}")"
yq --prettyPrint --output-format yaml "$out" > "${hook.settings.outputPath}"
'';
mkdir -p "$(dirname "${outputPath}")"
yq --prettyPrint --output-format yaml "$out" > "${outputPath}"
'';
in
lib.concatStringsSep "\n" (lib.mapAttrsToList generatePipeline pipelines);
};
in
{
Expand All @@ -34,18 +38,18 @@ let
type = types.submodule {
imports = [ hookModule ];
options.settings = {
pipeline = lib.mkOption {
type = types.str;
description = "The pipeline to generate.";
default = "default";
example = "pr";
};

outputPath = lib.mkOption {
type = types.str;
description = "The path of the output file generated.";
default = ".github/workflows/ci.yaml";
example = ".github/workflows/example.yaml";
pipelines = lib.mkOption {
type = types.attrsOf types.str;
default = {
default = ".github/workflows/ci.yaml";
};
description = "Pipeline name to output path mapping.";
example = lib.literalExpression ''
{
default = ".github/workflows/ci.yaml";
nightly = ".github/workflows/nightly.yaml";
}
'';
};
};
};
Expand All @@ -56,18 +60,18 @@ let
type = types.submodule {
imports = [ hookModule ];
options.settings = {
pipeline = lib.mkOption {
type = types.str;
description = "The pipeline to generate.";
default = "default";
example = "pr";
};

outputPath = lib.mkOption {
type = types.str;
description = "The path of the output file generated.";
default = ".gitlab-ci.yml";
example = ".gitlab/ci.yml";
pipelines = lib.mkOption {
type = types.attrsOf types.str;
default = {
default = ".gitlab-ci.yml";
};
description = "Pipeline name to output path mapping.";
example = lib.literalExpression ''
{
default = ".gitlab-ci.yml";
pr = ".gitlab/ci-pr.yml";
}
'';
};
};
};
Expand All @@ -79,8 +83,8 @@ let
name = "generate-github-actions";
description = "generate GitHub Actions workflow";
package = writePipelineGenerator {
name = "github-actions";
hook = config.hooks.first-ci-kit-gen-github-actions;
backend = "github-actions";
inherit (config.hooks.first-ci-kit-gen-github-actions.settings) pipelines;
};
entry = "${config.hooks.first-ci-kit-gen-github-actions.package}/bin/generate-github-actions";
files = lib.mkDefault "\\.nix$";
Expand All @@ -91,8 +95,8 @@ let
name = "generate-gitlab-ci";
description = "generate GitLab CI pipeline";
package = writePipelineGenerator {
name = "gitlab-ci";
hook = config.hooks.first-ci-kit-gen-gitlab-ci;
backend = "gitlab-ci";
inherit (config.hooks.first-ci-kit-gen-gitlab-ci.settings) pipelines;
};
entry = "${config.hooks.first-ci-kit-gen-gitlab-ci.package}/bin/generate-gitlab-ci";
files = lib.mkDefault "\\.nix$";
Expand Down