orbit-tui 1.2.0

Terminal UI for AWS - navigate, observe, and manage AWS resources
# Triggered by the tag that release-plz pushes after a release PR merge.
# release-plz handles the Cargo.toml bump, changelog, crates.io publish
# and version tag; this workflow adds multi-platform binary builds,
# GitHub release and a Docker image.

name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  packages: write

env:
  CRATE_NAME: orbit-tui
  BINARY_NAME: orbit
  DESCRIPTION: "Terminal UI for AWS"
  HOMEPAGE: "https://github.com/doughlass/orbit"
  DOCKER_IMAGE: orbit

jobs:
  version-check:
    name: Verify Version Match
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}
    steps:
      - name: Checkout
        uses: actions/checkout@v7

      - name: Get version
        id: get_version
        run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Check version match
        run: |
          TAG_VERSION=${{ steps.get_version.outputs.version }}
          CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')

          echo "Tag version: $TAG_VERSION"
          echo "Cargo.toml version: $CARGO_VERSION"

          if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
            echo "❌ Version mismatch!"
            exit 1
          fi
          echo "✅ Versions match!"

  build-linux:
    needs: version-check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - x86_64-unknown-linux-musl
          - aarch64-unknown-linux-musl
    steps:
      - name: Checkout
        uses: actions/checkout@v7

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

      - name: Install cross
        run: cargo install cross

      - name: Build
        run: cross build --release --target ${{ matrix.target }}
        env:
          PROJECT_VERSION: ${{ needs.version-check.outputs.version }}

      - name: Package
        run: |
          cd target/${{ matrix.target }}/release
          tar -czf ../../../${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz ${{ env.BINARY_NAME }}

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.CRATE_NAME }}-${{ matrix.target }}
          path: ${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz

  build-macos:
    needs: version-check
    runs-on: macos-latest
    strategy:
      matrix:
        target:
          - x86_64-apple-darwin
          - aarch64-apple-darwin
    steps:
      - name: Checkout
        uses: actions/checkout@v7

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

      - name: Build
        run: cargo build --release --target ${{ matrix.target }}
        env:
          PROJECT_VERSION: ${{ needs.version-check.outputs.version }}

      - name: Package
        run: |
          cd target/${{ matrix.target }}/release
          tar -czf ../../../${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz ${{ env.BINARY_NAME }}

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.CRATE_NAME }}-${{ matrix.target }}
          path: ${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz

  build-windows:
    needs: version-check
    runs-on: windows-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: x86_64-pc-windows-msvc

      - name: Build
        run: cargo build --release --target x86_64-pc-windows-msvc
        env:
          PROJECT_VERSION: ${{ needs.version-check.outputs.version }}

      - name: Package
        shell: bash
        run: |
          cd target/x86_64-pc-windows-msvc/release
          ls -R
          7z a ../../../${{ env.CRATE_NAME }}-x86_64-pc-windows-msvc.zip ${{ env.BINARY_NAME }}.exe

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.CRATE_NAME }}-x86_64-pc-windows-msvc
          path: ${{ env.CRATE_NAME }}-x86_64-pc-windows-msvc.zip

  release:
    needs: [build-linux, build-macos, build-windows]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout
        uses: actions/checkout@v7

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          pattern: ${{ env.CRATE_NAME }}-*
          merge-multiple: true

      - name: Generate checksums
        run: sha256sum ${{ env.CRATE_NAME }}-* > checksums.txt

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            ${{ env.CRATE_NAME }}-*
            checksums.txt
          generate_release_notes: true

  docker:
    needs: [release, version-check]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Extract metadata for Docker
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}
          tags: |
            type=semver,pattern={{version}},value=v${{ needs.version-check.outputs.version }}
            type=semver,pattern={{major}}.{{minor}},value=v${{ needs.version-check.outputs.version }}
            type=semver,pattern={{major}},value=v${{ needs.version-check.outputs.version }}
            type=raw,value=latest

      - name: Build and push Docker image
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ./Dockerfile
          push: true
          platforms: linux/amd64
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

  homebrew:
    needs: [release, version-check]
    runs-on: ubuntu-latest
    steps:
      - name: Download checksums
        run: |
          curl -sL \
            "https://github.com/${{ github.repository }}/releases/download/v${{ needs.version-check.outputs.version }}/checksums.txt" \
            -o checksums.txt

      - name: Parse checksums
        id: shas
        run: |
          echo "darwin_amd64=$(grep x86_64-apple-darwin checksums.txt | awk '{print $1}')" >> $GITHUB_OUTPUT
          echo "darwin_arm64=$(grep aarch64-apple-darwin checksums.txt | awk '{print $1}')" >> $GITHUB_OUTPUT
          echo "linux_amd64=$(grep x86_64-unknown-linux-musl checksums.txt | awk '{print $1}')" >> $GITHUB_OUTPUT
          echo "linux_arm64=$(grep aarch64-unknown-linux-musl checksums.txt | awk '{print $1}')" >> $GITHUB_OUTPUT

      - name: Checkout homebrew-tap
        uses: actions/checkout@v7
        with:
          repository: ${{ github.repository_owner }}/homebrew-tap
          token: ${{ secrets.RELEASE_PLZ_TOKEN }}
          path: homebrew-tap

      - name: Update formula
        run: |
          VERSION="${{ needs.version-check.outputs.version }}"
          REPO="${{ github.repository }}"

          cat > homebrew-tap/Formula/orbit.rb << EOF
          class Orbit < Formula
            desc "${{ env.DESCRIPTION }}"
            homepage "${{ env.HOMEPAGE }}"
            version "${VERSION}"
            license "MIT"

            if OS.mac?
              if Hardware::CPU.arm?
                url "https://github.com/${REPO}/releases/download/v${VERSION}/${{ env.CRATE_NAME }}-aarch64-apple-darwin.tar.gz",
                    using: CurlDownloadStrategy,
                    headers: ["Accept: application/octet-stream"]
                sha256 "${{ steps.shas.outputs.darwin_arm64 }}"
              else
                url "https://github.com/${REPO}/releases/download/v${VERSION}/${{ env.CRATE_NAME }}-x86_64-apple-darwin.tar.gz",
                    using: CurlDownloadStrategy,
                    headers: ["Accept: application/octet-stream"]
                sha256 "${{ steps.shas.outputs.darwin_amd64 }}"
              end
            end

            on_linux do
              if Hardware::CPU.arm?
                url "https://github.com/${REPO}/releases/download/v${VERSION}/${{ env.CRATE_NAME }}-aarch64-unknown-linux-musl.tar.gz",
                    using: CurlDownloadStrategy,
                    headers: ["Accept: application/octet-stream"]
                sha256 "${{ steps.shas.outputs.linux_arm64 }}"
              else
                url "https://github.com/${REPO}/releases/download/v${VERSION}/${{ env.CRATE_NAME }}-x86_64-unknown-linux-musl.tar.gz",
                    using: CurlDownloadStrategy,
                    headers: ["Accept: application/octet-stream"]
                sha256 "${{ steps.shas.outputs.linux_amd64 }}"
              end
            end

            def install
              bin.install "${{ env.BINARY_NAME }}"
            end

            test do
              system "#{bin}/${{ env.BINARY_NAME }}", "--version"
            end
          end
          EOF

      - name: Commit and push
        run: |
          cd homebrew-tap
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/orbit.rb
          git commit -m "orbit ${{ needs.version-check.outputs.version }}" || echo "No changes"
          git push