name: acceptance tests

on:
  pull_request:
    branches:
      - 'main'
  push:
    branches:
      - 'develop'

jobs:
  run-acceptance-tests:
    name: Run acceptance tests
    runs-on: ubuntu-latest
    steps:
      - name: Set up Go 1.17
        uses: actions/setup-go@v2
        with:
          go-version: '^1.17'

      - name: Check out code into the Go module directory
        uses: actions/checkout@v2

      - name: Setup acceptance test
        run: ./acceptanceTests/setup.sh

      - name: Create k8s users and change context
        env:
          USERNAME_UNRESTRICTED: user-with-clusterwide-access
          USERNAME_RESTRICTED: user-with-restricted-access
        run: |
          ./acceptanceTests/create_user.sh "${USERNAME_UNRESTRICTED}"
          ./acceptanceTests/create_user.sh "${USERNAME_RESTRICTED}"
          kubectl apply -f cli/cmd/permissionFiles/permissions-all-namespaces-tap.yaml
          kubectl config use-context ${USERNAME_UNRESTRICTED}

      - name: Test
        run: make acceptance-test

      - name: Slack notification on failure
        uses: ravsamhq/notify-slack-action@v1
        if: always()
        with:
          status: ${{ job.status }}
          notification_title: 'Mizu {workflow} has {status_message}'
          message_format: '{emoji} *{workflow}* {status_message} during <{run_url}|run>, after commit: <{commit_url}|{commit_sha}>'
          footer: 'Linked Repo <{repo_url}|{repo}>'
          notify_when: 'failure'
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
