name: Run Trivy scanner for Go version vulnerabilities
on:
  push:
    branches:
      - master
  pull_request:
jobs:
  trivy:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - 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@master
        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'
