name: audit

on:
  schedule:
    - cron: '0 10 * * *'
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  scan:
    name: npm audit
    runs-on: ubuntu-latest

    strategy:
      matrix:
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
        node-version: [18.x]

    steps:
      - name: Checkout code
        uses: actions/checkout@v5

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          # version from package.json
          run_install: false

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v5
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'pnpm'

      - name: Install dependencies
        run: |
          echo ::group::Install dependencies
          echo "install"
          pnpm --silent install 
          echo "show outdated (if any)"
          pnpm outdated --depth=3 || echo "::warning::🕸️ you must think about update your dependencies :)"
          echo ::endgroup::

      - name: pnpm audit
        run: |
          echo "pnpm audit"
          pnpm audit || echo "::error::❌ there is an audit issue in your dependencies"