@@ -73,28 +73,28 @@ jobs:
7373 exit 1
7474 fi
7575
76- # Derive current version from latest tag for this package
77- # If no tags exist, fall back to package.json version
78- # Note: Uses git's version sorting which correctly handles semver including prereleases
79- latest_tag=$(git tag -l "$package@*" --sort=-version:refname | head -n1)
80-
81- if [ -n "$latest_tag" ]; then
82- # Extract version from tag (format: package@version)
83- current_version="${latest_tag#$package@}"
84- echo "Found latest tag: $latest_tag (version: $current_version)"
85- else
86- # No tags exist, use package.json version as starting point
87- package_json_path="packages/$package/package.json"
88- if [ ! -r "$package_json_path" ]; then
89- echo "package.json not found or not readable: $package_json_path"
90- exit 1
91- fi
76+ # Derive current version from npm registry (fallback to package.json if unpublished)
77+ package_json_path="packages/$package/package.json"
78+ if [ ! -r "$package_json_path" ]; then
79+ echo "package.json not found or not readable: $package_json_path"
80+ exit 1
81+ fi
82+
83+ package_name="$(node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));process.stdout.write(typeof pkg.name==='string'?pkg.name.trim():'')" "$package_json_path")"
84+ if [ -z "$package_name" ]; then
85+ echo "package.json does not contain a valid name field: $package_json_path"
86+ exit 1
87+ fi
88+
89+ if ! current_version="$(npm view "$package_name" version 2>/dev/null | tr -d '\r\n')"; then
9290 current_version="$(node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync(process.argv[1],'utf8'));process.stdout.write(typeof pkg.version==='string'?pkg.version.trim():'')" "$package_json_path")"
9391 if [ -z "$current_version" ]; then
94- echo "package.json does not contain a valid version field: $package_json_path"
92+ echo "Could not fetch npm version and package.json does not contain a valid version field: $package_json_path"
9593 exit 1
9694 fi
97- echo "No existing tags found, using package.json version: $current_version"
95+ echo "Could not fetch version from npm for $package_name, using package.json version: $current_version"
96+ else
97+ echo "Using npm registry version for $package_name: $current_version"
9898 fi
9999
100100 if ! [[ "$current_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)([.-][0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
@@ -231,6 +231,7 @@ jobs:
231231 fi
232232
233233 git commit -m 'chore(release): bump ${{ steps.metadata.outputs.package }} to v${{ steps.metadata.outputs.version }}'
234+ git pull --rebase origin "${{ github.ref_name }}"
234235 git push origin "HEAD:${{ github.ref_name }}"
235236 echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
236237
0 commit comments