name: Build, Test and Publish
on:
  pull_request:
    branches: 
      - master
  push:
    branches:
      - master
  schedule:
    - cron: '0 2 * * 0' # Weekly on Sundays at 02:00

jobs:
  publish:
    if: github.event_name == 'push'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
        with:
          fetch-depth: 1
      - name: Publish to Docker Hub
        uses: elgohr/Publish-Docker-Github-Action@master
        with:
          name: azuracast/azuracast_web_v2
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          cache: ${{ github.event_name != 'schedule' }}
  test:
    needs: [publish]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
      with:
        fetch-depth: 1
    - name: Set up test environment
      run: |
        cp azuracast.sample.env azuracast.env
        cp docker-compose.sample.yml docker-compose.yml
        cp docker-compose.testing.yml docker-compose.override.yml
        chmod 777 tests/_output/
        docker-compose build web
        docker-compose run --user="azuracast" --rm web azuracast_install
    - name: Run test suite
      run: |
        docker-compose run --user="azuracast" --rm web composer test
    - name: Echo test output directory
      if: failure()
      run: |
        cat tests/_output/*.html

name: Build, Test and Publish
on:
  pull_request:
    branches: 
      - master
  push:
    branches:
      - master
  schedule:
    - cron: '0 2 * * 0' # Weekly on Sundays at 02:00

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
        with:
          fetch-depth: 1
      - name: Publish to Docker Hub
        uses: elgohr/Publish-Docker-Github-Action@master
        if: github.event_name == 'push'
        with:
          name: azuracast/azuracast_web_v2
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
          cache: ${{ github.event_name != 'schedule' }}
  test:
    needs: [publish]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
      with:
        fetch-depth: 1
    - name: Set up test environment
      run: |
        cp azuracast.sample.env azuracast.env
        cp docker-compose.sample.yml docker-compose.yml
        cp docker-compose.testing.yml docker-compose.override.yml
        chmod 777 tests/_output/
        docker-compose build web
        docker-compose run --user="azuracast" --rm web azuracast_install
    - name: Run test suite
      run: |
        docker-compose run --user="azuracast" --rm web composer test
    - name: Echo test output directory
      if: failure()
      run: |
        cat tests/_output/*.html

Make pull requests still run regular test suite.
Make pull requests still run regular test suite.