name: Publish # OpenTokenUsage is a Windows fork: this workflow builds and publishes the # per-user NSIS installer (.exe) plus the signed native-updater assets # (latest.json + .sig) consumed by the in-app auto-updater. # No MSI: Tauri's MSI is always per-machine, so every update asked for admin # rights. An MSI install (0.7.7 or older) updates to the NSIS build, whose # installer removes the MSI (one admin prompt) and installs per user. # # REQUIRED updater secrets (add BEFORE tagging a release, or the build fails): # TAURI_SIGNING_PRIVATE_KEY - contents of the updater private key file # TAURI_SIGNING_PRIVATE_KEY_PASSWORD - key password (empty if generated w/o one) # The matching public key + endpoints live in src-tauri/tauri.conf.json. # # Supply chain: every action is pinned to a full commit SHA (the version is in the comment), because # the signing key and WINGET_TOKEN are handed to them. Bump deliberately, never to a moving tag. # Release notes come from the matching "## vX.Y.Z" section of CHANGELOG.md (required). on: push: tags: - "v*" permissions: contents: write jobs: publish: if: startsWith(github.ref, 'refs/tags/v') runs-on: windows-latest permissions: contents: write id-token: write # Sigstore certificate for the build provenance attestation attestations: write defaults: run: shell: bash env: RELEASE_TAG: ${{ github.ref_name }} steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: ref: ${{ env.RELEASE_TAG }} - uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable branch, 2026-09-03 with: toolchain: stable - uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2 with: workspaces: "./src-tauri -> target" - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 with: bun-version: "1.4.2" - run: bun install --frozen-lockfile - name: Bundle plugins run: bun run bundle:plugins - name: Verify bundled plugins run: | COUNT=$(find src-tauri/resources/bundled_plugins -maxdepth 2 -name plugin.json | wc -l | tr -d ' ') if [[ "$COUNT" -lt 1 ]]; then echo "No bundled plugins found under src-tauri/resources/bundled_plugins." exit 1 fi - name: Validate release tag run: | if [[ -z "$RELEASE_TAG" ]]; then echo "Missing RELEASE_TAG (push a v* tag)." exit 1 fi if [[ ! "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo "Invalid RELEASE_TAG: $RELEASE_TAG (expected vMAJOR.MINOR.PATCH)" exit 1 fi - name: Validate app version matches tag id: version run: | TAG_VERSION="${RELEASE_TAG#v}" echo "version=$TAG_VERSION" >> "$GITHUB_OUTPUT" TAURI_CONF_VERSION=$(node -p 'require("./src-tauri/tauri.conf.json").version') CARGO_VERSION=$(awk -F'"' '/^version =/ { print $2; exit }' ./src-tauri/Cargo.toml) PKG_VERSION=$(node -p 'require("./package.json").version') if [[ "$TAURI_CONF_VERSION" != "$TAG_VERSION" ]]; then echo "src-tauri/tauri.conf.json version ($TAURI_CONF_VERSION) != tag version ($TAG_VERSION)" exit 1 fi if [[ "$CARGO_VERSION" != "$TAG_VERSION" ]]; then echo "src-tauri/Cargo.toml version ($CARGO_VERSION) != tag version ($TAG_VERSION)" exit 1 fi if [[ "$PKG_VERSION" != "$TAG_VERSION" ]]; then echo "package.json version ($PKG_VERSION) != tag version ($TAG_VERSION)" exit 1 fi - name: Release notes from CHANGELOG.md id: notes run: | NOTES="$RUNNER_TEMP/release-notes.md" # The "## vX.Y.Z" section, without its heading, up to the next "## v" heading. # (The Windows runner may check files out with CRLF: drop the \r first.) awk -v tag="## $RELEASE_TAG" ' { sub(/\r$/, "") } $0 == tag { found = 1; next } found && /^## v/ { exit } found { print } ' CHANGELOG.md > "$NOTES" if ! grep -q '[^[:space:]]' "$NOTES"; then echo "CHANGELOG.md has no '## $RELEASE_TAG' section; add the release notes first." exit 1 fi { echo "body<<__RELEASE_NOTES__" cat "$NOTES" echo "__RELEASE_NOTES__" } >> "$GITHUB_OUTPUT" - uses: tauri-apps/tauri-action@84b9d35b5fc46c1e45415bdb6144030364f7ebc5 # v0.6.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} with: tagName: ${{ env.RELEASE_TAG }} releaseName: ${{ env.RELEASE_TAG }} releaseBody: ${{ steps.notes.outputs.body }} # Releases are immutable (repo setting): a published release takes no more assets, so tauri-action # fills a draft and the last step publishes it. A re-run finds the same draft by its tag. releaseDraft: true prerelease: false includeUpdaterJson: true # Signed build provenance for the setup the draft now holds (the same file tauri-action uploaded; named # in full, as the rust cache could bring back an older setup): # `gh attestation verify -R PowerUserZ/OpenTokenUsage` shows it was built here, from this tag. # No storage record: those exist only for organization-owned repositories. A failure leaves the draft # unpublished, so no release goes out without it. - uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2 with: subject-path: src-tauri/target/release/bundle/nsis/OpenTokenUsage_${{ steps.version.outputs.version }}_x64-setup.exe create-storage-record: false - name: Verify Windows installers uploaded env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | ASSETS=$(gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name' | tr -d '\r') printf '%s\n' "$ASSETS" | grep -Eq '\.exe$' || { echo "Missing NSIS installer (.exe)"; exit 1; } ! printf '%s\n' "$ASSETS" | grep -Eq '\.msi$' || { echo "Unexpected MSI (.msi): per-machine, asks for admin on every update"; exit 1; } printf '%s\n' "$ASSETS" | grep -Fxq 'latest.json' || { echo "Missing updater manifest: latest.json"; exit 1; } printf '%s\n' "$ASSETS" | grep -Eq '\.sig$' || { echo "Missing updater signatures (.sig)"; exit 1; } # MSI installs look up windows-x86_64-msi, then windows-x86_64: both must lead to the NSIS setup. # A draft's asset URLs say "untagged-…" (dead once published); tauri-action rewrites them to the tag. gh release download "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --pattern latest.json --dir "$RUNNER_TEMP" --clobber node -e ' const p = require(process.argv[1]).platforms; const url = p["windows-x86_64"]?.url ?? ""; if (p["windows-x86_64-msi"] || !url.endsWith("-setup.exe")) { console.error("latest.json must send every Windows install to the NSIS setup.exe:", Object.keys(p)); process.exit(1); } if (!url.includes("/download/" + process.env.RELEASE_TAG + "/")) { console.error("latest.json must point at this tag, not at the draft:", url); process.exit(1); } ' "$RUNNER_TEMP/latest.json" # Last, once everything above passed: publishing makes the release immutable (its assets and tag can't # change any more) and the in-app updater's releases/latest/download/latest.json moves to it. - name: Publish the release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh release edit "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --draft=false # The token can't read the repository setting, so ask the published release: the README promises immutable ones. [ "$(gh release view "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" --json isImmutable --jq .isImmutable)" = true ] || echo "::warning::$RELEASE_TAG was published mutable: turn on immutable releases in the repository settings." # Auto-submit a winget-pkgs update PR for each release. No-ops unless the # WINGET_TOKEN secret (a classic PAT with public_repo + workflow) is configured. # workflow is needed because the new branch in the winget-pkgs fork carries # upstream's .github/workflows changes. # Requires the package to already exist in winget-pkgs — the initial # PowerUserZ.OpenTokenUsage manifest was submitted manually for v0.6.23; # this keeps subsequent versions in sync automatically. # It submits the same per-user setup. komac copies the previous version's manifest fields, so # the first version after the 0.7.7 MSI needs its winget PR checked (see CLAUDE.md). winget: name: Submit to WinGet needs: publish runs-on: ubuntu-latest permissions: contents: read env: WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }} steps: - name: Publish to WinGet Community Repo if: ${{ env.WINGET_TOKEN != '' }} uses: vedantmgoyal9/winget-releaser@4ffc7888bffd451b357355dc214d43bb9f23917e # v2 with: identifier: PowerUserZ.OpenTokenUsage installers-regex: 'OpenTokenUsage_.*_x64-setup\.exe$' release-tag: ${{ github.ref_name }} token: ${{ env.WINGET_TOKEN }}