name: Build docker images

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-20.04
    steps:
      # Checks out repository under $GITHUB_WORKSPACE, so we can access it
      - uses: actions/checkout@v2

      # Runs build script
      - name: Run build script
        run: |
          # always push
          export PUSH=true
          # if this is a push to master and not a PR, also push latest - GITHUB_HEAD_REF is only set for PRs
          if [ -z ${GITHUB_HEAD_REF+x} ] && [ "$GITHUB_REF" == "refs/heads/master" ]; then export PUSH=latest; fi
          # log into quay.io so we can push
          echo "$QUAY_PASSWORD" | docker login quay.io -u "$QUAY_USER" --password-stdin
          # build and push all components. try to pull and re-use layers from images for all parent commits.
          'CACHE_FROM=$(git rev-list HEAD -n1 --parents | cut -d" " -f 2-) ./build'
          
