cloudflare-speed-cli 1.0.8

CLI tool for Cloudflare speed testing with TUI interface
name: Push Docker Image to ghcr.io

on:
  workflow_run:
    workflows: ["Release"]
    types: [completed]
  workflow_dispatch:

permissions:
  contents: read
  packages: write

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    # For workflow_run: only run if the Release workflow succeeded on a tag push
    # (skip PR runs of Release). workflow_dispatch is always allowed.
    if: >-
      ${{
        github.event_name == 'workflow_dispatch' ||
        (github.event.workflow_run.conclusion == 'success' &&
         github.event.workflow_run.event == 'push')
      }}

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

      # The image repackages the static musl binaries already built and
      # published by the Release workflow (cargo-dist), so no compilation
      # happens here. For workflow_run the triggering tag is used; for
      # workflow_dispatch the latest published release is used.
      - name: Determine release tag
        id: ref
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          if [ "${{ github.event_name }}" = "workflow_run" ]; then
            echo "tag=${{ github.event.workflow_run.head_branch }}" >> "$GITHUB_OUTPUT"
          else
            echo "tag=$(gh release view --repo "$GITHUB_REPOSITORY" --json tagName -q .tagName)" >> "$GITHUB_OUTPUT"
          fi

      - name: Download release binaries
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          mkdir -p dist/amd64 dist/arm64
          gh release download "${{ steps.ref.outputs.tag }}" --repo "$GITHUB_REPOSITORY" \
            --pattern '*-x86_64-unknown-linux-musl.tar.xz' \
            --pattern '*-aarch64-unknown-linux-musl.tar.xz'
          tar -xJf cloudflare-speed-cli-x86_64-unknown-linux-musl.tar.xz --strip-components=1 -C dist/amd64
          tar -xJf cloudflare-speed-cli-aarch64-unknown-linux-musl.tar.xz --strip-components=1 -C dist/arm64

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v4

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

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

      - name: Lowercase owner
        id: owner
        run: echo "name=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"

      - name: Build and push Docker image
        uses: docker/build-push-action@v7
        with:
          context: .
          file: Dockerfile.ghcr
          push: true
          platforms: linux/amd64,linux/arm64
          tags: |
            ghcr.io/${{ steps.owner.outputs.name }}/cloudflare-speed-cli:${{ steps.ref.outputs.tag }}
            ghcr.io/${{ steps.owner.outputs.name }}/cloudflare-speed-cli:latest