name: Build Docker Package

on:
  workflow_dispatch:
  push:
    branches: [main]
  release:
    types: [published]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

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

      - name: Log in to Gitea Container Registry
        uses: docker/login-action@v2
        with:
          registry: git.ewenlau.net
          username: ${{ secrets.GIT_USERNAME }}
          password: ${{ secrets.GIT_PASSWORD }}

      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: git.ewenlau.net/${{ secrets.GIT_USERNAME }}/tg-dev-srv-bot
          tags: |
            type=raw,value=dev,enable=${{ github.event_name == 'push' }}
            type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
            type=raw,value=latest,enable=${{ github.event_name == 'release' }}

      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}