Skip to content

Commit 31d7758

Browse files
authored
Merge pull request #3059 from gluestack/feat/update-npm-v
fix: fixed version of package changed
2 parents 6bc1e2b + ce82bbc commit 31d7758

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

.github/workflows/publish-production.yml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,37 @@ jobs:
126126
echo "Version changes detected"
127127
echo "version_changed=true" >> $GITHUB_OUTPUT
128128
129-
# Get the new version from the first package (assuming monorepo versioning)
130-
NEW_VERSION=$(node -e "
131-
const fs = require('fs');
132-
const packages = fs.readdirSync('packages');
133-
for (const pkg of packages) {
129+
# Get the new version from the packages that were actually modified by changesets
130+
MODIFIED_PACKAGES=$(git diff --name-only HEAD~1 | grep "packages/.*/package.json" || true)
131+
132+
if [ -z "$MODIFIED_PACKAGES" ]; then
133+
echo "No modified package.json files found, falling back to first non-private package"
134+
NEW_VERSION=$(node -e "
135+
const fs = require('fs');
136+
const packages = fs.readdirSync('packages');
137+
for (const pkg of packages) {
138+
try {
139+
const pkgJson = JSON.parse(fs.readFileSync(\`packages/\${pkg}/package.json\`, 'utf8'));
140+
if (!pkgJson.private) {
141+
console.log(pkgJson.version);
142+
break;
143+
}
144+
} catch (e) {}
145+
}
146+
")
147+
else
148+
echo "📋 Getting version from modified packages: $MODIFIED_PACKAGES"
149+
# Get version from the first modified package
150+
FIRST_MODIFIED=$(echo "$MODIFIED_PACKAGES" | head -n1)
151+
NEW_VERSION=$(node -e "
134152
try {
135-
const pkgJson = JSON.parse(fs.readFileSync(\`packages/\${pkg}/package.json\`, 'utf8'));
136-
if (!pkgJson.private) {
137-
console.log(pkgJson.version);
138-
break;
139-
}
140-
} catch (e) {}
141-
}
142-
")
153+
const pkg = JSON.parse(require('fs').readFileSync('$FIRST_MODIFIED', 'utf8'));
154+
console.log(pkg.version || '');
155+
} catch(e) { console.log(''); }
156+
")
157+
fi
158+
159+
echo "📋 Using version: $NEW_VERSION"
143160
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
144161
fi
145162
else

0 commit comments

Comments
 (0)