Skip to content

Commit d9d6ad6

Browse files
committed
chore: evaluate version incase version is not fixed
Signed-off-by: Sonu Saha <[email protected]>
1 parent db09e49 commit d9d6ad6

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

Diff for: .github/workflows/sbom.yml

+38-13
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,52 @@ jobs:
6363
echo "Processing RubyGem: $name"
6464
gem_name=$(echo "$name" | tr -d '"')
6565
version=$(echo "$versionInfo" | tr -d '"')
66-
# Check if the version contains a version constraint (e.g., ~>, >=, <=)
66+
67+
# If version has a comparison operator (e.g., ~>, >=, <=)
6768
if [[ "$versionInfo" =~ [\~\>\<\=\ ] ]]; then
68-
echo "Skipping call to rubygems.org for version constraint: $versionInfo"
69-
continue # Skip processing for this gem versionInfo
69+
echo "Evaluating version constraint: $versionInfo"
70+
71+
# Extract the base version (e.g., "2.11" from "~> 2.11")
72+
base_version=$(echo "$versionInfo" | sed -E 's/[^\d.]//g')
73+
74+
# Get the list of available versions from RubyGems API
75+
api_url="https://rubygems.org/api/v2/rubygems/${gem_name}/versions.json"
76+
available_versions=$(curl -s "$api_url" | jq -r '.[].version')
77+
78+
# Find the valid version according to the constraint
79+
valid_version=$(echo "$available_versions" | grep -E "^$base_version" | sort -V | head -n 1)
80+
81+
if [ -z "$valid_version" ]; then
82+
echo "No valid version found for constraint $versionInfo"
83+
continue
84+
fi
85+
86+
# Proceed with the valid version
87+
echo "Using version: $valid_version for $gem_name"
88+
api_url="https://rubygems.org/api/v2/rubygems/${gem_name}/versions/${valid_version}.json"
89+
response=$(curl -s "$api_url")
90+
91+
# Extract relevant fields from the response
92+
new_license=$(echo "$response" | jq -r '.licenses[0] // "None"')
93+
new_source_code_url=$(echo "$response" | jq -r '.source_code_uri // "None"')
94+
new_vendor=$(echo "$response" | jq -r '.authors // "None"')
7095
else
71-
# Proceed with making the call to rubygems.org
72-
echo "Making call to rubygems.org for fixed version: $versionInfo"
73-
# Your logic to call rubygems.org
96+
# Handle fixed version
97+
echo "Fixed version: $versionInfo"
98+
api_url="https://rubygems.org/api/v2/rubygems/${gem_name}/versions/${versionInfo}.json"
99+
response=$(curl -s "$api_url")
100+
new_license=$(echo "$response" | jq -r '.licenses[0] // "None"')
101+
new_source_code_url=$(echo "$response" | jq -r '.source_code_uri // "None"')
102+
new_vendor=$(echo "$response" | jq -r '.authors // "None"')
74103
fi
75-
api_url="https://rubygems.org/api/v2/rubygems/${gem_name}/versions/${version}.json"
76-
response=$(curl -s "$api_url")
77-
echo "Response: $response"
78-
new_license=$(echo "$response" | jq -r '.licenses[0] // "None"')
79-
echo "License: $new_license"
80-
new_source_code_url=$(echo "$response" | jq -r '.source_code_uri // "None"')
81-
new_vendor=$(echo "$response" | jq -r '.authors // "None"')
82104
else
105+
# Default values if not a RubyGem
83106
new_license="None"
84107
new_source_code_url="None"
85108
new_vendor="None"
86109
fi
110+
111+
# Write updated values to temp CSV
87112
echo "$name,$SPDXID,$versionInfo,$downloadLocation,$externalRefs,$new_license,$new_source_code_url,$new_vendor" >> "$TEMP_CSV"
88113
done
89114
mv "$TEMP_CSV" "${FILE_PREFIX}-sbom.csv"

0 commit comments

Comments
 (0)