name: Nightly builds

on:
  schedule: # Run every day at 03:00 UTC
    - cron: '0 3 * * *'
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    # only run this build in the main repository, not in forks
    if: github.repository == 'oauth2-proxy/oauth2-proxy'
    steps:
    - name: Check out code
      uses: actions/checkout@v4
      with:
        ref: master
        fetch-depth: 0
        fetch-tags: true

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v3

    - name: Set up Docker Buildx
      id: buildx
      uses: docker/setup-buildx-action@v3

    - name: Login to quay.io
      uses: docker/login-action@v3
      with:
        registry: quay.io/oauth2-proxy
        username: ${{ secrets.REGISTRY_USERNAME_NIGHTLY }}
        password: ${{ secrets.REGISTRY_PASSWORD_NIGHTLY }}

    - name: Build images
      run: |
        make nightly-build

    - name: Push images
      run: |
        make nightly-push
