name: Budibase Smoke Test

on:
 workflow_dispatch:
 schedule:
  - cron: "0 5 * * *" # every day at 5AM

jobs:
  release:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js 14.x
        uses: actions/setup-node@v1
        with:
          node-version: 14.x
      - run: yarn
      - run: yarn bootstrap
      - run: yarn build
      - name: Pull cypress.env.yaml from budibase-infra
        run: | 
          curl -H "Authorization: token ${{ secrets.GH_PERSONAL_TOKEN }}" \
          -H 'Accept: application/vnd.github.v3.raw' \
          -o packages/builder/cypress.env.json \
          -L https://api.github.com/repos/budibase/budibase-infra/contents/test/cypress.env.json
          wc -l packages/builder/cypress.env.json

      - name: Cypress run
        id: cypress
        continue-on-error: true
        uses: cypress-io/github-action@v2
        with:
          record: true
          install: false
          tag: nightly
          command: yarn test:e2e:ci:record
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
      
      - uses: actions/upload-artifact@v3
        with:
          name: Test Reports
          path: packages/builder/cypress/reports/testReport.html

      - name: Cypress Discord Notify
        run: yarn test:e2e:ci:notify
        env:
          CYPRESS_WEBHOOK_URL: ${{ secrets.BUDI_QA_WEBHOOK }}
          CYPRESS_OUTCOME: ${{ steps.cypress.outcome }}
          CYPRESS_DASHBOARD_URL: ${{ steps.cypress.outputs.dashboardUrl }}
          GITHUB_RUN_URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
