tokensave 7.9.0

Code intelligence tool that builds a semantic knowledge graph from Rust, Go, Java, Scala, TypeScript, Python, C, C++, Kotlin, C#, Swift, and many more codebases
name: Release (Beta)

# Beta channel is DISABLED as of 6.0.0.
#
# The workflow code is intentionally preserved so the beta channel can be
# revived later by:
#   1. Reverting this `on:` block to the previous `release: [published]`
#      trigger.
#   2. Removing the `BETA_CHANNEL_ENABLED` guard from every job (`if:`).
#
# While the guard is `false`, the workflow can still be exercised
# manually via `workflow_dispatch` for debugging — the jobs simply skip.
on:
  workflow_dispatch:

# Only runs for prerelease tags — stable releases handled by release.yml

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always
  # Single toggle that gates every job in this workflow. Flip to `true`
  # (or remove the guard from each `if:` line below) to re-enable.
  BETA_CHANNEL_ENABLED: 'false'

jobs:
  build:
    name: Build ${{ matrix.name }}
    if: env.BETA_CHANNEL_ENABLED == 'true' && github.event.release.prerelease
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - name: aarch64-macos
            runner: macos-14
            target: aarch64-apple-darwin
            bottle_tag: arm64_sonoma
            archive: tar.gz
          - name: x86_64-linux
            runner: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
            bottle_tag: x86_64_linux
            archive: tar.gz
          - name: aarch64-linux
            runner: ubuntu-22.04-arm
            target: aarch64-unknown-linux-gnu
            archive: tar.gz
          - name: x86_64-windows
            runner: windows-latest
            target: x86_64-pc-windows-msvc
            archive: zip
          - name: aarch64-windows
            runner: windows-11-arm
            target: aarch64-pc-windows-msvc
            archive: zip

    steps:
      - uses: actions/checkout@v5

      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build release binary
        run: cargo build --release --target ${{ matrix.target }}

      - name: Get version
        id: version
        shell: bash
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"

      # --- Binary archive (all platforms) ---

      - name: Package binary (unix)
        if: matrix.archive == 'tar.gz'
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../tokensave-beta-${{ github.ref_name }}-${{ matrix.name }}.tar.gz tokensave
          cd ../../..

      - name: Package binary (windows)
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          Compress-Archive -Path target/${{ matrix.target }}/release/tokensave.exe -DestinationPath tokensave-beta-${{ github.ref_name }}-${{ matrix.name }}.zip

      - name: Upload binary archive
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        shell: bash
        run: gh release upload ${{ github.ref_name }} tokensave-beta-${{ github.ref_name }}-${{ matrix.name }}.${{ matrix.archive }} --clobber

      # --- Homebrew bottle (only for platforms with bottle_tag) ---

      - name: Package Homebrew bottle
        if: matrix.bottle_tag
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          BOTTLE_TAG="${{ matrix.bottle_tag }}"
          mkdir -p tokensave-beta/${VERSION}/bin
          cp target/${{ matrix.target }}/release/tokensave tokensave-beta/${VERSION}/bin/tokensave
          chmod +x tokensave-beta/${VERSION}/bin/tokensave
          tar czf "tokensave-beta-${VERSION}.${BOTTLE_TAG}.bottle.tar.gz" tokensave-beta/

      - name: Upload bottle artifact
        if: matrix.bottle_tag
        uses: actions/upload-artifact@v6
        with:
          name: bottle-beta-${{ matrix.bottle_tag }}
          path: "tokensave-beta-*.bottle.tar.gz"

  update-homebrew:
    name: Update Homebrew tap (beta)
    if: env.BETA_CHANNEL_ENABLED == 'true' && github.event.release.prerelease && !cancelled()
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Get version
        id: version
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"

      - name: Download bottle artifacts
        uses: actions/download-artifact@v7
        with:
          path: bottles
          merge-multiple: true

      - name: Upload bottles to release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          for f in bottles/tokensave-beta-*.bottle.tar.gz; do
            gh release upload "${GITHUB_REF_NAME}" "$f" --clobber
          done

      - name: Download source tarball
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          curl -sL "https://github.com/${{ github.repository }}/archive/refs/tags/${GITHUB_REF_NAME}.tar.gz" -o "source.tar.gz"

      - name: Compute SHA256 hashes
        id: hashes
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          SOURCE_SHA=$(sha256sum source.tar.gz | awk '{print $1}')
          echo "source_sha=${SOURCE_SHA}" >> "$GITHUB_OUTPUT"

          for f in bottles/tokensave-beta-*.bottle.tar.gz; do
            tag=$(basename "$f" | sed "s/tokensave-beta-${VERSION}\.\(.*\)\.bottle\.tar\.gz/\1/")
            sha=$(sha256sum "$f" | awk '{print $1}')
            echo "${tag}_sha=${sha}" >> "$GITHUB_OUTPUT"
          done

      - name: Update formula
        env:
          TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
        run: |
          VERSION="${{ steps.version.outputs.version }}"
          SOURCE_SHA="${{ steps.hashes.outputs.source_sha }}"
          ARM64_SONOMA_SHA="${{ steps.hashes.outputs.arm64_sonoma_sha }}"
          X86_64_LINUX_SHA="${{ steps.hashes.outputs.x86_64_linux_sha }}"

          git clone "https://x-access-token:${TAP_GITHUB_TOKEN}@github.com/aovestdipaperino/homebrew-tap.git" tap

          cat > tap/Formula/tokensave-beta.rb << EOF
          class TokensaveBeta < Formula
            desc "Code intelligence tool (beta channel)"
            homepage "https://github.com/aovestdipaperino/tokensave"
            url "https://github.com/aovestdipaperino/tokensave/archive/refs/tags/v${VERSION}.tar.gz"
            sha256 "${SOURCE_SHA}"
            license "MIT"

            bottle do
              root_url "https://github.com/aovestdipaperino/tokensave/releases/download/v${VERSION}"
              sha256 cellar: :any_skip_relocation, arm64_sonoma: "${ARM64_SONOMA_SHA}"
              sha256 cellar: :any_skip_relocation, x86_64_linux: "${X86_64_LINUX_SHA}"
            end

            depends_on "rust" => :build

            conflicts_with "tokensave", because: "both install a `tokensave` binary"

            def install
              system "cargo", "install", *std_cargo_args
            end

            test do
              system "#{bin}/tokensave", "--help"
            end
          end
          EOF

          cd tap
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/tokensave-beta.rb
          git diff --cached --quiet || git commit -m "tokensave-beta ${VERSION}"
          git push

  update-scoop:
    name: Update Scoop bucket (beta)
    if: env.BETA_CHANNEL_ENABLED == 'true' && github.event.release.prerelease && !cancelled()
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Get release info
        id: release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
          echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"

          gh release download "${GITHUB_REF_NAME}" \
            --repo "${{ github.repository }}" \
            --pattern "tokensave-beta-${GITHUB_REF_NAME}-x86_64-windows.zip" \
            --pattern "tokensave-beta-${GITHUB_REF_NAME}-aarch64-windows.zip" \
            --dir .
          # Fail loudly on a missing asset rather than masking it inside a
          # `VAR=$(sha256sum missing)` assignment and publishing an empty hash.
          for arch in x86_64-windows aarch64-windows; do
            if [ ! -f "tokensave-beta-${GITHUB_REF_NAME}-${arch}.zip" ]; then
              echo "::error::required release asset tokensave-beta-${GITHUB_REF_NAME}-${arch}.zip is missing — aborting Scoop update"
              exit 1
            fi
          done
          SHA256=$(sha256sum "tokensave-beta-${GITHUB_REF_NAME}-x86_64-windows.zip" | cut -d' ' -f1)
          echo "sha256_win64=${SHA256}" >> "$GITHUB_OUTPUT"
          SHA256_ARM=$(sha256sum "tokensave-beta-${GITHUB_REF_NAME}-aarch64-windows.zip" | cut -d' ' -f1)
          echo "sha256_winarm64=${SHA256_ARM}" >> "$GITHUB_OUTPUT"

      - name: Update Scoop manifest
        env:
          SCOOP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
        run: |
          VERSION="${{ steps.release.outputs.version }}"
          TAG="${{ steps.release.outputs.tag }}"
          SHA256="${{ steps.release.outputs.sha256_win64 }}"
          SHA256_ARM="${{ steps.release.outputs.sha256_winarm64 }}"

          cat > tokensave-beta.json << EOF
          {
            "version": "${VERSION}",
            "description": "Code intelligence tool (beta channel)",
            "homepage": "https://github.com/aovestdipaperino/tokensave",
            "license": "MIT",
            "architecture": {
              "64bit": {
                "url": "https://github.com/aovestdipaperino/tokensave/releases/download/${TAG}/tokensave-beta-${TAG}-x86_64-windows.zip",
                "hash": "${SHA256}"
              },
              "arm64": {
                "url": "https://github.com/aovestdipaperino/tokensave/releases/download/${TAG}/tokensave-beta-${TAG}-aarch64-windows.zip",
                "hash": "${SHA256_ARM}"
              }
            },
            "bin": "tokensave.exe",
            "checkver": {
              "github": "https://github.com/aovestdipaperino/tokensave",
              "regex": "v([\\d.]+-beta[\\d.]*)"
            },
            "autoupdate": {
              "architecture": {
                "64bit": {
                  "url": "https://github.com/aovestdipaperino/tokensave/releases/download/v\$version/tokensave-beta-v\$version-x86_64-windows.zip"
                },
                "arm64": {
                  "url": "https://github.com/aovestdipaperino/tokensave/releases/download/v\$version/tokensave-beta-v\$version-aarch64-windows.zip"
                }
              }
            }
          }
          EOF

          git clone "https://x-access-token:${SCOOP_GITHUB_TOKEN}@github.com/aovestdipaperino/scoop-bucket.git" scoop-repo
          cd scoop-repo
          mkdir -p bucket
          cp ../tokensave-beta.json bucket/tokensave-beta.json
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add bucket/tokensave-beta.json
          git diff --cached --quiet || git commit -m "tokensave-beta ${VERSION}"
          git push