name: Release Builds

on:
  release:
    types: [published]

jobs:
  build:
    if: "!github.event.release.prerelease"
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.3
          extensions: opcache, gd
          coverage: none
        env:
          COMPOSER_TOKEN: ${{ secrets.GLOBAL_TOKEN }}

      - name: Install Dependencies
        run: |
          sudo apt-get -y update -qq  < /dev/null > /dev/null
          sudo apt-get -y install -qq git zip < /dev/null > /dev/null

      - name: Retrieval of Builder Scripts
        run: |
          # Real Grav URL
          curl --silent -H "Authorization: token ${{ secrets.GLOBAL_TOKEN }}" -H "Accept: application/vnd.github.v3.raw" ${{ secrets.BUILD_SCRIPT_URL }} --output build-grav.sh

          # Development Local URL
          # curl ${{ secrets.BUILD_SCRIPT_URL }} --output build-grav.sh

      - name: Grav Builder
        run: |
          bash ./build-grav.sh

      - name: Upload Grav Release Assets
        id: upload-release-asset
        uses: alexellis/upload-assets@0.2.3
        env:
          GITHUB_TOKEN: ${{ secrets.GLOBAL_TOKEN }}
        with:
          asset_paths: '["./grav-dist/*.zip"]'

  slack:
    name: Slack
    needs: build
    runs-on: ubuntu-latest
    if: always()
    steps:
      - uses: technote-space/workflow-conclusion-action@v2
      - uses: 8398a7/action-slack@v3
        with:
          status: failure
          fields: repo,message,author,action
          icon_emoji: ':octocat:'
          author_name: 'Github Action Build'
          text: '🚚 Automated Build Failure'
        env:
          GITHUB_TOKEN: ${{ secrets.GLOBAL_TOKEN }}
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        if: env.WORKFLOW_CONCLUSION == 'failure'
