name: ci-docker
on:
  schedule:
    - cron: "30 6 * * *"
  push:  
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
  workflow_dispatch:

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: antsx/antspy
      -
        name: Login to DockerHub
        if: ${{ github.repository == 'ANTsX/ANTsPy' }}
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Build and push
        uses: docker/build-push-action@v6
        with:
          context: .
          platforms: linux/amd64
          push: ${{ github.repository == 'ANTsX/ANTsPy' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) }}
          tags: ${{ github.event_name == 'schedule' && 'antsx/antspy:nightly,antsx/antspy:latest' || steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
