Explorer
/opt/struktur/buzz/.github/workflows/windows-canary.yml
← Zurück ↓ Download
name: Windows Canary

# Produces an unsigned Windows NSIS installer from main without creating
# a tag, GitHub Release, or auto-updater artifact. The installer is available
# only as a short-lived GitHub Actions artifact for explicit testing.
#
# Design notes vs. signed-macos-canary.yml:
#   - No mesh-llm: release-windows doesn't build it.
#   - pnpm store restore/save pattern mirrors ci.yml:149-196.
on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  build:
    name: Build Windows canary
    if: github.repository == 'block/buzz'
    runs-on: windows-latest
    timeout-minutes: 60
    permissions:
      contents: read
    env:
      TARGET: x86_64-pc-windows-msvc
    steps:
      - name: Require main
        shell: bash
        env:
          SOURCE_REF: ${{ github.ref }}
        run: |
          if [[ "$SOURCE_REF" != "refs/heads/main" ]]; then
            echo "::error::Canary builds must run from main; got $SOURCE_REF"
            exit 1
          fi

      - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          persist-credentials: false

      # The Windows runner ships with rustup preinstalled; rust-toolchain.toml
      # in the repo root pins the channel (1.95.0) automatically. We only need
      # to ensure the cross-compile target is registered; on windows-latest the
      # host IS x86_64-pc-windows-msvc so this is typically a no-op.
      - name: Add Rust target
        shell: bash
        run: rustup target add "$TARGET"

      - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          node-version: 24.14.1
          package-manager-cache: false

      - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0
        with:
          version: 11.4.0

      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: echo "STORE_PATH=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"

      - name: Restore pnpm store cache
        uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: pnpm-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: pnpm-${{ runner.os }}-

      - name: Install desktop dependencies
        shell: bash
        run: pnpm install --frozen-lockfile

      - name: Derive canary version
        id: version
        shell: bash
        run: |
          set -euo pipefail
          BASE_VERSION=$(node -p "require('./desktop/package.json').version")
          if ! [[ "$BASE_VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z.-]+)?$ ]]; then
            echo "::error::Desktop version '$BASE_VERSION' is not semver"
            exit 1
          fi
          VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3] + 1))-test.${GITHUB_RUN_NUMBER}"
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
          echo "Building canary version $VERSION from $GITHUB_SHA"

      - name: Patch canary version
        shell: bash
        env:
          VERSION: ${{ steps.version.outputs.version }}
        run: |
          cd desktop && node scripts/set-version-from-tag.mjs "$VERSION"
          cd src-tauri && cargo update --workspace

      - name: Resolve native toolchain identity
        id: native_toolchain
        shell: bash
        run: echo "id=$(scripts/desktop-native-toolchain-id.sh windows)" >> "$GITHUB_OUTPUT"

      # Compute this after cargo update so the key describes the graph that is
      # actually compiled. The helper normalizes only Buzz Desktop's release
      # version, allowing a canary to warm an otherwise identical tag build.
      - name: Compute exact release cache key
        id: rust_cache_key
        shell: bash
        env:
          NATIVE_TOOLCHAIN_ID: ${{ steps.native_toolchain.outputs.id }}
        run: |
          KEY=$(scripts/desktop-release-cache-key.py \
            --platform "$RUNNER_OS" \
            --target x86_64-pc-windows-msvc \
            --features default \
            --native-inputs "$NATIVE_TOOLCHAIN_ID")
          echo "key=$KEY" >> "$GITHUB_OUTPUT"
          echo "Release cache key: $KEY"

      - name: Restore exact release Cargo cache
        id: rust_cache
        uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
            desktop/src-tauri/target
            !desktop/src-tauri/target/**/release/bundle
          key: ${{ steps.rust_cache_key.outputs.key }}

      - name: Generate non-updating bundle config
        shell: bash
        run: |
          cat > desktop/src-tauri/tauri.canary.conf.json <<'JSON'
          {
            "bundle": {
              "createUpdaterArtifacts": false
            }
          }
          JSON

      - name: Build sidecars
        shell: bash
        run: |
          cargo build --release --target "$TARGET" -p buzz-acp -p buzz-agent -p buzz-dev-mcp -p git-credential-nostr -p buzz-cli
          ./scripts/bundle-sidecars.sh "$TARGET"

      - name: Build Windows NSIS installer (unsigned)
        shell: bash
        run: cd desktop && pnpm tauri build --target "$TARGET" --bundles nsis --config src-tauri/tauri.canary.conf.json
        env:
          CMAKE_POLICY_VERSION_MINIMUM: "3.5"

      - name: Locate NSIS installer
        id: artifact
        shell: bash
        run: |
          set -euo pipefail
          BUNDLE_DIR="desktop/src-tauri/target/${TARGET}/release/bundle"
          EXE=$(find "$BUNDLE_DIR/nsis" -name '*.exe' -type f | head -1)
          if [[ -z "$EXE" ]]; then
            echo "::error::No NSIS installer found in $BUNDLE_DIR/nsis"
            exit 1
          fi
          echo "exe=$EXE" >> "$GITHUB_OUTPUT"

      - name: Upload Windows canary installer
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: buzz-windows-canary-${{ github.sha }}
          path: ${{ steps.artifact.outputs.exe }}
          if-no-files-found: error
          retention-days: 7

      - name: Measure release Cargo cache inputs
        if: always()
        shell: bash
        run: du -sh ~/.cargo/registry ~/.cargo/git target desktop/src-tauri/target 2>/dev/null || true

      # Only this trusted, main-bound canary writes the cache. Excluding bundle
      # output prevents installers from entering it.
      - name: Save exact release Cargo cache
        if: steps.rust_cache.outputs.cache-hit != 'true'
        uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
            desktop/src-tauri/target
            !desktop/src-tauri/target/**/release/bundle
          key: ${{ steps.rust_cache_key.outputs.key }}

      - name: Save pnpm store cache
        uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: pnpm-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}