ci: move CI scripting into Nushell scripts with separate dependency steps

Replace the shell wrappers build-and-push-to-cachix, check-conventional-commits
and the release-plz apps with Nushell scripts in ci/, and move the git commands
out of the workflow YAML, so that every workflow command is a plain nix call.

Build the workspace dependencies in their own step, skipped when already in
Cachix. Later steps import the exported paths and also run after an earlier
failure. A separate step alone holds the Cachix token and uploads on main.
Pull requests run the same steps without the upload.

Wrap the recording tasks with makeBinaryWrapper instead of shell, and run the
CI task tests in a step of their own.
This commit is contained in:
Willem Vanhulle committed 2026-11-04 20:02:26 +01:00
1 parent d0833ad563
commit ce72695e29
8 files changed
+338 -84

No files matched your search

+79
View File
@@ -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
}
export def store-paths-from-lines []: string -> list<string> {
lines | compact --empty
}
def exported-store-paths []: nothing -> list<string> {
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 {
[]
}
}
export 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"
}
+36
View File
@@ -0,0 +1,36 @@
#!/usr/bin/env nu
const CODEBERG_USER = "wvhulle"
const RELEASE_BRANCH_NAME = "main"
export def authenticated-origin-url [repository_slug: string, access_token: string]: nothing -> string {
$"https://($CODEBERG_USER):($access_token)@codeberg.org/($repository_slug).git"
}
def run-release-plz [release_subcommand: string]: nothing -> nothing {
^release-plz $release_subcommand --forge gitea --git-token $env.CODEBERG_TOKEN
}
def "main release-plz-release" []: nothing -> nothing {
^git remote set-url origin (authenticated-origin-url $env.CI_REPO $env.CODEBERG_TOKEN)
^git checkout -B $RELEASE_BRANCH_NAME $env.CI_COMMIT_SHA
run-release-plz release
}
def "main release-plz-release-pr" []: nothing -> nothing {
run-release-plz release-pr
}
def "main check-conventional-commits" [
--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-conventional-commits"
}
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env nu
use std/assert
use ./nix-built-paths.nu [nix-config-with-hook store-paths-from-lines]
use ./release-tasks.nu [authenticated-origin-url]
def main []: nothing -> nothing {
assert equal (nix-config-with-hook "max-jobs = 1" "/nix/store/hook") "max-jobs = 1\npost-build-hook = /nix/store/hook"
assert equal (nix-config-with-hook "" "/nix/store/hook") "\npost-build-hook = /nix/store/hook"
assert equal ("/nix/store/first\n\n/nix/store/second\n" | store-paths-from-lines) ["/nix/store/first" "/nix/store/second"]
assert equal ("" | store-paths-from-lines) []
assert equal (authenticated-origin-url "wvhulle/bootvine" "sample-token") "https://wvhulle:sample-token@codeberg.org/wvhulle/bootvine.git"
print "CI task tests passed"
}