name: ci

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

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
      -
        name: Login to DockerHub
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      -
        name: Build and push
        if: ${{ github.event_name != 'pull_request' }}
        run: |
          docker buildx build --platform=linux/amd64 -t ${{ secrets.DOCKERHUB_USERNAME }}/aquery:${{github.sha}} .
          docker push ${{ secrets.DOCKERHUB_USERNAME }}/aquery:${{github.sha}}
          docker tag ${{ secrets.DOCKERHUB_USERNAME }}/aquery:${{github.sha}} ${{ secrets.DOCKERHUB_USERNAME }}/aquery:latest
          docker push ${{ secrets.DOCKERHUB_USERNAME }}/aquery:latest          
