name: Nightly build without cache

on:
  schedule:
    # strange schedule to reduce the risk of DDOS GitHub infra
    - cron: "48 4 * * *"
  workflow_dispatch:

jobs:
  build:
    uses: ./.github/workflows/build.yml
    with:
      no-build-cache: true
    secrets:
      GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

  test:
    uses: ./.github/workflows/test.yml
    with:
      no-build-cache: true
    secrets:
      GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

  testLatestDeps:
    uses: ./.github/workflows/test-latest-deps.yml
    with:
      no-build-cache: true
    secrets:
      GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

  smoke-test:
    uses: ./.github/workflows/smoke-test.yml
    with:
      no-build-cache: true
    secrets:
      GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}

  # muzzle is intentionally not included in the nightly-no-cache build because
  # it doesn't use gradle cache anyways and so is already covered by the normal nightly build

  examples:
    uses: ./.github/workflows/examples.yml
    with:
      no-build-cache: true

  # markdown-link-check is intentionally not included in the nightly-no-cache build because
  # it doesn't use gradle cache anyways and so is already covered by the normal nightly build

  issue:
    name: Open issue on failure
    needs: [ build, test, testLatestDeps, smoke-test, examples ]
    runs-on: ubuntu-latest
    if: always()
    steps:
      # run this action to get workflow conclusion
      # You can get conclusion by env (env.WORKFLOW_CONCLUSION)
      - uses: technote-space/workflow-conclusion-action@v2.2

      - uses: actions/checkout@v3

      - uses: JasonEtco/create-an-issue@v2.6
        if: env.WORKFLOW_CONCLUSION == 'failure' # notify only if failure
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          filename: .github/templates/workflow-failed.md
