@@ -74,13 +74,25 @@ jobs:
7474 # If a specific package is requested via workflow_dispatch, just publish that one
7575 echo "matrix={\"package\":[\"$PACKAGE\"]}" >> $GITHUB_OUTPUT
7676 else
77- # Otherwise, identify all packages with changes since the last commit
7877 CHANGED_PACKAGES=()
7978 for pkg in $(ls -d packages/*); do
8079 PKG_NAME=$(basename "$pkg")
81- # For manual runs, include all packages. For automatic runs, only include packages with changes
80+ PKG_JSON="$pkg/package.json"
81+
82+ # Determine if the package has changed (or include all on manual trigger)
8283 if [ "$EVENT_NAME" == "workflow_dispatch" ] || ! git diff --quiet $COMMIT_SHA~1 $COMMIT_SHA -- "$pkg/"; then
83- CHANGED_PACKAGES+=("$PKG_NAME")
84+ HAS_VERSION=$(jq 'has("version")' "$PKG_JSON")
85+ if [ "$HAS_VERSION" == "false" ]; then
86+ # Include packages without version field
87+ CHANGED_PACKAGES+=("$PKG_NAME")
88+ else
89+ # For packages with version field, include only if version changed
90+ OLD_VERSION=$(git show $COMMIT_SHA~1:$PKG_JSON | jq -r '.version')
91+ NEW_VERSION=$(jq -r '.version' "$PKG_JSON")
92+ if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
93+ CHANGED_PACKAGES+=("$PKG_NAME")
94+ fi
95+ fi
8496 fi
8597 done
8698
@@ -115,13 +127,22 @@ jobs:
115127 node-version-file : ' .nvmrc'
116128 registry-url : ' https://registry.npmjs.org'
117129
130+ - name : Re-install npm
131+ # TODO: OIDC requires npm >=11.5.1.
132+ # Until Node.js v24 is LTS (with npm 11 as the default), we need to bump.
133+ run : npm install -g npm@11
134+
118135 - name : Publish
119136 working-directory : packages/${{ matrix.package }}
120137 run : |
121138 # Install deps
122139 pnpm install --frozen-lockfile
123- # Create a unique version using the commit SHA as a prerelease identifier
124- npm version --no-git-tag-version 1.0.1-$COMMIT_SHA
140+
141+ HAS_VERSION=$(jq 'has("version")' package.json)
142+ if [ "$HAS_VERSION" == "false" ]; then
143+ # Only bump version if package has no version field
144+ npm version --no-git-tag-version 1.0.1-$COMMIT_SHA
145+ fi
125146
126147 # Check if a custom publish script exists in package.json
127148 if jq -e '.scripts.publish' package.json > /dev/null; then
0 commit comments