name: Docker

on:
  push:
    branches:
      - master
    tags:
      - '*'
  pull_request:
    branches:
      - master

jobs:

  docker-image:
    name: Build Image
    runs-on: ubuntu-latest

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

      - name: Setup docker
        uses: docker/setup-buildx-action@v2

      - name: Log into container registry
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build image
        run: make docker

      - name: Test image
        run: make docker-tests

      - name: Publish image
        if: github.event_name != 'pull_request'
        run: make docker-publish
