diff --git a/.woodpecker/checks.yaml b/.woodpecker/checks.yaml new file mode 100644 index 0000000..fcdc886 --- /dev/null +++ b/.woodpecker/checks.yaml @@ -0,0 +1,85 @@ +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 + - &after_dependency_step + - status: [success, failure] + +steps: + - name: prepare-build-dependencies + image: nixos/nix:latest + depends_on: [] + environment: *nix_config + commands: + - nix run --quiet .#build-unless-cached -- .#packages.x86_64-linux.workspace-dependencies + + - name: build-and-test-bootvine + image: nixos/nix:latest + depends_on: [prepare-build-dependencies] + when: *after_dependency_step + environment: *nix_config + commands: + - nix run --quiet .#import-exported-paths + - nix run --quiet .#build-and-export-paths -- .#checks.x86_64-linux.bootvine-build + + - name: build-repo-tasks + image: nixos/nix:latest + depends_on: [prepare-build-dependencies] + when: *after_dependency_step + environment: *nix_config + commands: + - nix run --quiet .#import-exported-paths + - nix run --quiet .#build-and-export-paths -- .#checks.x86_64-linux.repo-tasks-build + + - name: lint-with-clippy + image: nixos/nix:latest + depends_on: [prepare-build-dependencies] + when: *after_dependency_step + environment: *nix_config + commands: + - nix run --quiet .#import-exported-paths + - nix build --quiet --print-build-logs .#checks.x86_64-linux.clippy-lints + + - name: upload-builds-to-cachix + image: nixos/nix:latest + depends_on: [build-and-test-bootvine, build-repo-tasks] + when: + - event: [push, manual] + branch: main + status: [success, failure] + environment: + <<: *nix_config + CACHIX_AUTH_TOKEN: + from_secret: cachix_auth_token + commands: + - nix run --quiet .#upload-exported-paths + + - name: run-pre-commit-hooks + image: nixos/nix:latest + depends_on: [prepare-build-dependencies] + when: *after_dependency_step + environment: *nix_config + commands: + - nix run --quiet .#run-pre-commit-hooks + + - name: evaluate-flake-outputs + image: nixos/nix:latest + depends_on: [] + environment: *nix_config + commands: + - nix flake check --quiet --no-build + + - name: check-commit-messages + image: nixos/nix:latest + depends_on: [] + when: + - event: pull_request + environment: *nix_config + commands: + - nix run --quiet .#check-commit-messages -- --fetch-target-branch FETCH_HEAD..HEAD diff --git a/.woodpecker/dependency-update-pr.yaml b/.woodpecker/dependency-update-pr.yaml new file mode 100644 index 0000000..4f1a351 --- /dev/null +++ b/.woodpecker/dependency-update-pr.yaml @@ -0,0 +1,28 @@ +when: + - repo: wvhulle/bootvine + event: cron + cron: weekly-dependency-update + +clone: + - name: clone-with-history + image: woodpeckerci/plugin-git + settings: + depth: 0 + partial: false + +steps: + - name: open-dependency-update-pr + image: nixos/nix:latest + environment: + NIX_CONFIG: | + experimental-features = nix-command flakes + build-users-group = + accept-flake-config = true + GIT_AUTHOR_NAME: wvhulle-bot + GIT_AUTHOR_EMAIL: willemvanhulle@protonmail.com + GIT_COMMITTER_NAME: wvhulle-bot + GIT_COMMITTER_EMAIL: willemvanhulle@protonmail.com + CODEBERG_TOKEN: + from_secret: bot_token + commands: + - nix run --quiet .#open-dependency-update-pr -- --cargo-lock --flake-lock diff --git a/.woodpecker/release-pr-and-publish.yaml b/.woodpecker/publish-release-and-update-pr.yaml similarity index 66% rename from .woodpecker/release-pr-and-publish.yaml rename to .woodpecker/publish-release-and-update-pr.yaml index 92dc7f8..622510c 100644 --- a/.woodpecker/release-pr-and-publish.yaml +++ b/.woodpecker/publish-release-and-update-pr.yaml @@ -4,10 +4,10 @@ when: branch: main depends_on: - - rust-and-flake-checks + - checks clone: - - name: clone-with-history-and-tags + - name: clone-with-history image: woodpeckerci/plugin-git settings: depth: 0 @@ -25,21 +25,19 @@ variables: GIT_COMMITTER_NAME: release-plz GIT_COMMITTER_EMAIL: willemvanhulle@protonmail.com CODEBERG_TOKEN: - from_secret: codeberg_token + from_secret: bot_token CARGO_REGISTRY_TOKEN: from_secret: cargo_registry_token steps: - - name: publish-crate-and-tag-release + - name: publish-unreleased-crate-version image: nixos/nix:latest environment: *release_env commands: - - git remote set-url origin "https://wvhulle:$${CODEBERG_TOKEN}@codeberg.org/$${CI_REPO}.git" - - git checkout -B main "$${CI_COMMIT_SHA}" - - nix run .#release-plz-release + - nix run --quiet .#publish-unreleased-crate-version - - name: update-release-pr + - name: open-or-update-release-pr image: nixos/nix:latest environment: *release_env commands: - - nix run .#release-plz-release-pr + - nix run --quiet .#open-or-update-release-pr diff --git a/.woodpecker/rust-and-flake-checks.yaml b/.woodpecker/rust-and-flake-checks.yaml deleted file mode 100644 index 2a0d04d..0000000 --- a/.woodpecker/rust-and-flake-checks.yaml +++ /dev/null @@ -1,87 +0,0 @@ -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/ci/dependency-updates.nu b/ci/dependency-updates.nu new file mode 100755 index 0000000..1022db9 --- /dev/null +++ b/ci/dependency-updates.nu @@ -0,0 +1,64 @@ +#!/usr/bin/env nu + +const CODEBERG_USER = "wvhulle-bot" +const TEA_LOGIN_NAME = "codeberg" +const UPDATE_BRANCH = "bot/dependency-updates" +const UPDATE_COMMIT_MESSAGE = "chore(deps): update lock files" +const PULL_REQUEST_DESCRIPTION = "Opened by the weekly dependency update job. The checks on this pull request are the trial build. Commits pushed to this branch by hand stop further automatic updates until it is merged." + +def open-pull-request-heads []: nothing -> list { + ^tea pulls list --login $TEA_LOGIN_NAME --repo $env.CI_REPO --state open --fields head --output simple + | lines + | str trim +} + +def remote-update-branch-commits []: nothing -> list { + ^git ls-remote --heads origin $"refs/heads/($UPDATE_BRANCH)" + | parse "{commit_id}\t{ref_name}" + | get commit_id +} + +def update-branch-has-hand-written-commits []: nothing -> bool { + ^git fetch --quiet origin $"+refs/heads/($UPDATE_BRANCH):refs/remotes/origin/($UPDATE_BRANCH)" + ^git log --format=%an $"origin/main..origin/($UPDATE_BRANCH)" + | lines + | any {|commit_author| $commit_author != $env.GIT_AUTHOR_NAME } +} + +def "main open-dependency-update-pr" [ + --cargo-lock + --flake-lock +]: nothing -> nothing { + ^git remote set-url origin $"https://($CODEBERG_USER):($env.CODEBERG_TOKEN)@codeberg.org/($env.CI_REPO).git" + ^tea login add --name $TEA_LOGIN_NAME --url $env.CI_FORGE_URL --token $env.CODEBERG_TOKEN + ^git fetch --quiet origin +refs/heads/main:refs/remotes/origin/main + let remote_commits = remote-update-branch-commits + let remote_commit = $remote_commits | str join + let pull_request_is_open = $UPDATE_BRANCH in (open-pull-request-heads) + if ($remote_commits | is-not-empty) and $pull_request_is_open and (update-branch-has-hand-written-commits) { + print $"Leaving ($UPDATE_BRANCH) alone because it contains hand-written commits" + return + } + ^git checkout -B $UPDATE_BRANCH origin/main + if $cargo_lock { + ^cargo update + } + if $flake_lock { + ^nix flake update + } + if (^git diff --name-only | is-empty) { + print "Dependencies are up to date" + return + } + ^git commit --all --message $UPDATE_COMMIT_MESSAGE + ^git push $"--force-with-lease=($UPDATE_BRANCH):($remote_commit)" origin $UPDATE_BRANCH + if $pull_request_is_open { + print $"Updated the open pull request from ($UPDATE_BRANCH)" + } else { + ^tea pulls create --login $TEA_LOGIN_NAME --repo $env.CI_REPO --head $UPDATE_BRANCH --base main --title $UPDATE_COMMIT_MESSAGE --description $PULL_REQUEST_DESCRIPTION + } +} + +def main []: nothing -> nothing { + print "Run a subcommand, for example: open-dependency-update-pr --cargo-lock --flake-lock" +} diff --git a/ci/nix-built-paths.nu b/ci/nix-built-paths.nu new file mode 100755 index 0000000..9b3444c --- /dev/null +++ b/ci/nix-built-paths.nu @@ -0,0 +1,79 @@ +#!/usr/bin/env nu + +const EXPORT_DIRECTORY_NAME = ".nix-built-paths" +const PATH_LIST_FILE_NAME = "paths.txt" +const CACHIX_CACHE_NAME = "wvhulle" +const CACHIX_CACHE_URL = "https://wvhulle.cachix.org" + +def export-directory []: nothing -> path { + $env.CI_WORKSPACE | path join $EXPORT_DIRECTORY_NAME +} + +def store-paths-from-lines []: string -> list { + lines | compact --empty +} + +def exported-store-paths []: nothing -> list { + let path_list_file = export-directory | path join $PATH_LIST_FILE_NAME + if ($path_list_file | path exists) { + open --raw $path_list_file | store-paths-from-lines + } else { + [] + } +} + +def nix-config-with-hook [existing_config: string, hook_program: string]: nothing -> string { + $"($existing_config)\npost-build-hook = ($hook_program)" +} + +def "main export-built-paths-hook" []: nothing -> nothing { + let built_paths = $env.OUT_PATHS | split row " " | compact --empty + let directory = export-directory + mkdir $directory + ^nix copy --quiet --to $"file://($directory)?compression=zstd" ...$built_paths + $built_paths | each {|built_path| $"($built_path)\n" } | str join | save --append ($directory | path join $PATH_LIST_FILE_NAME) +} + +def --wrapped "main build-and-export-paths" [ + ...build_arguments: string +]: nothing -> nothing { + let hook_config = nix-config-with-hook ($env.NIX_CONFIG? | default "") $env.EXPORT_HOOK_PROGRAM + with-env {NIX_CONFIG: $hook_config} { + ^nix build --quiet --print-build-logs ...$build_arguments + } +} + +def "main build-unless-cached" [ + installable: string +]: nothing -> nothing { + let built_output = ^nix eval --quiet --raw $"($installable).outPath" + let cache_lookup = do { ^nix path-info --quiet --store $CACHIX_CACHE_URL $built_output } | complete + if $cache_lookup.exit_code == 0 { + print $"($built_output) is already in Cachix" + } else { + main build-and-export-paths $installable + } +} + +def "main import-exported-paths" []: nothing -> nothing { + let exported_paths = exported-store-paths + if ($exported_paths | is-empty) { + print "No exported paths to import" + } else { + ^nix copy --quiet --no-check-sigs --from $"file://(export-directory)" ...$exported_paths + } +} + +def "main upload-exported-paths" []: nothing -> nothing { + let exported_paths = exported-store-paths + if ($exported_paths | is-empty) { + print "No newly built paths to upload" + } else { + main import-exported-paths + ^cachix push $CACHIX_CACHE_NAME ...$exported_paths + } +} + +def main []: nothing -> nothing { + print "Run a subcommand, for example: build-and-export-paths" +} diff --git a/ci/release-tasks.nu b/ci/release-tasks.nu new file mode 100755 index 0000000..a7ed337 --- /dev/null +++ b/ci/release-tasks.nu @@ -0,0 +1,69 @@ +#!/usr/bin/env nu + +const CODEBERG_USER = "wvhulle-bot" +const TEA_LOGIN_NAME = "codeberg" +const RELEASE_ARCHIVE_PATTERN = "*.tar.gz" +const CHECKSUM_FILE_NAME = "sha256sum.txt" + +def checksum-line [archive_digest: string, archive_name: string]: nothing -> string { + $"($archive_digest) ($archive_name)\n" +} + +def run-release-plz [subcommand: string]: nothing -> nothing { + ^release-plz $subcommand --forge gitea --git-token $env.CODEBERG_TOKEN +} + +def "main authenticate-git-origin" []: nothing -> nothing { + ^git remote set-url origin $"https://($CODEBERG_USER):($env.CODEBERG_TOKEN)@codeberg.org/($env.CI_REPO).git" +} + +def "main publish-unreleased-crate-version" []: nothing -> nothing { + main authenticate-git-origin + ^git checkout -B main $env.CI_COMMIT_SHA + ^git fetch origin main:refs/remotes/origin/main + ^git branch --set-upstream-to=origin/main main + run-release-plz release +} + +def "main open-or-update-release-pr" []: nothing -> nothing { + run-release-plz release-pr +} + +def "main collect-release-archives" [ + build_result: path + dist_directory: path +]: nothing -> nothing { + mkdir $dist_directory + for archive_path in (glob ($build_result | path join $RELEASE_ARCHIVE_PATTERN)) { + cp $archive_path $dist_directory + } +} + +def "main upload-release-assets" [ + dist_directory: path +]: nothing -> nothing { + let archive_paths = glob ($dist_directory | path join $RELEASE_ARCHIVE_PATTERN) | sort + let checksum_file = $dist_directory | path join $CHECKSUM_FILE_NAME + $archive_paths + | each {|archive_path| + checksum-line (open --raw $archive_path | hash sha256) ($archive_path | path basename) + } + | str join + | save --force $checksum_file + ^tea login add --name $TEA_LOGIN_NAME --url $env.CI_FORGE_URL --token $env.CODEBERG_TOKEN + ^tea releases assets create --login $TEA_LOGIN_NAME --repo $env.CI_REPO $env.CI_COMMIT_TAG ...$archive_paths $checksum_file +} + +def "main check-commit-messages" [ + --fetch-target-branch + ...revision_ranges: string +]: nothing -> nothing { + if $fetch_target_branch { + ^git fetch --quiet origin $env.CI_COMMIT_TARGET_BRANCH + } + ^convco check ...$revision_ranges +} + +def main []: nothing -> nothing { + print "Run a subcommand, for example: check-commit-messages" +} diff --git a/docs/development.md b/docs/development.md index d089092..d8388e5 100644 --- a/docs/development.md +++ b/docs/development.md @@ -34,25 +34,26 @@ Commit messages follow [Conventional Commits](https://www.conventionalcommits.or 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 +nix run .#check-commit-messages -- origin/main..HEAD ``` Git users can install the same commit-message check and a formatting check as hooks with `prek install` ([prek](https://github.com/j178/prek), from the dev -shell) or `pre-commit install` ([pre-commit](https://pre-commit.com)). +shell) or `pre-commit install` ([pre-commit](https://pre-commit.com)). CI runs +the formatting hook with `nix run .#run-pre-commit-hooks`. ## Continuous integration -`.woodpecker/rust-and-flake-checks.yaml` runs on Codeberg's +`.woodpecker/checks.yaml` runs on Codeberg's [Woodpecker CI](https://woodpecker-ci.org) 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](https://www.cachix.org) cache, which -`nixConfig` in `flake.nix` offers as a substituter. The two VM checks need KVM, +the pre-commit hooks, an evaluation of every flake output, and the commit-message check on +pull requests. The workspace dependencies are built or fetched in a step of their own. Builds on `main` are pushed to the `wvhulle` [Cachix](https://www.cachix.org) cache, which +`nixConfig` in `flake.nix` offers as a substituter. CI tasks are Nushell scripts in `ci/`, exposed as flake apps in `nix/ci-tasks.nix`. The two VM checks need KVM, which Codeberg's runners lack, so they only run locally. ## Releases -`.woodpecker/release-pr-and-publish.yaml` runs +`.woodpecker/publish-release-and-update-pr.yaml` runs [release-plz](https://release-plz.dev) after the checks pass on `main`. It keeps a pull request labelled `release` open on Codeberg that bumps the version in `Cargo.toml` and adds the new commits to `CHANGELOG.md`. Only `feat`, `fix` @@ -61,11 +62,20 @@ minor version while bootvine is below 1.0. Merging that pull request publishes the crate to crates.io, tags the merge `v` and creates a Codeberg release with the changelog. Settings are in `release-plz.toml`. -The pipeline needs two Woodpecker secrets: `codeberg_token`, a Codeberg access -token with repository write access, and `cargo_registry_token`, a crates.io -token that may publish new crates and updates. Preview the next release +The pipeline needs two Woodpecker secrets: `bot_token`, an access token of the +`wvhulle-bot` Codeberg account, which has write access to the repository, and +`cargo_registry_token`, a crates.io token that may publish new crates and updates. Preview the next release locally from the dev shell with `release-plz update`. +## Dependency updates + +The `weekly-dependency-update` cron runs `.woodpecker/dependency-update-pr.yaml`, +which updates `Cargo.lock` and `flake.lock` and opens or updates one pull request +from the `bot/dependency-updates` branch as `wvhulle-bot`. The checks on that pull +request are the trial build. Commits pushed to the branch by hand stop further +automatic updates until it is merged. Updates that need changes to `Cargo.toml` +stay manual. + ## Testing | What | Command | diff --git a/flake.nix b/flake.nix index 34029c9..0797466 100644 --- a/flake.nix +++ b/flake.nix @@ -61,6 +61,7 @@ { default = builds.bootvine; inherit (builds) bootvine scripted-demos repo-tasks; + workspace-dependencies = builds.cargoArtifacts; sample-unit-files = pkgs.callPackage ./vm-tests/slow-services/sample-unit-files.nix { inherit (vmTests) sampleUnits; }; @@ -86,12 +87,29 @@ ... }: let - shellScriptApp = name: description: scriptArgs: { + mkApp = drv: { type = "app"; - meta.description = description; - program = lib.getExe (pkgs.writeShellApplication ({ inherit name; } // scriptArgs)); + program = lib.getExe drv; }; + repoTaskApp = + name: description: xtaskArguments: runtimeInputs: + mkApp ( + pkgs.runCommand name + { + nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; + meta.mainProgram = name; + } + '' + makeWrapper ${lib.getExe builds.repo-tasks} $out/bin/${name} \ + --add-flags ${lib.escapeShellArg xtaskArguments} \ + --prefix PATH : ${lib.makeBinPath runtimeInputs} + '' + ) + // { + meta.description = description; + }; + sampleMachineApps = lib.mapAttrs' ( machineName: machineDescription: lib.nameValuePair "sample-vm-${machineName}" { @@ -101,80 +119,50 @@ } ) vmTests.machineDescriptions; - releasePlzOnCodeberg = - subcommand: description: - shellScriptApp "release-plz-${subcommand}" description { - runtimeInputs = [ - pkgs.release-plz - pkgs.gitMinimal - pkgs.pkg-config - pkgs.stdenv.cc - rustToolchain - ]; - runtimeEnv.PKG_CONFIG_PATH = - lib.makeSearchPathOutput "dev" "lib/pkgconfig" - builds.bootvine.buildInputs; - text = ''exec release-plz ${subcommand} --forge gitea --git-token "$CODEBERG_TOKEN"''; - }; + ciTaskApps = import ./nix/ci-tasks.nix { + inherit pkgs mkApp; + cargoToolchain = rustToolchain; + preCommitInputs = [ rustToolchain ]; + extraReleaseInputs = [ + pkgs.pkg-config + pkgs.stdenv.cc + ]; + releaseWrapperArgs = [ + "--set" + "PKG_CONFIG_PATH" + (lib.makeSearchPathOutput "dev" "lib/pkgconfig" builds.bootvine.buildInputs) + ]; + }; in sampleMachineApps + // ciTaskApps // { - release-plz-release = releasePlzOnCodeberg "release" "Publish unpublished versions to crates.io and tag them with a Codeberg release"; - release-plz-release-pr = releasePlzOnCodeberg "release-pr" "Open or update the Codeberg pull request that bumps the version and changelog"; - record-screencasts = - shellScriptApp "record-screencasts" + repoTaskApp "record-screencasts" "Re-record the scripted demo animations and the sample machine recordings into recordings/; publish them with publish-recordings" - { - runtimeInputs = [ - pkgs.vhs - pkgs.libwebp - builds.scripted-demos - builds.repo-tasks - ]; - text = "exec xtask record-screencasts --vm-check-outputs ${ - pkgs.linkFarm "vm-check-outputs" ( - lib.mapAttrs (machineName: _: self.checks.${system}."vm-${machineName}") vmTests.machines - ) - }"; - }; + "record-screencasts --vm-check-outputs ${ + pkgs.linkFarm "vm-check-outputs" ( + lib.mapAttrs (machineName: _: self.checks.${system}."vm-${machineName}") vmTests.machines + ) + }" + [ + pkgs.vhs + pkgs.libwebp + builds.scripted-demos + ]; publish-recordings = - shellScriptApp "publish-recordings" + repoTaskApp "publish-recordings" "Replace the recordings branch on origin with a single commit holding recordings/" - { - runtimeInputs = [ - pkgs.gitMinimal - builds.repo-tasks - ]; - text = "exec xtask publish-recordings"; - }; - - build-and-push-to-cachix = - shellScriptApp "build-and-push-to-cachix" - "Build flake outputs and push everything built to the wvhulle Cachix cache" - { - runtimeInputs = [ pkgs.cachix ]; - text = ''exec cachix watch-exec wvhulle -- nix build --print-build-logs "$@"''; - }; - - check-conventional-commits = - shellScriptApp "check-conventional-commits" - "Check that the commit messages in a git revision range are conventional commits" - { - runtimeInputs = [ - pkgs.convco - pkgs.gitMinimal - ]; - text = ''exec convco check "$@"''; - }; + "publish-recordings" + [ pkgs.gitMinimal ]; } ); checks = forEachSystem ( { pkgs, builds, ... }: { - inherit (builds) rustfmt-formatting clippy-lints; + inherit (builds) clippy-lints; bootvine-build = builds.bootvine; repo-tasks-build = builds.repo-tasks; } diff --git a/nix/ci-tasks.nix b/nix/ci-tasks.nix new file mode 100644 index 0000000..931b074 --- /dev/null +++ b/nix/ci-tasks.nix @@ -0,0 +1,115 @@ +{ + pkgs, + mkApp, + cargoToolchain, + preCommitInputs, + extraReleaseInputs ? [ ], + releaseWrapperArgs ? [ ], +}: +let + inherit (pkgs) lib; + + nuScriptTool = + { + script, + name, + runtimeInputs ? [ ], + wrapperArgs ? [ ], + }: + pkgs.runCommand name + { + nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; + meta.mainProgram = name; + } + '' + makeWrapper ${lib.getExe pkgs.nushell} $out/bin/${name} \ + --add-flags ${script} \ + --add-flags ${name} \ + ${lib.optionalString (runtimeInputs != [ ]) "--prefix PATH : ${lib.makeBinPath runtimeInputs}"} \ + ${lib.escapeShellArgs wrapperArgs} + ''; + + nixBuiltPathsTool = toolArgs: nuScriptTool (toolArgs // { script = ../ci/nix-built-paths.nu; }); + + exportBuiltPathsHook = nixBuiltPathsTool { name = "export-built-paths-hook"; }; + + exportingBuildApp = + name: + mkApp (nixBuiltPathsTool { + inherit name; + wrapperArgs = [ + "--set" + "EXPORT_HOOK_PROGRAM" + (lib.getExe exportBuiltPathsHook) + ]; + }); + + releasePlzApp = + name: + mkApp (nuScriptTool { + inherit name; + script = ../ci/release-tasks.nu; + runtimeInputs = [ + cargoToolchain + pkgs.release-plz + pkgs.gitMinimal + ] + ++ extraReleaseInputs; + wrapperArgs = releaseWrapperArgs; + }); + + releaseTaskApps = + lib.mapAttrs + ( + name: runtimeInputs: + mkApp (nuScriptTool { + inherit name runtimeInputs; + script = ../ci/release-tasks.nu; + }) + ) + { + authenticate-git-origin = [ pkgs.gitMinimal ]; + collect-release-archives = [ ]; + upload-release-assets = [ pkgs.tea ]; + check-commit-messages = [ + pkgs.convco + pkgs.gitMinimal + ]; + }; + + preCommitHooksTool = + pkgs.runCommand "run-pre-commit-hooks" + { + nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; + meta.mainProgram = "run-pre-commit-hooks"; + } + '' + makeWrapper ${lib.getExe pkgs.prek} $out/bin/run-pre-commit-hooks \ + --add-flags "run --all-files --show-diff-on-failure" \ + --prefix PATH : ${lib.makeBinPath ([ pkgs.gitMinimal ] ++ preCommitInputs)} + ''; +in +releaseTaskApps +// { + publish-unreleased-crate-version = releasePlzApp "publish-unreleased-crate-version"; + open-or-update-release-pr = releasePlzApp "open-or-update-release-pr"; + open-dependency-update-pr = mkApp (nuScriptTool { + name = "open-dependency-update-pr"; + script = ../ci/dependency-updates.nu; + runtimeInputs = [ + cargoToolchain + pkgs.gitMinimal + pkgs.tea + ]; + }); + run-pre-commit-hooks = mkApp preCommitHooksTool; + build-and-export-paths = exportingBuildApp "build-and-export-paths"; + build-unless-cached = exportingBuildApp "build-unless-cached"; + import-exported-paths = mkApp (nixBuiltPathsTool { + name = "import-exported-paths"; + }); + upload-exported-paths = mkApp (nixBuiltPathsTool { + name = "upload-exported-paths"; + runtimeInputs = [ pkgs.cachix ]; + }); +} diff --git a/nix/crane-builds.nix b/nix/crane-builds.nix index 1ab5128..2f59051 100644 --- a/nix/crane-builds.nix +++ b/nix/crane-builds.nix @@ -30,10 +30,7 @@ let args: craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; } // args); in { - rustfmt-formatting = craneLib.cargoFmt { - inherit (commonArgs) src pname version; - cargoExtraArgs = "--all"; - }; + inherit cargoArtifacts; clippy-lints = craneLib.cargoClippy ( commonArgs