name: Build and push image to Docker Hub

on:
  # Build and push to registry for all git pushes, mark as 'latest' only for
  # main branch.
  push:
  # For pull requests, build but don't push.
  pull_request:

env:
  PUSH_TO_MASTER: ${{ github.event_name == 'push' && endsWith(github.ref, '/master') }}

jobs:
  build:
    name: Build and optionally push the image to Docker Hub
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Work out docker tags
        uses: crazy-max/ghaction-docker-meta@v1
        id: docker_meta
        with:
          images: yacoob/aib2ofx
          tag-sha: true
      - name: Set up docker builder (buildx)
        uses: docker/setup-buildx-action@v1
      - name: Log in to docker hub
        # Skip registry push for pull_requests.
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}
      - name: Build and optionally push the docker image
        uses: docker/build-push-action@v2
        with:
          target: aib2ofx
          context: .
          # Skip registry push for pull_requests.
          push: ${{ github.event_name != 'pull_request' }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          tags: |
            ${{ steps.docker_meta.outputs.tags }}
            ${{ env.PUSH_TO_MASTER == 'true' && 'yacoob/aib2ofx:latest' }}
Add docker image building action.
Add docker image building action.
