roam-sdk 0.4.0

Roam Research SDK and terminal UI client
Documentation
name: Release Beta

on:
  workflow_run:
    workflows: ["CI"]
    branches: [main]
    types: [completed]

permissions:
  contents: write

jobs:
  build:
    if: github.event.workflow_run.conclusion == 'success'
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            cross: false
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            cross: true
          - target: x86_64-apple-darwin
            os: macos-15-large
            cross: false
          - target: aarch64-apple-darwin
            os: macos-latest
            cross: false
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            cross: false
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.workflow_run.head_sha }}

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

      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: Install cross
        if: matrix.cross
        run: cargo install cross --locked

      - name: Build with cross
        if: matrix.cross
        run: cross build --release --target ${{ matrix.target }}

      - name: Build
        if: "!matrix.cross"
        run: cargo build --release --target ${{ matrix.target }}

      - name: Rename binary (unix)
        if: runner.os != 'Windows'
        run: mv target/${{ matrix.target }}/release/roam roam-${{ matrix.target }}

      - name: Rename binary (windows)
        if: runner.os == 'Windows'
        run: mv target/${{ matrix.target }}/release/roam.exe roam-${{ matrix.target }}.exe

      - name: Upload artifact (unix)
        if: runner.os != 'Windows'
        uses: actions/upload-artifact@v4
        with:
          name: roam-${{ matrix.target }}
          path: roam-${{ matrix.target }}

      - name: Upload artifact (windows)
        if: runner.os == 'Windows'
        uses: actions/upload-artifact@v4
        with:
          name: roam-${{ matrix.target }}
          path: roam-${{ matrix.target }}.exe

  publish:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.workflow_run.head_sha }}

      - uses: actions/download-artifact@v4
        with:
          path: artifacts/

      - name: Prepare release
        id: prep
        run: |
          VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
          SHA=$(echo "${{ github.event.workflow_run.head_sha }}" | cut -c1-7)
          TAG="v${VERSION}-beta+${SHA}"
          echo "tag=$TAG" >> "$GITHUB_OUTPUT"
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"

      - name: Delete previous beta releases
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release list --json tagName,isPrerelease -q '.[] | select(.isPrerelease) | .tagName' | while read -r tag; do
            if echo "$tag" | grep -q "beta"; then
              gh release delete "$tag" --yes --cleanup-tag || true
            fi
          done

      - name: Create beta release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          # Collect all binaries
          FILES=()
          for dir in artifacts/roam-*/; do
            for file in "$dir"*; do
              [ -f "$file" ] && FILES+=("$file")
            done
          done

          gh release create "${{ steps.prep.outputs.tag }}" \
            --prerelease \
            --title "Beta ${{ steps.prep.outputs.tag }}" \
            --notes "Automated beta build from main branch (commit ${{ github.event.workflow_run.head_sha }})" \
            "${FILES[@]}"