name: benchmark
on:
  push:
    branches:
      - master
      - cluster
    paths-ignore:
      - "docs/**"
      - "**.md"
      - "dashboards/**"
      - "deployment/**.yml"
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
      - labeled
    branches:
      - master
      - cluster
    paths-ignore:
      - "docs/**"
      - "**.md"
      - "dashboards/**"
      - "deployment/**.yml"
permissions:
  contents: read
  packages: write

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  build-streamaggr-benchmark-image:
    name: build
    runs-on: ubuntu-latest
    if: contains(github.event.pull_request.labels.*.name, 'streamaggr-benchmark')
    steps:
      - name: Code checkout
        uses: actions/checkout@v4

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

      - name: Package VMAgent Docker image for benchmark
        run: |
          SKIP_SCRATCH_BUILD=true \
          DOCKER_BUILD_OPTS='--cache-to type=gha,mode=max --cache-from type=gha' \
          PKG_TAG=${{ github.event.pull_request.head.sha }} \
          DOCKER_REGISTRY=ghcr.io \
          TARGET_PLATFORM=linux/amd64 make publish-vmagent