etoon 0.2.0

Fast TOON (Token-Oriented Object Notation) encoder. 8x faster than toons, 2.7x faster than the official TS SDK.
Documentation
name: Release

on:
  workflow_dispatch:
  push:
    tags:
      - "v*"

permissions: read-all

jobs:
  # ========================================================================
  # Build Python wheels for PyPI (Linux, macOS, Windows × x86_64/aarch64)
  # ========================================================================
  wheels-linux:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    strategy:
      matrix:
        target: [x86_64, aarch64]
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: "3.x"
      - name: Build wheels
        uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # v1.50.1
        with:
          target: ${{ matrix.target }}
          manylinux: auto
          args: --release --out dist --interpreter 3.10 3.11 3.12 3.13
      - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        with:
          name: wheels-linux-${{ matrix.target }}
          path: dist

  wheels-macos:
    runs-on: macos-14
    permissions:
      contents: read
    strategy:
      matrix:
        target: [x86_64, aarch64]
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: "3.x"
      - name: Build wheels
        uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # v1.50.1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --interpreter 3.10 3.11 3.12 3.13
      - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        with:
          name: wheels-macos-${{ matrix.target }}
          path: dist

  wheels-windows:
    runs-on: windows-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: "3.x"
          architecture: x64
      - name: Build wheels
        uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # v1.50.1
        with:
          target: x64
          args: --release --out dist --interpreter 3.10 3.11 3.12 3.13
      - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        with:
          name: wheels-windows-x64
          path: dist

  sdist:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - name: Build sdist
        uses: PyO3/maturin-action@04ac600d27cdf7a9a280dadf7147097c42b757ad # v1.50.1
        with:
          command: sdist
          args: --out dist
      - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        with:
          name: sdist
          path: dist

  # ========================================================================
  # Build native CLI binaries for GitHub Releases
  # ========================================================================
  cli-binaries:
    permissions:
      contents: read
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            name: etoon-linux-x86_64
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            name: etoon-linux-aarch64
            cross: true
          - target: x86_64-apple-darwin
            os: macos-14
            name: etoon-macos-x86_64
          - target: aarch64-apple-darwin
            os: macos-14
            name: etoon-macos-aarch64
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: etoon-windows-x86_64.exe
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: Install cross (for aarch64 Linux)
        if: matrix.cross
        run: cargo install cross --locked
      - name: Build (native)
        if: '!matrix.cross'
        run: cargo build --release --bin etoon --no-default-features --target ${{ matrix.target }}
      - name: Build (cross)
        if: matrix.cross
        run: cross build --release --bin etoon --no-default-features --target ${{ matrix.target }}
      - name: Rename binary
        shell: bash
        run: |
          if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
            cp target/${{ matrix.target }}/release/etoon.exe ${{ matrix.name }}
          else
            cp target/${{ matrix.target }}/release/etoon ${{ matrix.name }}
          fi
      - uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
        with:
          name: cli-${{ matrix.target }}
          path: ${{ matrix.name }}

  # ========================================================================
  # Publish to PyPI (on tag push)
  # ========================================================================
  publish-pypi:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [wheels-linux, wheels-macos, wheels-windows, sdist]
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          pattern: "wheels-*"
          path: dist
          merge-multiple: true
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: sdist
          path: dist
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
        with:
          password: ${{ secrets.PYPI_TOKEN }}
          skip-existing: true

  # ========================================================================
  # Publish to crates.io (on tag push)
  # ========================================================================
  publish-crates:
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      - uses: dtolnay/rust-toolchain@stable
      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --no-default-features

  # ========================================================================
  # Create GitHub Release with CLI binaries + checksums + signatures
  # ========================================================================
  github-release:
    if: startsWith(github.ref, 'refs/tags/v')
    needs: [cli-binaries]
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
    steps:
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          pattern: "cli-*"
          path: cli
          merge-multiple: true

      - name: Generate SHA256 checksums
        run: |
          cd cli
          sha256sum * > ../SHA256SUMS.txt
          cat ../SHA256SUMS.txt

      - name: Install cosign
        uses: sigstore/cosign-installer@cad07c2e89fa2edd6e2d7bab4c1aa38e53f76003 # v4.1.1

      - name: Sign binaries with cosign (keyless)
        run: |
          cd cli
          for f in *; do
            cosign sign-blob --yes "$f" --output-signature "../${f}.sig" --output-certificate "../${f}.pem"
          done

      - name: Collect release assets
        run: |
          mkdir release
          cp cli/* release/
          cp SHA256SUMS.txt release/
          cp *.sig *.pem release/

      - name: Create release
        uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1
        with:
          files: release/*
          draft: false
          prerelease: false
          generate_release_notes: true