name: weekly-docs
# runs every monday at 9 am
on:
  schedule:
    - cron: "0 9 * * 1"
  workflow_dispatch: # allows to run manually for testing

jobs:
  check-docs:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@master

      - name: Check Markdown links
        uses: gaurav-nelson/github-action-markdown-link-check@v1
        id: markdown-link-check
        # checks all markdown files from /docs including all subfolders
        with:
          use-quiet-mode: "yes"
          use-verbose-mode: "yes"
          config-file: ".github/workflows/mlc_config.json"
          folder-path: "docs/"
          file-path: "./README.md"

      - name: Send Slack notification
        if: failure()
        run: |
          curl -X POST -H 'Content-type: application/json' -d '{"msg":"Broken links found in the documentation. Please check the logs at ${{ env.LOGS_URL }}"}' ${{ secrets.DOCS_LINK_SLACK_WEBHOOK }}
          echo "Sent Slack notification"
        env:
          LOGS_URL: https://github.com/coder/coder/actions/runs/${{ github.run_id }}
