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
|
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
|
# Function to update package.json version using jq
|
||||||
update_package_version() {
|
update_package_version() {
|
||||||
local package_file="$1"
|
local package_file="$1"
|
||||||
@@ -23,27 +49,30 @@ update_package_version() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if jq is available
|
# Check if jq is available, fallback to sed if not
|
||||||
if ! command -v jq &> /dev/null; then
|
if ! command -v jq &> /dev/null; then
|
||||||
echo "❌ jq is required but not installed. Please install jq first."
|
echo "⚠️ jq not found, using sed fallback for $package_file"
|
||||||
return 1
|
return update_package_version_fallback "$package_file" "$version"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get current version using jq
|
# Get current version using jq
|
||||||
local old_version=$(jq -r '.version' "$package_file")
|
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)
|
# Update version using jq (with proper formatting)
|
||||||
local temp_file=$(mktemp)
|
local temp_file=$(mktemp)
|
||||||
jq --arg version "$version" '.version = $version' "$package_file" > "$temp_file"
|
if jq --arg version "$version" '.version = $version' "$package_file" > "$temp_file" 2>/dev/null; then
|
||||||
|
|
||||||
# Replace original file if jq succeeded
|
|
||||||
if [[ $? -eq 0 ]]; then
|
|
||||||
mv "$temp_file" "$package_file"
|
mv "$temp_file" "$package_file"
|
||||||
echo "✅ Updated $(basename "$package_file"): $old_version → $version"
|
echo "✅ Updated $(basename "$package_file"): $old_version → $version"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
echo "❌ Failed to update $package_file"
|
echo "❌ Failed to update $package_file with jq"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -59,6 +88,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "📦 Cargo.toml version: $version"
|
echo "📦 Cargo.toml version: $version"
|
||||||
|
echo "🔍 Project root: $PROJECT_ROOT"
|
||||||
echo "🔄 Syncing versions..."
|
echo "🔄 Syncing versions..."
|
||||||
|
|
||||||
# List of package.json files to update
|
# List of package.json files to update
|
||||||
@@ -68,13 +98,25 @@ main() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
local updated_count=0
|
local updated_count=0
|
||||||
|
local failed_count=0
|
||||||
|
|
||||||
for package in "${packages[@]}"; do
|
for package in "${packages[@]}"; do
|
||||||
if update_package_version "$package" "$version"; then
|
if update_package_version "$package" "$version"; then
|
||||||
((updated_count++))
|
((updated_count++))
|
||||||
|
else
|
||||||
|
((failed_count++))
|
||||||
|
echo "⚠️ Failed to update: $package"
|
||||||
fi
|
fi
|
||||||
done
|
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
|
# Run main function
|
||||||
|
Reference in New Issue
Block a user