From b7e30ec14896d3b67494a30fac0b3ab37de50b28 Mon Sep 17 00:00:00 2001 From: Willem Vanhulle Date: Wed, 21 Oct 2026 12:44:02 +0200 Subject: [PATCH] ci: add Woodpecker checks, Cachix config and conventional commit hooks --- .pre-commit-config.yaml | 15 +++++ .woodpecker/rust-and-flake-checks.yaml | 87 ++++++++++++++++++++++++++ CONTRIBUTING.md | 19 ++++++ crane-builds.nix | 14 +++++ flake.nix | 48 +++++++++++++- 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 .woodpecker/rust-and-flake-checks.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6205d14 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +default_install_hook_types: [pre-commit, commit-msg] +repos: + - repo: https://github.com/compilerla/conventional-pre-commit + rev: v4.4.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] + - repo: local + hooks: + - id: rustfmt-formatting + name: rustfmt formatting + entry: cargo fmt --all --check + language: system + types: [rust] + pass_filenames: false diff --git a/.woodpecker/rust-and-flake-checks.yaml b/.woodpecker/rust-and-flake-checks.yaml new file mode 100644 index 0000000..2a0d04d --- /dev/null +++ b/.woodpecker/rust-and-flake-checks.yaml @@ -0,0 +1,87 @@ +when: + - repo: wvhulle/bootvine + event: [pull_request, push, manual] + +variables: + - &nix_config + NIX_CONFIG: | + experimental-features = nix-command flakes + build-users-group = + accept-flake-config = true + - &cache_writing_env + <<: *nix_config + CACHIX_AUTH_TOKEN: + from_secret: cachix_auth_token + - &on_main_branch + - event: [push, manual] + branch: main + - &off_main_branch + - event: pull_request + - event: [push, manual] + branch: + exclude: main + - &on_pull_requests + - event: pull_request + +steps: + - name: build-test-and-cache-bootvine + image: nixos/nix:latest + depends_on: [] + when: *on_main_branch + environment: *cache_writing_env + commands: + - nix run .#build-and-push-to-cachix -- .#checks.x86_64-linux.bootvine-build + + - name: build-and-test-bootvine + image: nixos/nix:latest + depends_on: [] + when: *off_main_branch + environment: *nix_config + commands: + - nix build --print-build-logs .#checks.x86_64-linux.bootvine-build + + - name: build-and-cache-repo-tasks + image: nixos/nix:latest + depends_on: [] + when: *on_main_branch + environment: *cache_writing_env + commands: + - nix run .#build-and-push-to-cachix -- .#checks.x86_64-linux.repo-tasks-build + + - name: build-repo-tasks + image: nixos/nix:latest + depends_on: [] + when: *off_main_branch + environment: *nix_config + commands: + - nix build --print-build-logs .#checks.x86_64-linux.repo-tasks-build + + - name: lint-rust-with-clippy + image: nixos/nix:latest + depends_on: [] + environment: *nix_config + commands: + - nix build --print-build-logs .#checks.x86_64-linux.clippy-lints + + - name: check-rust-formatting + image: nixos/nix:latest + depends_on: [] + environment: *nix_config + commands: + - nix build --print-build-logs .#checks.x86_64-linux.rustfmt-formatting + + - name: evaluate-flake-outputs + image: nixos/nix:latest + depends_on: [] + environment: *nix_config + commands: + - nix flake check --no-build + + - name: check-conventional-commit-messages + image: nixos/nix:latest + depends_on: [] + when: *on_pull_requests + environment: *nix_config + commands: + - git fetch --quiet origin "$${CI_COMMIT_TARGET_BRANCH}" + - nix run .#check-conventional-commits -- FETCH_HEAD..HEAD diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d468286..093a1a5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,25 @@ cargo fmt --all Clippy runs with the pedantic lints and forbids absolute paths; formatting needs the nightly toolchain the dev shell provides. +Commit messages follow [Conventional Commits](https://www.conventionalcommits.org). +jj does not run git hooks, so check the commits you are about to push with: + +```sh +nix run .#check-conventional-commits -- origin/main..HEAD +``` + +Git users can install the same commit-message check and a formatting check as +hooks with `prek install` (from the dev shell) or `pre-commit install`. + +## Continuous integration + +`.woodpecker/rust-and-flake-checks.yaml` runs on Codeberg for every push and +pull request: the bootvine build with its tests, the xtask build, clippy, +rustfmt, an evaluation of every flake output, and the commit-message check on +pull requests. Builds on `main` are pushed to the `wvhulle` Cachix cache, which +`nixConfig` in `flake.nix` offers as a substituter. The two VM checks need KVM, +which Codeberg's runners lack, so they only run locally. + ## Testing | What | Command | diff --git a/crane-builds.nix b/crane-builds.nix index 81cabad..71a0aba 100644 --- a/crane-builds.nix +++ b/crane-builds.nix @@ -10,6 +10,7 @@ let fileset = lib.fileset.unions [ (craneLib.fileset.commonCargoSources ./.) ./system-files + ./.rustfmt.toml ]; }; strictDeps = true; @@ -23,6 +24,19 @@ let args: craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; } // args); in { + rustfmt-formatting = craneLib.cargoFmt { + inherit (commonArgs) src; + cargoExtraArgs = "--all"; + }; + + clippy-lints = craneLib.cargoClippy ( + commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--workspace --all-targets -- --deny warnings"; + } + ); + bootvine = buildWorkspaceMember { cargoExtraArgs = "-p bootvine"; postInstall = '' diff --git a/flake.nix b/flake.nix index 40fa0ac..1c58dfe 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,13 @@ { description = "bootvine — live dependency tree of systemd jobs on the boot console"; + nixConfig = { + extra-substituters = [ "https://wvhulle.cachix.org" ]; + extra-trusted-public-keys = [ + "wvhulle.cachix.org-1:heXx8DZMiRsKUx6l1TxNoF+Nmtmz66QEdsonQzc1ir0=" + ]; + }; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; crane.url = "github:ipetkov/crane"; @@ -93,12 +100,38 @@ } ); }; + build-and-push-to-cachix = { + type = "app"; + meta.description = "Build flake outputs and push everything built to the wvhulle Cachix cache"; + program = lib.getExe ( + pkgs.writeShellApplication { + name = "build-and-push-to-cachix"; + runtimeInputs = [ pkgs.cachix ]; + text = ''exec cachix watch-exec wvhulle -- nix build --print-build-logs "$@"''; + } + ); + }; + check-conventional-commits = { + type = "app"; + meta.description = "Check that the commit messages in a git revision range are conventional commits"; + program = lib.getExe ( + pkgs.writeShellApplication { + name = "check-conventional-commits"; + runtimeInputs = [ + pkgs.convco + pkgs.gitMinimal + ]; + text = ''exec convco check "$@"''; + } + ); + }; } ); checks = forEachSystem ( { pkgs, builds, ... }: { + inherit (builds) rustfmt-formatting clippy-lints; bootvine-build = builds.bootvine; repo-tasks-build = builds.repo-tasks; vm-boot-and-shutdown = pkgs.testers.runNixOSTest ( @@ -111,9 +144,20 @@ ); devShells = forEachSystem ( - { craneLib, builds, ... }: { - default = craneLib.devShell { inputsFrom = [ builds.bootvine ]; }; + pkgs, + craneLib, + builds, + ... + }: + { + default = craneLib.devShell { + inputsFrom = [ builds.bootvine ]; + packages = [ + pkgs.prek + pkgs.convco + ]; + }; } ); };