kelper 0.0.30

A CLI tool to serve as swiss-army knife for your operations on Kubernetes pods and nodes
Documentation
name: release
on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"

jobs:
  check_version:
    name: Check Cargo.toml version matches Git tag
    runs-on: ubuntu-latest
    outputs:
      tag_version: ${{ steps.get_version.outputs.TAG_VERSION }}
      cargo_version: ${{ steps.get_version.outputs.CARGO_VERSION }}
    steps:
      - uses: actions/checkout@v4
      - name: Install toml-cli
        run: cargo install toml-cli@0.2.3
      - name: Get versions
        id: get_version
        run: |
          TAG_VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//')
          CARGO_VERSION=$(toml get Cargo.toml package.version | tr -d '"')
          echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_OUTPUT
          echo "CARGO_VERSION=$CARGO_VERSION" >> $GITHUB_OUTPUT
      - name: Verify versions match
        run: |
          echo "Git tag version: ${{ steps.get_version.outputs.tag_version }}"
          echo "Cargo.toml version: ${{ steps.get_version.outputs.cargo_version }}"
          if [ "${{ steps.get_version.outputs.tag_version }}" != "${{ steps.get_version.outputs.cargo_version }}" ]; then
            echo "Error: Git tag version (${{ steps.get_version.outputs.tag_version }}) does not match Cargo.toml version (${{ steps.get_version.outputs.cargo_version }})."
            echo "Please run 'scripts/cargo_release.sh' to update the cargo version before generating tag."
            exit 1
          fi
  build:
    name: Build multi-platform binaries
    needs: check_version
    strategy:
      fail-fast: false
      matrix:
        platform:
          - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
          - { os: macos-latest, target: x86_64-apple-darwin }
          - { os: macos-latest, target: aarch64-apple-darwin }
          - { os: windows-latest, target: x86_64-pc-windows-msvc }
    runs-on: ${{ matrix.platform.os }}
    steps:
      - uses: actions/checkout@v4
      - name: Building ${{ matrix.platform.os }}-${{ matrix.platform.target }}
        uses: ./.github/actions/build-cli
        with:
          runner_os: ${{ matrix.platform.os }}
          target_platform: ${{ matrix.platform.target }}
          rust_toolchain: "stable"
      - name: Create compressed binary for krew on Windows environment
        if: matrix.platform.os == 'windows-latest'
        run: |
          Copy-Item -Path LICENSE -Destination target/${{ matrix.platform.target }}/release/
          Compress-Archive -Path target/${{ matrix.platform.target }}/release/kelper.exe, target/${{ matrix.platform.target }}/release/LICENSE -DestinationPath target/${{ matrix.platform.target }}/release/kelper-${{ matrix.platform.target }}.zip
          Move-Item -Path target/${{ matrix.platform.target }}/release/kelper.exe -Destination target/${{ matrix.platform.target }}/release/kelper-${{ matrix.platform.target }}.exe

      - name: Create compressed binary for krew on Unix-like environments
        if: matrix.platform.os != 'windows-latest'
        run: |
          cp LICENSE target/${{ matrix.platform.target }}/release/
          tar -czvf target/${{ matrix.platform.target }}/release/kelper-${{ matrix.platform.target }}.tar.gz -C target/${{ matrix.platform.target }}/release kelper LICENSE
          mv target/${{ matrix.platform.target }}/release/kelper target/${{ matrix.platform.target }}/release/kelper-${{ matrix.platform.target }}
      - name: Upload Build Artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.platform.target }}
          path: |
            target/${{ matrix.platform.target }}/release/kelper-${{ matrix.platform.target }}
            target/${{ matrix.platform.target }}/release/*.zip
            target/${{ matrix.platform.target }}/release/*.exe
            target/${{ matrix.platform.target }}/release/*.tar.gz

  release:
    name: Create Release, Publish Crate, and Update Homebrew & Krew
    runs-on: ubuntu-latest
    # needs: [update_version, build]
    needs: build
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Download All Build Artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist/
      - name: List downloaded files
        run: ls -lahR dist/

      - name: Create GitHub Release and Upload Assets
        id: create_release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/**/*
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Update Homebrew Tap
        uses: ./.github/actions/update-homebrew
        with:
          tap_repo: aliabbasjaffri/homebrew-kelper
          release_tag: ${{ github.ref_name }}
          repository: ${{ github.repository }}
          amd64_artifact_name: kelper-x86_64-apple-darwin
          arm64_artifact_name: kelper-aarch64-apple-darwin
          amd64_artifact_path: dist/x86_64-apple-darwin/kelper-x86_64-apple-darwin
          arm64_artifact_path: dist/aarch64-apple-darwin/kelper-aarch64-apple-darwin
          tap_token: ${{ secrets.HOMEBREW_TAP_TOKEN }}

      - name: Update new version for kelper in krew-index
        uses: rajatjindal/krew-release-bot@v0.0.47
        with:
          krew_template_file: .krew/kelper.yml

  release-cargo:
    name: Release to cargo.io
    runs-on: ubuntu-latest
    needs: [release]
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Publish to crates.io
        uses: actions-rs/cargo@v1
        with:
          command: publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}