mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2026-06-19 00:29:25 +02:00
feat: auto-generate CI jobs from flake checks
Add `checks` option and `config.autoChecks` to auto-generate a CI job for each flake check derivation. Auto-generated jobs go through `mkJobPatched` for proper Nix setup, cache, and environment handling. The `checks` option is automatically wired to `config.checks` in flake-parts. System is inferred from `pkgs.system` and set via the new `system` option. User-defined jobs with the same name always take precedence. New tests cover both flake-parts and direct API entry points. MT-14138
This commit is contained in:
parent
097f775cff
commit
ab41bc24ec
8 changed files with 388 additions and 5 deletions
|
|
@ -67,6 +67,86 @@ in
|
|||
# exposes `soonix` for the soonix hook and `packages` which contain the configs, jobs etc.
|
||||
```
|
||||
|
||||
## Auto-generate jobs from flake checks
|
||||
|
||||
You can auto-generate CI jobs from your flake checks with the `autoChecks` option.
|
||||
Each check becomes a job that runs `nix build .#checks.<system>.<name>`.
|
||||
Auto-generated jobs are skipped if a user-defined job with the same name exists.
|
||||
|
||||
### With flake-parts
|
||||
|
||||
```nix
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
systems.url = "github:nix-systems/default-linux";
|
||||
nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci?dir=lib";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ flake-parts, systems, ... } @ inputs:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [ inputs.nix-gitlab-ci.flakeModule ];
|
||||
systems = import systems;
|
||||
perSystem = { pkgs, system, ... }: {
|
||||
checks = {
|
||||
lint = pkgs.runCommand "lint" { } ''
|
||||
${pkgs.nodePackages.prettier}/bin/prettier --check .
|
||||
touch $out
|
||||
'';
|
||||
test = pkgs.runCommand "test" { } ''
|
||||
${pkgs.python3}/bin/python -m pytest
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
ci = {
|
||||
config.autoChecks.enable = true;
|
||||
pipelines.default.stages = [ "test" "build" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
### Without flake-parts
|
||||
|
||||
```nix
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
nix-gitlab-ci.url = "gitlab:TECHNOFAB/nix-gitlab-ci?dir=lib";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{ self, nixpkgs, nix-gitlab-ci, ... }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
cilib = nix-gitlab-ci.lib { inherit pkgs; };
|
||||
in
|
||||
{
|
||||
checks.${system} = {
|
||||
lint = pkgs.runCommand "lint" { } ''
|
||||
${pkgs.nodePackages.prettier}/bin/prettier --check .
|
||||
touch $out
|
||||
'';
|
||||
test = pkgs.runCommand "test" { } ''
|
||||
${pkgs.python3}/bin/python -m pytest
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
|
||||
packages.${system} =
|
||||
(cilib.mkCI {
|
||||
checks = self.checks.${system};
|
||||
config.autoChecks.enable = true;
|
||||
pipelines.default.stages = [ "test" "build" ];
|
||||
}).packages;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
______________________________________________________________________
|
||||
|
||||
Since V2 multiple pipelines are supported.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue