edgefirst-imu 3.0.0

EdgeFirst IMU Service for BNO08x sensors
# GitHub Actions workflow for publishing releases
#
# This workflow orchestrates release publishing when a version tag is pushed:
# - Creates GitHub Release with binaries and SBOM
# - Publishes to crates.io using trusted publisher
#
# Release Process:
# 1. Update version in Cargo.toml
# 2. Update CHANGELOG.md with version entry
# 3. Commit and push changes
# 4. Create and push tag: git tag v3.0.0 && git push --tags
#
# crates.io Trusted Publisher Setup:
# 1. Go to https://crates.io/crates/edgefirst-imu/settings
# 2. Add trusted publisher: EdgeFirstAI/imu, release.yml, publish-crates
#
# Action Versions (verified January 2026):
# - actions/checkout@v4
# - actions/download-artifact@v4
# - softprops/action-gh-release@v2
# - dtolnay/rust-toolchain@stable

name: Release

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
      - 'v[0-9]+.[0-9]+.[0-9]+-*'

permissions:
  contents: write
  id-token: write

jobs:
  prepare-release:
    name: Prepare Release
    runs-on: ubuntu-22.04
    outputs:
      version: ${{ steps.version.outputs.version }}
      changelog: ${{ steps.changelog.outputs.changelog }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Extract version from tag
        id: version
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "Extracted version: $VERSION"

      - name: Extract changelog for this version
        id: changelog
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}

          # Extract changelog section for this version
          if [ -f CHANGELOG.md ]; then
            CHANGELOG=$(awk -v ver="$VERSION" '
              /^## \['"$VERSION"'\]/ { found=1; next }
              found && /^## \[/ { exit }
              found { print }
            ' CHANGELOG.md)
          fi

          if [ -z "$CHANGELOG" ]; then
            echo "WARNING: No changelog entry found for version $VERSION"
            CHANGELOG="See commit history for details."
          fi

          echo "changelog<<EOF" >> $GITHUB_OUTPUT
          echo "$CHANGELOG" >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

  build-artifacts:
    name: Build Artifacts
    needs: prepare-release
    uses: ./.github/workflows/build.yml

  build-sbom:
    name: Generate SBOM
    needs: prepare-release
    uses: ./.github/workflows/sbom.yml

  run-tests:
    name: Run Tests
    needs: prepare-release
    uses: ./.github/workflows/test.yml

  create-github-release:
    name: Create GitHub Release
    runs-on: ubuntu-22.04
    needs:
      - prepare-release
      - build-artifacts
      - build-sbom
      - run-tests
    permissions:
      contents: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

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

      - name: Organize release assets
        run: |
          mkdir -p release-assets
          VERSION=${{ needs.prepare-release.outputs.version }}

          # Copy x86_64 binary
          if [ -f artifacts/packages-x86_64/edgefirst-imu-x86_64 ]; then
            cp artifacts/packages-x86_64/edgefirst-imu-x86_64 \
               release-assets/edgefirst-imu-linux-x86_64
          fi

          # Copy ARM64 binary
          if [ -f artifacts/packages-aarch64/edgefirst-imu-aarch64 ]; then
            cp artifacts/packages-aarch64/edgefirst-imu-aarch64 \
               release-assets/edgefirst-imu-linux-aarch64
          fi

          # Copy SBOM
          if [ -f artifacts/sbom/sbom.json ]; then
            cp artifacts/sbom/sbom.json \
               release-assets/edgefirst-imu-v${VERSION}-sbom.json
          fi

          echo "Release assets prepared:"
          ls -lh release-assets/

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          name: EdgeFirst IMU v${{ needs.prepare-release.outputs.version }}
          body: |
            # EdgeFirst IMU v${{ needs.prepare-release.outputs.version }}

            ## Installation

            ### From crates.io (Recommended)

            ```bash
            cargo install edgefirst-imu
            ```

            ### Download Binaries

            | Platform | Binary |
            |----------|--------|
            | Linux x86_64 | `edgefirst-imu-linux-x86_64` |
            | Linux ARM64 | `edgefirst-imu-linux-aarch64` |

            ```bash
            # Download and install (ARM64 example)
            wget https://github.com/EdgeFirstAI/imu/releases/download/v${{ needs.prepare-release.outputs.version }}/edgefirst-imu-linux-aarch64
            chmod +x edgefirst-imu-linux-aarch64
            sudo mv edgefirst-imu-linux-aarch64 /usr/local/bin/edgefirst-imu
            ```

            ## What's Changed

            ${{ needs.prepare-release.outputs.changelog }}

            ---

            **Full Documentation**: https://github.com/EdgeFirstAI/imu#readme
          files: |
            release-assets/*
          draft: false
          prerelease: ${{ contains(needs.prepare-release.outputs.version, '-') }}
          fail_on_unmatched_files: false

  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-22.04
    needs:
      - prepare-release
      - run-tests
    environment: crates-io

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish