name: Check Documentation URLs

on:
  release:
    types: [published]
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:

jobs:
  check-docs-urls:
    runs-on: ubuntu-latest

    timeout-minutes: 5

    steps:
      - uses: actions/checkout@v3.5.3

      - uses: pnpm/action-setup@v2.4.0

      - uses: actions/setup-node@v3.7.0
        with:
          node-version: 18.x
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Build nodes-base
        run: pnpm --filter @n8n/client-oauth2 --filter n8n-workflow --filter n8n-core --filter n8n-nodes-base build

      - name: Test URLS
        run: node scripts/validate-docs-links.js

      - name: Notify Slack on failure
        uses: act10ns/slack@v2.0.0
        if: failure()
        with:
          status: ${{ job.status }}
          channel: '#updates-build-alerts'
          webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
          message: Documentation URLs check failed (${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
