# Publish Docker image to Docker Hub
#
# Triggers:
#   - Push to main/master branch
#   - Release tags (v*)
#   - Manual dispatch
#
# Images are published to: docker.io/mvfolino68/pathway-viz
#
# Required secrets:
#   - DOCKERHUB_USERNAME: Your Docker Hub username (mvfolino68)
#   - DOCKERHUB_TOKEN: Docker Hub access token (create at hub.docker.com/settings/security)

name: Docker Publish

on:
  push:
    branches: [main, master]
    tags: ["v*"]
  workflow_dispatch:

env:
  REGISTRY: docker.io
  IMAGE_NAME: mvfolino68/pathway-viz

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Extract metadata
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
          tags: |
            type=ref,event=branch
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }}

      - name: Build and push
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
