tokf-server: v0.2.39 #175
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag to republish (e.g. tokf-v0.2.13)" | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RELEASE_TAG: ${{ inputs.tag || github.event.release.tag_name }} | |
| jobs: | |
| publish: | |
| name: Publish to crates.io | |
| if: startsWith(inputs.tag || github.event.release.tag_name, 'tokf-v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ env.RELEASE_TAG }} | |
| - uses: dtolnay/rust-toolchain@stable | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Publish tokf-common | |
| run: | | |
| LOCAL=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "tokf-common") | .version') | |
| PUBLISHED=$(cargo search tokf-common --limit 1 --color never | sed -n 's/^tokf-common = "\([^"]*\)".*/\1/p') | |
| if [ "$LOCAL" = "$PUBLISHED" ]; then | |
| echo "::notice::tokf-common@$LOCAL already published, skipping" | |
| else | |
| cargo publish -p tokf-common | |
| fi | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| - name: Publish tokf-hook-types | |
| run: | | |
| LOCAL=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "tokf-hook-types") | .version') | |
| PUBLISHED=$(cargo search tokf-hook-types --limit 1 --color never | sed -n 's/^tokf-hook-types = "\([^"]*\)".*/\1/p') | |
| if [ "$LOCAL" = "$PUBLISHED" ]; then | |
| echo "::notice::tokf-hook-types@$LOCAL already published, skipping" | |
| else | |
| cargo publish -p tokf-hook-types | |
| fi | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| - name: Publish tokf-filter | |
| run: | | |
| LOCAL=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "tokf-filter") | .version') | |
| PUBLISHED=$(cargo search tokf-filter --limit 1 --color never | sed -n 's/^tokf-filter = "\([^"]*\)".*/\1/p') | |
| if [ "$LOCAL" = "$PUBLISHED" ]; then | |
| echo "::notice::tokf-filter@$LOCAL already published, skipping" | |
| else | |
| cargo publish -p tokf-filter | |
| fi | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| - name: Publish tokf-cli | |
| run: | | |
| LOCAL=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "tokf") | .version') | |
| PUBLISHED=$(cargo search tokf --limit 1 --color never | sed -n 's/^tokf = "\([^"]*\)".*/\1/p') | |
| if [ "$LOCAL" = "$PUBLISHED" ]; then | |
| echo "::notice::tokf@$LOCAL already published, skipping" | |
| else | |
| cargo publish -p tokf | |
| fi | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| publish-npm: | |
| name: Publish @tokf/catalog-types to npm | |
| needs: [publish] | |
| if: startsWith(inputs.tag || github.event.release.tag_name, 'tokf-v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ env.RELEASE_TAG }} | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Publish catalog types | |
| working-directory: crates/tokf-server/generated | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| build-binaries: | |
| name: Build ${{ matrix.target }} | |
| if: startsWith(inputs.tag || github.event.release.tag_name, 'tokf-v') | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: aarch64-apple-darwin | |
| runner: macos-14 | |
| - target: x86_64-apple-darwin | |
| runner: macos-14 | |
| - target: x86_64-unknown-linux-gnu | |
| runner: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ env.RELEASE_TAG }} | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - uses: Swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Add target | |
| run: rustup target add ${{ matrix.target }} | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target }} -p tokf | |
| - name: Package binary | |
| shell: bash | |
| run: | | |
| TAG="${{ env.RELEASE_TAG }}" | |
| VERSION="${TAG#tokf-v}" | |
| ARCHIVE="tokf-v${VERSION}-${{ matrix.target }}.tar.gz" | |
| cp "target/${{ matrix.target }}/release/tokf" tokf | |
| tar -czf "${ARCHIVE}" tokf | |
| echo "ARCHIVE=${ARCHIVE}" >> "$GITHUB_ENV" | |
| openssl dgst -sha256 "${ARCHIVE}" | awk '{print $2}' > "${ARCHIVE}.sha256" | |
| - name: Upload to release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh release upload "${{ env.RELEASE_TAG }}" \ | |
| "${{ env.ARCHIVE }}" \ | |
| "${{ env.ARCHIVE }}.sha256" \ | |
| --clobber | |
| update-homebrew: | |
| name: Update Homebrew tap | |
| needs: build-binaries | |
| if: startsWith(inputs.tag || github.event.release.tag_name, 'tokf-v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Compute version | |
| id: version | |
| run: | | |
| TAG="${{ env.RELEASE_TAG }}" | |
| echo "version=${TAG#tokf-v}" >> "$GITHUB_OUTPUT" | |
| - name: Download SHA256 checksums | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| for TARGET in aarch64-apple-darwin x86_64-apple-darwin x86_64-unknown-linux-gnu; do | |
| gh release download "${{ env.RELEASE_TAG }}" \ | |
| --repo "${{ github.repository }}" \ | |
| --pattern "tokf-v${VERSION}-${TARGET}.tar.gz.sha256" \ | |
| --output "${TARGET}.sha256" | |
| done | |
| echo "SHA256_AARCH64=$(cat aarch64-apple-darwin.sha256)" >> "$GITHUB_ENV" | |
| echo "SHA256_X86_64_DARWIN=$(cat x86_64-apple-darwin.sha256)" >> "$GITHUB_ENV" | |
| echo "SHA256_LINUX=$(cat x86_64-unknown-linux-gnu.sha256)" >> "$GITHUB_ENV" | |
| - name: Generate GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| app-id: ${{ secrets.REPOSITORY_BUTLER_APP_ID }} | |
| private-key: ${{ secrets.REPOSITORY_BUTLER_PEM }} | |
| repositories: homebrew-tokf,homebrew-tools | |
| - name: Checkout homebrew-tokf tap | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: mpecan/homebrew-tokf | |
| token: ${{ steps.app-token.outputs.token }} | |
| path: homebrew-tokf | |
| - name: Checkout homebrew-tools tap | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: mpecan/homebrew-tools | |
| token: ${{ steps.app-token.outputs.token }} | |
| path: homebrew-tools | |
| - name: Update formula | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| python3 - <<'EOF' | |
| import os, textwrap | |
| v = os.environ['VERSION'] | |
| sha_arm = os.environ['SHA256_AARCH64'] | |
| sha_intel = os.environ['SHA256_X86_64_DARWIN'] | |
| sha_linux = os.environ['SHA256_LINUX'] | |
| base = "https://github.com/mpecan/tokf/releases/download" | |
| formula = textwrap.dedent(f""" | |
| class Tokf < Formula | |
| desc "Config-driven CLI that compresses command output before it reaches an LLM context" | |
| homepage "https://tokf.net" | |
| version "{v}" | |
| license "MIT" | |
| on_macos do | |
| on_arm do | |
| url "{base}/tokf-v{v}/tokf-v{v}-aarch64-apple-darwin.tar.gz" | |
| sha256 "{sha_arm}" | |
| end | |
| on_intel do | |
| url "{base}/tokf-v{v}/tokf-v{v}-x86_64-apple-darwin.tar.gz" | |
| sha256 "{sha_intel}" | |
| end | |
| end | |
| on_linux do | |
| on_intel do | |
| url "{base}/tokf-v{v}/tokf-v{v}-x86_64-unknown-linux-gnu.tar.gz" | |
| sha256 "{sha_linux}" | |
| end | |
| end | |
| def install | |
| bin.install "tokf" | |
| end | |
| test do | |
| assert_match "tokf", shell_output("#{{bin}}/tokf --version") | |
| end | |
| end | |
| """).strip() | |
| for tap_dir in ["homebrew-tokf", "homebrew-tools"]: | |
| os.makedirs(f"{tap_dir}/Formula", exist_ok=True) | |
| with open(f"{tap_dir}/Formula/tokf.rb", "w") as f: | |
| f.write(formula + "\n") | |
| EOF | |
| - name: Commit and push homebrew-tokf | |
| working-directory: homebrew-tokf | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/tokf.rb | |
| git diff --staged --quiet && echo "Formula unchanged, skipping commit" && exit 0 | |
| git commit -m "chore: update tokf to v${{ steps.version.outputs.version }}" | |
| git push | |
| - name: Commit and push homebrew-tools | |
| working-directory: homebrew-tools | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/tokf.rb | |
| git diff --staged --quiet && echo "Formula unchanged, skipping commit" && exit 0 | |
| git commit -m "chore: update tokf to v${{ steps.version.outputs.version }}" | |
| git push | |
| publish-stdlib: | |
| name: Publish stdlib filters | |
| needs: [publish] | |
| if: startsWith(inputs.tag || github.event.release.tag_name, 'tokf-v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ env.RELEASE_TAG }} | |
| fetch-depth: 0 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Publish stdlib filters | |
| run: cargo run -p tokf --features stdlib-publish -- publish-stdlib | |
| env: | |
| TOKF_SERVICE_TOKEN: ${{ secrets.TOKF_SERVICE_TOKEN }} | |
| TOKF_REGISTRY_URL: https://api.tokf.net | |
| trigger-site-rebuild: | |
| name: Trigger tokf.net rebuild | |
| needs: build-binaries | |
| if: startsWith(inputs.tag || github.event.release.tag_name, 'tokf-v') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Generate GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| app-id: ${{ secrets.REPOSITORY_BUTLER_APP_ID }} | |
| private-key: ${{ secrets.REPOSITORY_BUTLER_PEM }} | |
| repositories: tokf-net | |
| - name: Dispatch rebuild | |
| run: | | |
| gh api repos/mpecan/tokf-net/dispatches \ | |
| --method POST \ | |
| --field event_type=tokf-release | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} |