cloudflare-speed-cli 1.0.4

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: Determine ref to build
        id: ref
        run: |
          if [ "${{ github.event_name }}" = "workflow_run" ]; then
            echo "ref=${{ github.event.workflow_run.head_branch }}" >> "$GITHUB_OUTPUT"
          else
            echo "ref=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
          fi

      - name: Checkout code
        uses: actions/checkout@v4
        with:
          ref: ${{ steps.ref.outputs.ref }}

      - 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: 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@v6
        with:
          context: .
          push: true
          platforms: linux/amd64,linux/arm64
          tags: |
            ghcr.io/${{ steps.owner.outputs.name }}/cloudflare-speed-cli:${{ steps.ref.outputs.ref }}
            ghcr.io/${{ steps.owner.outputs.name }}/cloudflare-speed-cli:latest