name: Publish to Dockerhub

on:
  push:
    tags:
      - 'v*'

jobs:
  push_to_registry:
    name: Push Docker image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579

      - name: Log in to Docker Hub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@e5622373a38e60fb6d795a4421e56882f2d7a681
        with:
          images: krateng/maloja
          # generate Docker tags based on the following events/attributes
          tags: |
            type=semver,pattern={{version}}
          flavor: |
            latest=true

      - name: Build and push Docker image
        uses: docker/build-push-action@7f9d37fa544684fb73bfe4835ed7214c255ce02b
        with:
          context: .
          file: Containerfile
          #platforms: linux/amd64,linux/arm64
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

      - name: Update Readme and short description
        uses: peter-evans/dockerhub-description@1cf9afbac3c5d2fdc66416a464c2c38260cb6f8d
        continue-on-error: true
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
          repository: krateng/maloja
          short-description: ${{ github.event.repository.description }}
