name: Check OpenAPI updates

on:
  schedule:
    # - cron: "*/5 * * * *" # every 5 minutes (for testing)
    - cron: "0 16 * * *" # every day at 4pm UTC

jobs:
  check-open-api-spec-updates:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Check OpenAPI updates
        run: make openapi-spec-check-updates
  on-failure:
    runs-on: ubuntu-latest
    if: ${{ always() && (needs.check-open-api-spec-updates.result == 'failure' || needs.check-open-api-spec-updates.result == 'timed_out') }}
    needs:
      - check-open-api-spec-updates
    steps:
      - uses: actions/checkout@v4
      - name: Send Slack notification
        uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # v2
        env:
          SLACK_CHANNEL: proj-cli
          SLACK_COLOR: ${{ job.status }}
          SLACK_ICON_EMOJI: ':launchdarkly:'
          SLACK_TITLE: ':warning: The OpenAPI spec has changed and resources need to be updated.'
          SLACK_USERNAME: github
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
