55 pull_request_target :
66 branches : [ "main" ]
77 schedule :
8- - cron : ' 6 1 * * 0'
8+ - cron : ' 15 0 * * 0'
99 workflow_dispatch :
1010
1111permissions :
1717 runs-on : [ ubuntu-latest ]
1818 steps :
1919 - name : Checkout code
20- if : github.event_name != 'pull_request_target'
2120 uses : actions/checkout@v4
2221
2322 - name : Run Black Duck Full SCA Scan (Push, Manual Trigger or Schedule)
2625 env :
2726 DETECT_PROJECT_USER_GROUPS : opencomponentmodel
2827 DETECT_PROJECT_VERSION_DISTRIBUTION : opensource
29- DETECT_SOURCE_PATH : ./
3028 DETECT_EXCLUDED_DIRECTORIES : .bridge
3129 DETECT_BLACKDUCK_SIGNATURE_SCANNER_ARGUMENTS : ' --min-scan-interval=0'
3230 NODE_TLS_REJECT_UNAUTHORIZED : true
@@ -43,12 +41,55 @@ jobs:
4341 env :
4442 DETECT_PROJECT_USER_GROUPS : opencomponentmodel
4543 DETECT_PROJECT_VERSION_DISTRIBUTION : opensource
46- DETECT_SOURCE_PATH : ./
4744 DETECT_EXCLUDED_DIRECTORIES : .bridge
4845 NODE_TLS_REJECT_UNAUTHORIZED : true
4946 with :
5047 github_token : ${{ secrets.GITHUB_TOKEN }}
5148 blackducksca_url : ${{ secrets.BLACKDUCK_URL }}
5249 blackducksca_token : ${{ secrets.BLACKDUCK_API_TOKEN }}
5350 blackducksca_scan_full : false
54- blackducksca_prComment_enabled : true
51+
52+ # Check Black Duck status and upload status file as artifact.
53+ # This step is required to be set as always(), so the status file is uploaded even if the Black Duck scan fails.
54+ - name : Check Black Duck status
55+ if : always()
56+ id : check_blackduck_status
57+ shell : bash
58+ run : |
59+ # Use find to locate status file
60+ STATUS_FILE=$(find "/home/runner/work/ocm-cicd-playground/ocm-cicd-playground/.bridge/Blackduck SCA Detect Execution/detect/runs" -name "status.json" | head -n 1)
61+
62+ if [ -z "$STATUS_FILE" ]; then
63+ echo "::warning file=status.json::No Black Duck status file found"
64+ exit 1
65+ else
66+ ISSUE_COUNT=$(jq '.issues | length' "$STATUS_FILE")
67+
68+ if [[ "$ISSUE_COUNT" -eq 0 ]]; then
69+ echo "status_file_path=$STATUS_FILE" >> "$GITHUB_OUTPUT"
70+ echo "Black Duck scan successfully executed. Status JSON will be uploaded as an artifact to the GitHub action.""
71+ else
72+ # Issues exist, fail step but save file path for upload
73+ echo "status_file_path=$STATUS_FILE" >> "$GITHUB_OUTPUT"
74+ echo "::error file=$STATUS_FILE::Black Duck scan had issues:"
75+
76+ # Extract and print issue details
77+ jq -r '.issues[] | "\(.type) : \(.title)\n Details: \((.messages | if type == "string" then [.] else . end) | join("; "))"' status.json | \
78+ while IFS= read -r line; do
79+ echo "::error::$line"
80+ done
81+ echo
82+ echo "Black Duck Overall Status:"
83+ jq -r '.overallStatus[0].key + " - " + .overallStatus[0].status' "$STATUS_FILE"
84+ echo
85+ echo "Status JSON will be uploaded as an artifact to the GitHub action."
86+ exit 1
87+ fi
88+ fi
89+
90+ - name : Upload Blackduck status file
91+ if : always()
92+ uses : actions/upload-artifact@v4
93+ with :
94+ name : status-json
95+ path : ${{ steps.check_blackduck_status.outputs.status_file_path }}
0 commit comments