context-footprint 0.1.0

A static analysis tool for measuring architectural context exposure in codebases.
Documentation
name: Package and Release

on:
  push:
    tags:
      - 'v*'

jobs:
  # 1. Build and Publish Cargo Crate
  publish-cargo:
    name: Publish to Cargo
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Protocol Buffers compiler
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Publish to crates.io
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  # 2. Build and Push Multi-platform Docker Image
  publish-docker:
    name: Build and Push Docker Image
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
        
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
        
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
          
      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository }}
          tags: |
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=sha
            type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

  # 3. Build Binaries for different platforms
  build-binaries:
    name: Build Binaries
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: cftool-linux-x86_64
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            artifact_name: cftool-linux-aarch64
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: cftool-macos-x86_64
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: cftool-macos-aarch64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: cftool-windows-x86_64

    steps:
      - uses: actions/checkout@v4
      
      - name: Install Protocol Buffers compiler
        shell: bash
        run: |
          if [ "${{ runner.os }}" = "Linux" ]; then
            sudo apt-get update && sudo apt-get install -y protobuf-compiler
          elif [ "${{ runner.os }}" = "macOS" ]; then
            brew install protobuf
          elif [ "${{ runner.os }}" = "Windows" ]; then
            choco install protoc
          fi

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

      - name: Install cross-compilation tools (Linux arm64)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Build binary
        shell: bash
        run: |
          if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then
            export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
          fi
          cargo build --release --target ${{ matrix.target }}

      - name: Prepare artifact
        shell: bash
        run: |
          mkdir dist
          if [ "${{ runner.os }}" = "Windows" ]; then
            cd target/${{ matrix.target }}/release
            7z a ../../../dist/${{ matrix.artifact_name }}.zip cftool.exe
          else
            cd target/${{ matrix.target }}/release
            tar czf ../../../dist/${{ matrix.artifact_name }}.tar.gz cftool
          fi

      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.artifact_name }}
          path: dist/*

  # 4. Create GitHub Release and upload binaries
  github-release:
    name: Create GitHub Release
    needs: [build-binaries, publish-docker]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: artifacts/**/*/*.{tar.gz,zip}
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}