name: Create and publish a Docker image

on: push

jobs:
  docker:
    runs-on: docker
    
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Repository meta
        id: repository
        run: |
          registry=${{ github.server_url }}
          registry=${registry##http*://}
          echo "registry=${registry}" >> "$GITHUB_OUTPUT"
          repository="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
          echo "repository=${repository}" >> "$GITHUB_OUTPUT"

      - name: Docker meta
        uses: docker/metadata-action@v5
        id: docker
        with:
          images: ${{ steps.repository.outputs.registry }}/${{ steps.repository.outputs.repository }}

      - name: Build and push
        uses: https://codeberg.org/umglurf/kaniko-action@main
        with:
          credentials: |
            ${{ steps.repository.outputs.registry }}=${{ github.repository }}:${{ secrets.PACKAGES_TOKEN }}            
          destinations: |
            ${{ steps.docker.outputs.tags }}
          push: true
