name: Daytona Eval Image

on:
  push:
    branches:
      - dev
    paths:
      - .devcontainer/Dockerfile.daytona-vnc
      - .devcontainer/start-daytona-vnc.sh
      - .devcontainer/start-daytona-electron.sh
      - .devcontainer/start-daytona-recording.sh
      - .github/workflows/daytona-eval-image.yml
      - pnpm-lock.yaml
      - package.json
  workflow_dispatch:

permissions:
  contents: read
  packages: write

concurrency:
  group: daytona-eval-image-${{ github.ref }}
  cancel-in-progress: true

env:
  IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/openwork-eval-vnc

jobs:
  build-and-push:
    name: Build and Push Daytona Eval Image
    runs-on: blacksmith-4vcpu-ubuntu-2404
    steps:
      - name: Checkout
        uses: actions/checkout@v6

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

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ github.token }}

      - name: Normalize image name
        id: image
        shell: bash
        run: |
          set -euo pipefail
          image="${IMAGE_NAME,,}"
          echo "name=$image" >> "$GITHUB_OUTPUT"

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .devcontainer
          file: .devcontainer/Dockerfile.daytona-vnc
          platforms: linux/arm64
          push: true
          tags: |
            ${{ steps.image.outputs.name }}:dev
            ${{ steps.image.outputs.name }}:${{ github.sha }}
          labels: |
            org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
            org.opencontainers.image.revision=${{ github.sha }}
