diff --git a/.forgejo/workflows/test.yaml b/.forgejo/workflows/test.yaml new file mode 100644 index 0000000..132ccd9 --- /dev/null +++ b/.forgejo/workflows/test.yaml @@ -0,0 +1,64 @@ +# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie +# SPDX-License-Identifier: MIT + +name: test + +# The workflow has to be on the default branch for the manual trigger to show +# up in the UI, where it appears as a "Run workflow" button on the Actions tab. +on: + push: + workflow_dispatch: + +jobs: + test: + runs-on: nixos + env: + # Keep Zig's caches on the runner rather than inside the workspace, so + # they survive between runs. + ZIG_LOCAL_CACHE_DIR: /zig/local-cache + ZIG_GLOBAL_CACHE_DIR: /zig/global-cache + steps: + - name: Check out + uses: actions/checkout@v4 + + # The dev shell pins the toolchain, so CI and a local checkout build with + # the same Zig and the same reuse. + - name: Check formatting + run: nix develop .#default -c zig fmt --check . + + # Every file needs an SPDX header and every license a file in LICENSES/, + # which is easy to forget when adding one. + - name: Check REUSE compliance + run: nix develop .#default -c reuse lint + + # Debug and ReleaseSafe keep the safety checks that catch overflow and + # out-of-bounds writes, which is what the decoder's bounds properties + # lean on; ReleaseFast drops them and can behave differently. The library + # module takes its optimize mode from the build flag, so these really are + # three different builds of the test suite. + - name: Run tests + run: | + nix develop .#default -c zig build test -Doptimize=Debug --summary all + nix develop .#default -c zig build test -Doptimize=ReleaseSafe --summary all + nix develop .#default -c zig build test -Doptimize=ReleaseFast --summary all + + docs: + # Gated on the tests, so a red build never replaces the published + # reference, and on the default branch, or any pushed branch would publish + # over the live site. + needs: test + if: ${{ forge.ref == 'refs/heads/main' }} + runs-on: nixos + env: + ZIG_LOCAL_CACHE_DIR: /zig/local-cache + ZIG_GLOBAL_CACHE_DIR: /zig/global-cache + steps: + - name: Check out + uses: actions/checkout@v4 + + - name: Build API docs + run: nix develop .#default -c zig build docs + + # Publishes the generated reference to https://jeff.ocj.page/zuucode/ . + - name: Publish docs + run: nix develop .#default -c git-pages-cli https://jeff.ocj.page/zuucode/ --server ocj.page --token ${{ forge.token }} --upload-dir zig-out/docs diff --git a/build.zig b/build.zig index 6bcb0ec..bd453a2 100644 --- a/build.zig +++ b/build.zig @@ -43,4 +43,20 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Run tests"); test_step.dependOn(&b.addRunArtifact(mod_tests).step); test_step.dependOn(&b.addRunArtifact(exe_tests).step); + + // The autodoc generator emits its output as a side effect of building a + // library, so `lib` exists only to be the thing whose docs are collected. + const lib = b.addLibrary(.{ + .name = "zuucode", + .root_module = mod, + }); + + const install_docs = b.addInstallDirectory(.{ + .source_dir = lib.getEmittedDocs(), + .install_dir = .prefix, + .install_subdir = "docs", + }); + + const docs_step = b.step("docs", "Build the API docs"); + docs_step.dependOn(&install_docs.step); } diff --git a/flake.nix b/flake.nix index 567ebf8..c98c1e3 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ # SPDX-License-Identifier: MIT { - description = ""; + description = "A uuencode encoder and decoder for Zig."; inputs = { nixpkgs = { @@ -37,7 +37,7 @@ in { default = pkgs.mkShell { - name = "znntp"; + name = "zuucode"; nativeBuildInputs = [ pkgs.git-pages-cli pkgs.kcov