---
name: Release Images

on:
  push:
    branches:
      - master
      - release-*

jobs:
  e2e:
    name: E2E
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repository
        uses: actions/checkout@v2

      - name: Reclaim free space
        run: |
          # cleanup 30GB+ of tools we don't need for our CI
          rm -rf /opt/ghc /usr/share/dotnet /usr/share/swift
          df -h
          free -h

      - name: Run E2E deployment and tests
        run: make e2e

      - name: Post mortem
        if: failure()
        run: make post-mortem

      - name: Clean up E2E deployment
        run: make cleanup

  release:
    name: Release Images
    needs: e2e
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Build new images
        env:
          IMAGES_ARGS: --nocache
        run: make images

      - name: Release the images
        env:
          QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }}
          QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }}
          IMAGES: lighthouse-agent lighthouse-coredns
        # Pass RELEASE_ARGS on the call, since GITHUB_REF set in the `env` directive doesn't get properly expanded
        run: make release RELEASE_ARGS="$IMAGES --tag '${GITHUB_REF##*/}'"
