Skip to content

Commit 039d896

Browse files
committed
chore: update Blackduck scan workflow to ignore workflow paths and improve status checking
On-behalf-of: Gerald Morrison (SAP) <gerald.morrison@sap.com> Signed-off-by: Gerald Morrison (SAP) <gerald.morrison@sap.com>
1 parent 606e7c4 commit 039d896

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

.github/workflows/blackduck_scan.yaml

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
name: Blackduck SCA Scan
22
on:
33
push:
4+
paths-ignore:
5+
- '.github/workflows/**'
46
branches: [ "main" ]
57
pull_request_target:
8+
paths-ignore:
9+
- '.github/workflows/**'
610
branches: [ "main" ]
711
schedule:
8-
- cron: '6 1 * * 0'
12+
- cron: '6 0 * * 0'
913
workflow_dispatch:
1014

1115
permissions:
@@ -25,7 +29,6 @@ jobs:
2529
env:
2630
DETECT_PROJECT_USER_GROUPS: opencomponentmodel
2731
DETECT_PROJECT_VERSION_DISTRIBUTION: opensource
28-
DETECT_SOURCE_PATH: ./
2932
DETECT_EXCLUDED_DIRECTORIES: .bridge
3033
DETECT_BLACKDUCK_SIGNATURE_SCANNER_ARGUMENTS: '--min-scan-interval=0'
3134
NODE_TLS_REJECT_UNAUTHORIZED: true
@@ -42,13 +45,55 @@ jobs:
4245
env:
4346
DETECT_PROJECT_USER_GROUPS: opencomponentmodel
4447
DETECT_PROJECT_VERSION_DISTRIBUTION: opensource
45-
DETECT_SOURCE_PATH: ./
4648
DETECT_EXCLUDED_DIRECTORIES: .bridge
4749
NODE_TLS_REJECT_UNAUTHORIZED: true
4850
with:
4951
github_token: ${{ secrets.GITHUB_TOKEN }}
5052
blackducksca_url: ${{ secrets.BLACKDUCK_URL }}
5153
blackducksca_token: ${{ secrets.BLACKDUCK_API_TOKEN }}
5254
blackducksca_scan_full: false
53-
blackducksca_prComment_enabled: true
54-
55+
56+
# Check Black Duck status and upload status file as artifact.
57+
# This step is required to be set as always(), so the status file is uploaded even if the Black Duck scan fails.
58+
- name: Check Black Duck status
59+
if: always()
60+
id: check_blackduck_status
61+
shell: bash
62+
run: |
63+
# Use find to locate status file
64+
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)
65+
66+
if [ -z "$STATUS_FILE" ]; then
67+
echo "::warning file=status.json::No Black Duck status file found"
68+
exit 1
69+
else
70+
ISSUE_COUNT=$(jq '.issues | length' "$STATUS_FILE")
71+
72+
if [[ "$ISSUE_COUNT" -eq 0 ]]; then
73+
echo "status_file_path=$STATUS_FILE" >> "$GITHUB_OUTPUT"
74+
echo "Black Duck scan successfully executed. Status JSON will be uploaded as an artifact to the GitHub action.""
75+
else
76+
# Issues exist, fail step but save file path for upload
77+
echo "status_file_path=$STATUS_FILE" >> "$GITHUB_OUTPUT"
78+
echo "::error file=$STATUS_FILE::Black Duck scan had issues:"
79+
80+
# Extract and print issue details
81+
jq -r '.issues[] | "\(.type): \(.title)\n Details: \((.messages | if type == "string" then [.] else . end) | join("; "))"' status.json | \
82+
while IFS= read -r line; do
83+
echo "::error::$line"
84+
done
85+
echo
86+
echo "Black Duck Overall Status:"
87+
jq -r '.overallStatus[0].key + " - " + .overallStatus[0].status' "$STATUS_FILE"
88+
echo
89+
echo "Status JSON will be uploaded as an artifact to the GitHub action."
90+
exit 1
91+
fi
92+
fi
93+
94+
- name: Upload Blackduck status file
95+
if: always()
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: status-json
99+
path: ${{ steps.check_blackduck_status.outputs.status_file_path }}

0 commit comments

Comments
 (0)