paperboy 0.7.2

A Rust TUI API tester
name: CI

on:
  push:
    branches: [main, master]
  pull_request:
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  # The vendored libcurl/OpenSSL build (see the `curl` dependency in Cargo.toml)
  # dominates a cold build, so a warm cache is the difference between a two
  # minute job and a twenty minute one.
  CARGO_INCREMENTAL: 0

jobs:
  fmt:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all --check

  # The feature matrix is the point of this job. PaperBoy builds in four shapes
  # and each one has to stay both compiling *and* warning-free on its own:
  #
  #   headless  -- no front-end at all; the shape used in CI images and Docker
  #   tui       -- the default, and what `cargo install paperboy` gives you
  #   gui       -- tui + gui, what `--features gui` gives you
  #   gui-only  -- the GUI without the terminal UI
  #
  # Without this job the non-default shapes rot silently: `gui-only` did not
  # compile at all until the front-ends were split apart, because nothing ever
  # built it. `-D warnings` is deliberate — the dead-code suppression in
  # `main.rs` is keyed on the `tui` feature, and this is what proves the two
  # front-end-complete configurations are still carrying full analysis.
  # The Windows jobs copy an icon into the cargo registry to get past hurl
  # 8.0.1's build script, which embeds `../../bin/windows/logo.ico`
  # unconditionally -- a path that resolves only inside hurl's own checkout
  # (Orange-OpenSource/hurl#5207). The trouble with that workaround is that it
  # is silent once it stops being necessary: copying a file goes on succeeding
  # forever, so no build would ever fail in a way that says "this can go now",
  # and the registry copy would sit there looking inexplicable. Upstream fixed
  # it after 8.0.1, so the moment the lockfile resolves anything newer this
  # job fails and spells out what to delete. Removing the shim is the whole
  # point of the failure; do that rather than deleting this check.
  hurl-icon-shim:
    name: hurl icon shim still needed
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Fail once hurl outgrows the Windows icon workaround
        run: |
          set -euo pipefail
          version="$(grep -A1 '^name = "hurl"$' Cargo.lock \
            | sed -n 's/^version = "\(.*\)"$/\1/p')"
          if [ -z "$version" ]; then
            echo "::error::could not read hurl's version from Cargo.lock"
            exit 1
          fi
          echo "lockfile resolves hurl $version"
          oldest="$(printf '%s\n8.0.1\n' "$version" | sort -V | head -n1)"
          if [ "$version" = "8.0.1" ] || { [ "$oldest" = "$version" ] && [ "$version" != "8.0.1" ]; }; then
            echo "hurl#5207 is unfixed at this version -- the icon shim is still required"
            exit 0
          fi
          echo "hurl $version is past 8.0.1 and carries the fix for hurl#5207."
          echo "Remove the 'Work around hurl's unreachable Windows icon' step from"
          echo "  .github/workflows/ci.yml"
          echo "  .github/workflows/release.yml"
          echo "and item 4 from the README's 'Windows' build-prerequisites section."
          echo
          echo "Note that paperboy.exe then gets NO icon at all: upstream's fix skips"
          echo "the resource when the file is missing, and the icon it embeds is hurl's"
          echo "own regardless. To keep ours, embed assets/windows/paperboy.ico from"
          echo "our build.rs instead of relying on a dependency's build script."
          echo "::error::hurl $version no longer needs the Windows icon shim; see this job's log"
          exit 1

  check:
    name: check (${{ matrix.name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: headless
            features: --no-default-features
          - name: tui
            features: ""
          - name: gui
            features: --features gui
          - name: gui-only
            features: --no-default-features --features gui
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.name }}
      # eframe pulls in winit, which needs the X11/Wayland and xkbcommon headers
      # at build time. The terminal and headless shapes need none of this, which
      # is a large part of why the GUI is opt-in in the first place.
      - name: Install GUI build dependencies
        if: contains(matrix.features, 'gui')
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends \
            libxkbcommon-dev libwayland-dev libx11-dev libxcursor-dev \
            libxrandr-dev libxi-dev libgl1-mesa-dev
      - run: cargo check ${{ matrix.features }} --all-targets
        env:
          RUSTFLAGS: -D warnings

  # Every shape that is built is also tested. The GUI configurations were
  # originally check-only, which left their 432 `gui::*` tests compiled but
  # never run — a shape CI proves builds and nothing more. They need no display
  # to run, so there was nothing bought by leaving them out.
  #
  # None of the four is redundant: headless is the only one proving the core
  # passes with no front-end linked in (what a CI-image user installs), and
  # gui-only is the only one proving the GUI stands on its own.
  test:
    name: test (${{ matrix.name }})
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: headless
            features: --no-default-features
          - name: tui
            features: ""
          - name: gui
            features: --features gui
          - name: gui-only
            features: --no-default-features --features gui
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: test-${{ matrix.name }}
      - name: Install GUI build dependencies
        if: contains(matrix.features, 'gui')
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-recommends \
            libxkbcommon-dev libwayland-dev libx11-dev libxcursor-dev \
            libxrandr-dev libxi-dev libgl1-mesa-dev
      # `paperboy` is a binary crate with no lib target, so the unit tests are
      # compiled into `src/main.rs` and plain `cargo test` is the only form that
      # works (`--lib` fails outright).
      - run: cargo test ${{ matrix.features }}

  # Everything above runs on Linux, which for a long time meant the two
  # platforms a user is most likely to *download* were never compiled at all --
  # "PaperBoy runs on Windows" was a claim resting on nothing, and the first
  # person to test it did so by hand, one missing dependency at a time.
  #
  # Only the `gui` shape is built here. It is a strict superset: the same binary
  # serves `-c`, the terminal UI and `--gui`, so it is both the widest compile
  # and exactly what a release artifact will be. A second shape would double a
  # slow job to prove something the Linux matrix already proves.
  #
  # Neither runner can build this out of the box, and what each is missing is
  # not the same:
  platform:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: windows
            os: windows-latest
          - name: macos
            os: macos-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.os }}

      # On MSVC, `libxml` asks vcpkg and nothing else. The image ships a vcpkg
      # tree already, so this installs the port rather than bootstrapping one --
      # and `VCPKG_ROOT` is exported because that, not `PATH`, is how vcpkg-rs
      # finds the tree. The triplet must be the `-static-md` one Rust's MSVC
      # target wants; the plain `x64-windows` port installs fine and then reads
      # as missing.
      - name: Install libxml2 (vcpkg)
        if: runner.os == 'Windows'
        run: |
          & "$env:VCPKG_INSTALLATION_ROOT\vcpkg" install libxml2:x64-windows-static-md
          echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" >> $env:GITHUB_ENV
          echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" >> $env:GITHUB_ENV

      # OpenSSL assembles its Windows primitives with NASM, which is the one
      # prerequisite the image does not carry (it has Perl, LLVM and MSVC). Its
      # installer does not extend PATH either, hence the second line.
      - name: Install NASM
        if: runner.os == 'Windows'
        run: |
          choco install nasm -y --no-progress
          echo "C:\Program Files\NASM" >> $env:GITHUB_PATH

      # hurl 8.0.1's build script embeds a Windows icon from
      # `../../bin/windows/logo.ico`, a path relative to hurl's own git
      # checkout. The crates.io package ships nothing outside its own
      # directory, so on Windows `rc.exe` fails with RC2135 and the build
      # script panics -- hurl as a library simply cannot be built on Windows
      # from crates.io. Upstream fixed it by guarding the path
      # (Orange-OpenSource/hurl#5207, merged 2026-09-14) but has not released
      # it; 8.0.1 is still the newest crate.
      #
      # rc.exe resolves that relative path from the build script's working
      # directory, which Cargo sets to the package root -- so `../../` lands in
      # `registry/src`, and putting a file there is enough to satisfy it. We
      # supply *our own* icon rather than fetching hurl's: the resource is
      # linked into the final executable, so hurl's logo would otherwise become
      # paperboy.exe's icon. Remove this once hurl 8.1.0 is out.
      - name: Work around hurl's unreachable Windows icon (hurl#5207)
        if: runner.os == 'Windows'
        run: |
          $cargoHome = if ($env:CARGO_HOME) { $env:CARGO_HOME } else { Join-Path $env:USERPROFILE ".cargo" }
          $dir = Join-Path $cargoHome "registry\src\bin\windows"
          New-Item -ItemType Directory -Force -Path $dir | Out-Null
          Copy-Item "assets\windows\paperboy.ico" (Join-Path $dir "logo.ico") -Force

      # macOS bundles libxml2 in the dyld shared cache on every install, and the
      # SDK ships its headers and a linker stub -- but no pkg-config file, so
      # `libxml`'s pkg-config probe cannot find the one copy that is guaranteed
      # to be present. Synthesising the `.pc` is what makes that copy usable:
      # the binary then links `/usr/lib/libxml2.2.dylib`, a path every Mac has,
      # and the archive needs nothing installed. `xcrun` keeps this correct as
      # the SDK moves between Xcode releases.
      #
      # The previous approach -- Homebrew's keg-only libxml2 plus
      # `LIBXML2_STATIC` -- was a no-op, and silently so. Homebrew's bottle
      # ships no `libxml2.a` at all, and pkg-config-rs only emits `static=`
      # when it can see one in the `-L` directory; finding none it falls back
      # to an ordinary dynamic link without warning. The build then succeeds
      # having baked in an `/opt/homebrew` path that exists on this runner and
      # on no user's Mac, which is exactly what 0.7.0's first attempt shipped.
      # Supplying an `.a` would not have rescued it either: Apple's linker has
      # no `-Bstatic`, so `-lxml2` against a directory holding both files picks
      # the dylib regardless, and forcing the archive means linking it by
      # absolute path.
      #
      # Kept identical to release.yml's step on purpose: if they drift, this job
      # proves one linking arrangement works and the release ships another.
      - name: Point pkg-config at the macOS SDK's libxml2
        if: runner.os == 'macOS'
        run: |
          set -euo pipefail
          # `pkg-config` is a build tool here, not a link dependency: installing
          # it from Homebrew has no bearing on what the binary ends up linking.
          command -v pkg-config >/dev/null || brew install pkg-config
          sdk="$(xcrun --show-sdk-path)"
          header="$sdk/usr/include/libxml2/libxml/xmlversion.h"
          version="$(awk -F'"' '/define LIBXML_DOTTED_VERSION/ {print $2}' "$header")"
          if [ -z "$version" ]; then
            echo "::error::no LIBXML_DOTTED_VERSION in $header"
            exit 1
          fi
          echo "using the SDK's libxml2 $version from $sdk"
          mkdir -p "$RUNNER_TEMP/pkgconfig"
          cat > "$RUNNER_TEMP/pkgconfig/libxml-2.0.pc" <<PC
          Name: libxml2
          Description: libxml2 from the macOS SDK
          Version: $version
          Libs: -lxml2
          Cflags: -I$sdk/usr/include/libxml2
          PC
          echo "PKG_CONFIG_PATH=$RUNNER_TEMP/pkgconfig" >> "$GITHUB_ENV"

      # `-D warnings` matches the Linux matrix. Platform-gated code (clipboard
      # and terminal handling differ per OS) has never been under it before, so
      # this is the job that will say so.
      - run: cargo test --features gui
        env:
          RUSTFLAGS: -D warnings