name: Snyk report update
on:
  schedule:
    - cron: '0 0 * * 0' # midnight every Sunday

permissions:
  contents: read

jobs:
  snyk-report:
    permissions:
      contents: write  # To push snyk reports
    if: github.repository == 'argoproj/argo-cd'
    name: Update Snyk report in the docs directory
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout code
        uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Build reports
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
        run: |
          make snyk-report
          git config --global user.email 'ci@argoproj.com'
          git config --global user.name 'CI'
          git add docs/snyk/index.md
          git add docs/snyk/*/*.html
          git commit -m "[Bot] Update Snyk reports"
          git push
