name: Run Trivy scanner for Go version vulnerabilities
on:
  push:
    branches:
      - master
  schedule:
    - cron: '0 0 * * *'  # Run daily at midnight UTC
jobs:
  trivy:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

      - name: Get Go version
        id: go-version
        run: |
          GO_VERSION=$(cat prow.sh  | grep "configvar CSI_PROW_GO_VERSION_BUILD" | awk '{print $3}' | sed 's/"//g')
          echo "version=$GO_VERSION" >> $GITHUB_OUTPUT

      - name: Run Trivy scanner for Go version vulnerabilities
        uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1  # v0.35.0
        with:
          image-ref: 'golang:${{ steps.go-version.outputs.version }}'
          format: 'table'
          exit-code: '1'
          ignore-unfixed: true
          vuln-type: 'library'
          severity: 'CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN'
