env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

name: Build windmill-extra

on:
  workflow_dispatch:
    inputs:
      tag:
        description: "Tag for the image"
        required: false
        default: "dev"
        type: string

permissions: write-all

jobs:
  sleep:
    runs-on: ubicloud
    steps:
      - name: Sleep for 900 seconds waiting for pypi to update index
        if: startsWith(github.ref, 'refs/tags/v')
        run: sleep 900
        shell: bash
  build_extra:
    runs-on: ubicloud
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.ref }}
          fetch-depth: 0

      - uses: depot/setup-action@v1

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: |
            ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-extra
          flavor: |
            latest=false
          tags: |
            type=raw,value=${{ github.event.inputs.tag }}
            type=sha,enable=true,priority=100,prefix=,suffix=,format=short

      - name: Login to registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        uses: depot/build-push-action@v1
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          push: true
          file: "./docker/DockerfileExtra"
          tags: |
            ${{ steps.meta.outputs.tags }}
          labels: |
            ${{ steps.meta.outputs.labels }}
