|
1 | 1 | name: Download SBOM from Insights and Convert to CSV
|
2 | 2 |
|
3 |
| -# on: |
4 |
| -# workflow_dispatch: |
5 |
| - |
6 |
| - |
7 | 3 | # # NOTE: We would probably want to run this workflow on every push to main and not on pull requests
|
8 |
| -# # on: |
9 |
| -# # push: |
10 |
| -# # branches: |
11 |
| -# # - main |
| 4 | +# on: |
| 5 | +# push: |
| 6 | +# branches: |
| 7 | +# - main |
12 | 8 |
|
13 | 9 | on:
|
14 | 10 | pull_request:
|
@@ -47,14 +43,38 @@ jobs:
|
47 | 43 |
|
48 | 44 | - name: Convert SBOM to CSV using jq
|
49 | 45 | run: |
|
| 46 | + echo "name,SPDXID,versionInfo,downloadLocation,externalRefs,license,source_code_url,vendor" > "${FILE_PREFIX}-sbom.csv" |
50 | 47 | jq -r '
|
51 | 48 | .sbom.packages[] | [
|
52 | 49 | .name,
|
53 | 50 | .SPDXID,
|
54 | 51 | .versionInfo,
|
55 | 52 | .downloadLocation,
|
56 |
| - ( .externalRefs[]? | .referenceLocator ) |
57 |
| - ] | @csv' "${FILE_PREFIX}-sbom.json" > "${FILE_PREFIX}-sbom.csv" |
| 53 | + ( .externalRefs[]? | .referenceLocator ), |
| 54 | + "None", "None", "None" |
| 55 | + ] | @csv' "${FILE_PREFIX}-sbom.json" >> "${FILE_PREFIX}-sbom.csv" |
| 56 | +
|
| 57 | + - name: Enrich SBOM CSV with RubyGems Data |
| 58 | + run: | |
| 59 | + TEMP_CSV="${FILE_PREFIX}-sbom-temp.csv" |
| 60 | + echo "name,SPDXID,versionInfo,downloadLocation,externalRefs,license,source_code_url,vendor" > "$TEMP_CSV" |
| 61 | + tail -n +2 "${FILE_PREFIX}-sbom.csv" | while IFS=, read -r name SPDXID versionInfo downloadLocation externalRefs license source_code_url vendor; do |
| 62 | + if [[ "$downloadLocation" == *"rubygems.org"* ]]; then |
| 63 | + gem_name=$(echo "$name" | tr -d '"') |
| 64 | + version=$(echo "$versionInfo" | tr -d '"') |
| 65 | + api_url="https://rubygems.org/api/v2/rubygems/${gem_name}/versions/${version}.json" |
| 66 | + response=$(curl -s "$api_url") |
| 67 | + new_license=$(echo "$response" | jq -r '.licenses[0] // "None"') |
| 68 | + new_source_code_url=$(echo "$response" | jq -r '.source_code_uri // "None"') |
| 69 | + new_vendor=$(echo "$response" | jq -r '.authors // "None"') |
| 70 | + else |
| 71 | + new_license="None" |
| 72 | + new_source_code_url="None" |
| 73 | + new_vendor="None" |
| 74 | + fi |
| 75 | + echo "$name,$SPDXID,$versionInfo,$downloadLocation,$externalRefs,$new_license,$new_source_code_url,$new_vendor" >> "$TEMP_CSV" |
| 76 | + done |
| 77 | + mv "$TEMP_CSV" "${FILE_PREFIX}-sbom.csv" |
58 | 78 |
|
59 | 79 | - name: Verify SBOM CSV File
|
60 | 80 | run: |
|
|
0 commit comments