a3s-use-ocr 0.3.0

Provider-oriented optical character recognition interfaces for A3S
Documentation
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: read

jobs:
  validate:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy,rustfmt
      - uses: Swatinem/rust-cache@v2
      - id: version
        shell: bash
        run: |
          set -euo pipefail
          version=$(cargo metadata --no-deps --format-version 1 |
            python3 -c 'import json,sys; print(json.load(sys.stdin)["packages"][0]["version"])')
          test "${GITHUB_REF_NAME}" = "v${version}"
          echo "version=${version}" >> "${GITHUB_OUTPUT}"
      - run: cargo fmt --all -- --check
      - run: cargo test --no-default-features --lib --locked
      - run: cargo check --no-default-features --features mcp --locked
      - run: cargo test --all-features --locked
      - run: cargo clippy --all-targets --all-features --locked -- -D warnings
      - run: cargo package --locked

  assets:
    needs: validate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2
      - name: Prepare pinned model and Skill assets
        shell: bash
        run: |
          set -euo pipefail
          export A3S_USE_OCR_HOME="${RUNNER_TEMP}/ocr-models"
          cargo run --locked --example install_models
          rm -f "${A3S_USE_OCR_HOME}/.install.lock"
          stage="${RUNNER_TEMP}/a3s-use-ocr-assets-${{ needs.validate.outputs.version }}"
          install -d "${stage}/ocr-models" "${stage}/ocr-skills"
          cp -R "${A3S_USE_OCR_HOME}/." "${stage}/ocr-models/"
          cp -R skills/. "${stage}/ocr-skills/"
          cp LICENSE THIRD_PARTY_NOTICES.md "${stage}/"
          tar czf "a3s-use-ocr-assets-${{ needs.validate.outputs.version }}.tar.gz" \
            -C "${stage}" .
      - uses: actions/upload-artifact@v4
        with:
          name: a3s-use-ocr-assets
          path: a3s-use-ocr-assets-${{ needs.validate.outputs.version }}.tar.gz

  binaries:
    needs: validate
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: macos-latest
            target: aarch64-apple-darwin
            name: darwin-arm64
          - os: macos-15-intel
            target: x86_64-apple-darwin
            name: darwin-x86_64
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
            name: linux-arm64
          - os: ubuntu-24.04
            target: x86_64-unknown-linux-gnu
            name: linux-x86_64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            name: windows-x86_64
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --release --locked --target "${{ matrix.target }}"
      - name: Package Unix binary
        if: runner.os != 'Windows'
        shell: bash
        run: |
          set -euo pipefail
          archive="a3s-use-ocr-${{ needs.validate.outputs.version }}-${{ matrix.name }}.tar.gz"
          stage="${RUNNER_TEMP}/a3s-use-ocr-${{ matrix.name }}"
          install -d "${stage}"
          install -m 0755 \
            "target/${{ matrix.target }}/release/a3s-use-ocr" \
            "${stage}/a3s-use-ocr"
          cp LICENSE README.md THIRD_PARTY_NOTICES.md "${stage}/"
          tar czf "${archive}" -C "${stage}" .
          echo "ARCHIVE=${archive}" >> "${GITHUB_ENV}"
      - name: Package Windows binary
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          $archive = "a3s-use-ocr-${{ needs.validate.outputs.version }}-${{ matrix.name }}.zip"
          $stage = Join-Path $env:RUNNER_TEMP "a3s-use-ocr-${{ matrix.name }}"
          New-Item -ItemType Directory -Force -Path $stage | Out-Null
          Copy-Item "target/${{ matrix.target }}/release/a3s-use-ocr.exe" $stage
          Copy-Item LICENSE,README.md,THIRD_PARTY_NOTICES.md $stage
          Compress-Archive -Path "$stage/*" -DestinationPath $archive
          "ARCHIVE=$archive" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
      - uses: actions/upload-artifact@v4
        with:
          name: a3s-use-ocr-${{ matrix.name }}
          path: ${{ env.ARCHIVE }}

  publish-crate:
    needs: validate
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - id: auth
        uses: rust-lang/crates-io-auth-action@v1
      - run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

  release:
    needs: [validate, assets, binaries, publish-crate]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true
      - name: Generate checksums
        shell: bash
        run: |
          cd artifacts
          sha256sum *.tar.gz *.zip > checksums.txt
      - uses: softprops/action-gh-release@v2
        with:
          files: artifacts/*