Skip to content

Commit 2c95b9a

Browse files
committed
do not commit package.json beta version
1 parent b7e3275 commit 2c95b9a

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

.github/scripts/before-beta-release.cjs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const path = require('node:path');
55

66
const PKG_JSON_PATH = path.join(__dirname, '..', '..', 'package.json');
77

8+
// Check if we're in calculate-only mode
9+
const CALCULATE_ONLY = process.argv.includes('--calculate-only');
10+
811
function execCommand(command, options = {}) {
912
try {
1013
return execSync(command, { encoding: 'utf8', ...options }).trim();
@@ -145,6 +148,12 @@ function updatePackageVersion(newVersion) {
145148
console.log(`Updated package.json to ${newVersion}`);
146149
}
147150

151+
function saveBetaVersionToFile(version) {
152+
// Save version to temporary file for workflow to read
153+
fs.writeFileSync('/tmp/beta_version.txt', version);
154+
console.log(`Saved beta version to /tmp/beta_version.txt: ${version}`);
155+
}
156+
148157
function main() {
149158
console.log('🚀 Starting beta version calculation...');
150159

@@ -157,11 +166,17 @@ function main() {
157166
// Calculate next beta version (will auto-increment if base version exists as stable)
158167
const nextBetaVersion = getNextBetaVersion(packageName, baseVersion);
159168

160-
// Update package.json with the beta version
161-
updatePackageVersion(nextBetaVersion);
162-
163-
console.log('✅ Beta version preparation completed!');
164-
console.log(`Package will be published as: ${nextBetaVersion}`);
169+
if (CALCULATE_ONLY) {
170+
// Only calculate and save to file, don't update package.json
171+
saveBetaVersionToFile(nextBetaVersion);
172+
console.log('✅ Beta version calculation completed (calculate-only mode)!');
173+
console.log(`Beta version calculated: ${nextBetaVersion}`);
174+
} else {
175+
// Update package.json with the beta version (legacy behavior)
176+
updatePackageVersion(nextBetaVersion);
177+
console.log('✅ Beta version preparation completed!');
178+
console.log(`Package will be published as: ${nextBetaVersion}`);
179+
}
165180
}
166181

167182
main();

.github/workflows/pre_release.yaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,31 @@ jobs:
102102
- name: Update package version to base version
103103
run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }}
104104

105-
- name: Calculate and set beta version
105+
- name: Calculate beta version (without updating package.json)
106106
id: beta_version
107107
run: |
108-
# Use the improved beta script
109-
node ./.github/scripts/before-beta-release.cjs
110-
# Output the version for later jobs
111-
BETA_VERSION=$(node -p "require('./package.json').version")
108+
# Use the improved beta script to calculate version only
109+
node ./.github/scripts/before-beta-release.cjs --calculate-only
110+
# The script will output the beta version without updating package.json
111+
BETA_VERSION=$(cat /tmp/beta_version.txt)
112112
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT
113-
echo "Beta version: $BETA_VERSION"
113+
echo "Beta version calculated: $BETA_VERSION"
114114
115-
- name: Update CHANGELOG.md
115+
- name: Update CHANGELOG.md only
116116
uses: DamianReeves/write-file-action@master
117117
with:
118118
path: CHANGELOG.md
119119
write-mode: overwrite
120120
contents: ${{ needs.release_metadata.outputs.changelog }}
121121

122-
- name: Commit changes
122+
- name: Commit changelog only
123123
id: commit
124124
uses: EndBug/add-and-commit@v9
125125
with:
126126
author_name: Apify Release Bot
127127
author_email: [email protected]
128-
message: "chore(release): Update to ${{ steps.beta_version.outputs.version }} [skip ci]"
128+
message: "chore(release): Update changelog for ${{ steps.beta_version.outputs.version }} [skip ci]"
129+
add: 'CHANGELOG.md'
129130
push: true
130131

131132
- name: Create and push beta tag
@@ -155,7 +156,13 @@ jobs:
155156
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
156157
npm ci
157158
158-
- name: Verify version consistency
159+
- name: Set beta version in package.json
160+
run: |
161+
BETA_VERSION="${{ needs.update_changelog_and_version.outputs.beta_version }}"
162+
echo "Setting package.json version to: $BETA_VERSION"
163+
npm version --no-git-tag-version --allow-same-version "$BETA_VERSION"
164+
165+
- name: Verify version is set correctly
159166
run: |
160167
PACKAGE_VERSION=$(node -p "require('./package.json').version")
161168
EXPECTED_VERSION="${{ needs.update_changelog_and_version.outputs.beta_version }}"

0 commit comments

Comments
 (0)