@@ -280,6 +280,35 @@ jobs:
280280 path : ${{ inputs.ruby-app-directory != '' && format('{0}/Gemfile.lock', inputs.ruby-app-directory) || 'Gemfile.lock' }}
281281 name : ${{ github.event.repository.name }}-Gemfile-lock.txt
282282
283+ - name : Set up Go (required for Go workspace vendoring)
284+ if : ${{ hashFiles('go.work') != '' }}
285+ uses : actions/setup-go@v5
286+ with :
287+ go-version : ' stable'
288+
289+ - name : Prepare Go workspace for BlackDuck scanning
290+ if : ${{ hashFiles('go.work') != '' }}
291+ run : |
292+ # Extract all relative module paths from go.work.
293+ # grep -oE handles both single-line (use ./path) and block (use (\n ./path\n)) syntax
294+ # because it matches any './' sequence anywhere in the file.
295+ GO_WORK_DEPTH=$(grep -oE '\./[^[:space:]"/)]+' go.work \
296+ | awk -F'/' '{print NF-1}' \
297+ | sort -rn | head -1)
298+ # Default to 1 if all modules sit at root or grep returned nothing
299+ [[ -z "$GO_WORK_DEPTH" || "$GO_WORK_DEPTH" -le 0 ]] && GO_WORK_DEPTH=1
300+ echo "GO_WORK_DETECTOR_DEPTH=${GO_WORK_DEPTH}" >> "$GITHUB_ENV"
301+ echo "Go workspace detector search depth: ${GO_WORK_DEPTH}"
302+ # Vendor all workspace dependencies (requires Go 1.22+).
303+ # If this fails (e.g. private module network issue) Detect will still run
304+ # with the correct search depth and resolve modules via the Go toolchain.
305+ if go work vendor; then
306+ echo "GOFLAGS=-mod=vendor" >> "$GITHUB_ENV"
307+ echo "Successfully vendored Go workspace dependencies"
308+ else
309+ echo "go work vendor did not complete; Detect will resolve modules via Go toolchain"
310+ fi
311+
283312 - name : Construct BlackDuck detect arguments
284313 id : detect-args
285314 run : |
@@ -303,6 +332,16 @@ jobs:
303332 # RAPID scan for PRs - automatically compares against baseline from target branch
304333 DETECT_ARGS="${DETECT_ARGS} --detect.blackduck.scan.mode=RAPID"
305334 fi
335+
336+ # If repo uses a Go workspace, increase detector search depth so Detect finds
337+ # go.mod files inside module subdirectories (default depth 0 = root only = only Git found).
338+ # Also set accuracy.required=NONE: Detect's default HIGH accuracy check fails for multi-module
339+ # Go workspaces (FAILURE_ACCURACY_NOT_MET / exit 15) because it can't fully resolve the graph
340+ # via `go list` across workspace modules. Vendor mode resolves deps; accuracy=NONE lets it proceed.
341+ if [[ -f "go.work" ]]; then
342+ DETECT_ARGS="${DETECT_ARGS} --detect.detector.search.depth=${{ env.GO_WORK_DETECTOR_DEPTH }}"
343+ DETECT_ARGS="${DETECT_ARGS} --detect.accuracy.required=NONE"
344+ fi
306345
307346 echo "DETECT_ARGS=${DETECT_ARGS}" >> $GITHUB_ENV
308347 echo "Constructed detect_args: ${DETECT_ARGS}"
0 commit comments