fix gh-actions scpt
This commit is contained in:
@@ -13,6 +13,32 @@ get_cargo_version() {
|
||||
grep '^version = ' "$PROJECT_ROOT/Cargo.toml" | cut -d'"' -f2
|
||||
}
|
||||
|
||||
# Fallback function for when jq is not available
|
||||
update_package_version_fallback() {
|
||||
local package_file="$1"
|
||||
local version="$2"
|
||||
|
||||
# Get current version using grep/sed
|
||||
local old_version=$(grep '"version"' "$package_file" | sed 's/.*"version":\s*"\([^"]*\)".*/\1/')
|
||||
|
||||
# Skip update if version is already correct
|
||||
if [[ "$old_version" == "$version" ]]; then
|
||||
echo "✅ $(basename "$package_file"): Already up to date ($version)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Update version using sed
|
||||
if sed -i.bak "s/\"version\":\s*\"[^\"]*\"/\"version\": \"$version\"/" "$package_file"; then
|
||||
rm -f "$package_file.bak"
|
||||
echo "✅ Updated $(basename "$package_file"): $old_version → $version (sed)"
|
||||
return 0
|
||||
else
|
||||
rm -f "$package_file.bak"
|
||||
echo "❌ Failed to update $package_file with sed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to update package.json version using jq
|
||||
update_package_version() {
|
||||
local package_file="$1"
|
||||
@@ -23,27 +49,30 @@ update_package_version() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if jq is available
|
||||
# Check if jq is available, fallback to sed if not
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "❌ jq is required but not installed. Please install jq first."
|
||||
return 1
|
||||
echo "⚠️ jq not found, using sed fallback for $package_file"
|
||||
return update_package_version_fallback "$package_file" "$version"
|
||||
fi
|
||||
|
||||
# Get current version using jq
|
||||
local old_version=$(jq -r '.version' "$package_file")
|
||||
|
||||
# Skip update if version is already correct
|
||||
if [[ "$old_version" == "$version" ]]; then
|
||||
echo "✅ $(basename "$package_file"): Already up to date ($version)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Update version using jq (with proper formatting)
|
||||
local temp_file=$(mktemp)
|
||||
jq --arg version "$version" '.version = $version' "$package_file" > "$temp_file"
|
||||
|
||||
# Replace original file if jq succeeded
|
||||
if [[ $? -eq 0 ]]; then
|
||||
if jq --arg version "$version" '.version = $version' "$package_file" > "$temp_file" 2>/dev/null; then
|
||||
mv "$temp_file" "$package_file"
|
||||
echo "✅ Updated $(basename "$package_file"): $old_version → $version"
|
||||
return 0
|
||||
else
|
||||
rm -f "$temp_file"
|
||||
echo "❌ Failed to update $package_file"
|
||||
echo "❌ Failed to update $package_file with jq"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -59,6 +88,7 @@ main() {
|
||||
fi
|
||||
|
||||
echo "📦 Cargo.toml version: $version"
|
||||
echo "🔍 Project root: $PROJECT_ROOT"
|
||||
echo "🔄 Syncing versions..."
|
||||
|
||||
# List of package.json files to update
|
||||
@@ -68,13 +98,25 @@ main() {
|
||||
)
|
||||
|
||||
local updated_count=0
|
||||
local failed_count=0
|
||||
|
||||
for package in "${packages[@]}"; do
|
||||
if update_package_version "$package" "$version"; then
|
||||
((updated_count++))
|
||||
else
|
||||
((failed_count++))
|
||||
echo "⚠️ Failed to update: $package"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "✅ Successfully synced $updated_count package.json files"
|
||||
echo "📊 Summary: $updated_count updated, $failed_count failed"
|
||||
|
||||
if [[ $failed_count -gt 0 ]]; then
|
||||
echo "❌ Some files failed to update"
|
||||
exit 1
|
||||
else
|
||||
echo "✅ Successfully synced all package.json files"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run main function
|
||||
|
Reference in New Issue
Block a user