dakera-cli 0.5.3

Command-line interface for Dakera AI Agent Memory Platform
name: Release

on:
  release:
    types: [published]

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            artifact: dk
          - target: aarch64-apple-darwin
            os: macos-latest
            artifact: dk
          - target: x86_64-apple-darwin
            os: macos-latest
            artifact: dk
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            artifact: dk.exe
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: Install cargo-zigbuild
        if: matrix.use_zigbuild == true
        run: |
          pip install ziglang
          cargo install cargo-zigbuild
      - name: Build (zigbuild)
        if: matrix.use_zigbuild == true
        run: cargo zigbuild --release --target ${{ matrix.target }}
      - name: Build (native)
        if: matrix.use_zigbuild != true
        run: cargo build --release --target ${{ matrix.target }}
      - name: Upload artifact
        uses: actions/upload-artifact@v7
        with:
          name: dk-${{ matrix.target }}
          path: target/${{ matrix.target }}/release/${{ matrix.artifact }}

  publish-crate:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable
      - name: Publish to crates.io
        run: |
          output=$(cargo publish 2>&1) && echo "$output" || {
            echo "$output"
            echo "$output" | grep -q "already exists" && echo "crate already published, skipping" || exit 1
          }
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  upload-binaries:
    name: Upload Release Binaries
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v8
      - name: Rename artifacts with platform names
        run: |
          mv dk-x86_64-unknown-linux-gnu/dk dk-x86_64-unknown-linux-gnu/dk-x86_64-unknown-linux-gnu
          mv dk-aarch64-apple-darwin/dk dk-aarch64-apple-darwin/dk-aarch64-apple-darwin
          mv dk-x86_64-apple-darwin/dk dk-x86_64-apple-darwin/dk-x86_64-apple-darwin
      - name: Upload binaries to release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            dk-x86_64-unknown-linux-gnu/dk-x86_64-unknown-linux-gnu
            dk-aarch64-apple-darwin/dk-aarch64-apple-darwin
            dk-x86_64-apple-darwin/dk-x86_64-apple-darwin
            dk-x86_64-pc-windows-msvc/dk.exe

  deploy-binary:
    name: Deploy Native Binary
    runs-on: ubuntu-latest
    needs: upload-binaries
    continue-on-error: true
    steps:
      - name: Download Linux binary artifact
        uses: actions/download-artifact@v8
        with:
          name: dk-x86_64-unknown-linux-gnu

      - name: Upload binary to server
        uses: appleboy/scp-action@ff85246acaad7bdce478db94a363cd2bf7c90345  # v1.0.0
        with:
          host: ${{ secrets.DEPLOY_HOST }}
          username: ${{ secrets.DEPLOY_USER }}
          key: ${{ secrets.DEPLOY_SSH_KEY }}
          source: "dk"
          target: "/tmp/"

      - name: Install binary on server
        uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262  # v1.0.3
        with:
          host: ${{ secrets.DEPLOY_HOST }}
          username: ${{ secrets.DEPLOY_USER }}
          key: ${{ secrets.DEPLOY_SSH_KEY }}
          script: |
            chmod +x /tmp/dk
            mv /tmp/dk /home/dakera/.local/bin/dk
            echo "✅ dk ${{ github.ref_name }} deployed"