name: Build and Push Docker Image

on:
  push:
    tags:
      - 'v*'

  workflow_dispatch:

jobs:
  docker:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Log in to Docker registry
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}

      - name: Build Docker image
        run: |
          docker build \
            --build-arg VERSION=${{ github.ref_name }} \
            -t gabehf/music-importer:${{ github.ref_name }} \
            -t gabehf/music-importer:latest \
            .

      - name: Push Docker image
        run: |
          docker push gabehf/music-importer:${{ github.ref_name }}
          docker push gabehf/music-importer:latest
