Skip to content

Commit f238f15

Browse files
kelsetfacebook-github-bot
authored andcommitted
fix(scripts): add logic for version scripts to account for local E2E test versioning (#35846)
Summary: While working on 0.71 branch I encountered a problem in testing locally. Basically, I was getting hit by a silent error caused by recent work #35296 that didn't account for the shape of E2E local script for the release, `0.71.0-20230116-1649`. This scripts fixes both aspects: the error now gets thrown "better" and the logic accounts for the E2E shape. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [FIXED] - add logic for version scripts to account for local E2E test versioning Pull Request resolved: #35846 Test Plan: Tested via the other PR: #35847 Reviewed By: cortinico Differential Revision: D42543200 Pulled By: cipolleschi fbshipit-source-id: 727eb887fcbd183ec56d8a9b7e98241eaacb1d98
1 parent 58a6cf8 commit f238f15

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

scripts/set-rn-version.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ let argv = yargs
3838

3939
const buildType = argv.buildType;
4040
const version = argv.toVersion;
41-
validateBuildType(buildType);
41+
42+
try {
43+
validateBuildType(buildType);
44+
} catch (e) {
45+
throw e;
46+
}
4247

4348
let major,
4449
minor,
@@ -47,8 +52,7 @@ let major,
4752
try {
4853
({major, minor, patch, prerelease} = parseVersion(version, buildType));
4954
} catch (e) {
50-
echo(e.message);
51-
exit(1);
55+
throw e;
5256
}
5357

5458
const tmpVersioningFolder = fs.mkdtempSync(

scripts/test-e2e-local.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
const {exec, exit, pushd, popd, pwd, cd, cp} = require('shelljs');
2020
const yargs = require('yargs');
2121
const fs = require('fs');
22-
const {getBranchName} = require('./scm-utils');
2322

2423
const {
2524
launchAndroidEmulator,
@@ -147,11 +146,9 @@ if (argv.target === 'RNTester') {
147146
// we need to add the unique timestamp to avoid npm/yarn to use some local caches
148147
const baseVersion = require('../package.json').version;
149148

150-
const branchName = getBranchName();
151-
const buildType =
152-
branchName.endsWith('-stable') && baseVersion !== '1000.0.0'
153-
? 'release'
154-
: 'dry-run';
149+
// in local testing, 1000.0.0 mean we are on main, every other case means we are
150+
// working on a release version
151+
const buildType = baseVersion !== '1000.0.0' ? 'release' : 'dry-run';
155152

156153
const dateIdentifier = new Date()
157154
.toISOString()
@@ -162,10 +159,17 @@ if (argv.target === 'RNTester') {
162159
const releaseVersion = `${baseVersion}-${dateIdentifier}`;
163160

164161
// this is needed to generate the Android artifacts correctly
165-
exec(
162+
const exitCode = exec(
166163
`node scripts/set-rn-version.js --to-version ${releaseVersion} --build-type ${buildType}`,
167164
).code;
168165

166+
if (exitCode !== 0) {
167+
console.error(
168+
`Failed to set the RN version. Version ${releaseVersion} is not valid for ${buildType}`,
169+
);
170+
process.exit(exitCode);
171+
}
172+
169173
// Generate native files for Android
170174
generateAndroidArtifacts(releaseVersion);
171175

scripts/version-utils.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
1818
* Some examples of valid versions are:
1919
* - stable: 0.68.1
2020
* - stable prerelease: 0.70.0-rc.0
21-
* - nightly: 0.0.0-20221116-2018-0bc4547fc | 0.0.0
21+
* - e2e-test: X.Y.Z-20221116-2018
22+
* - nightly: 0.0.0-20221116-2018-0bc4547fc
2223
* - dryrun: 1000.0.0
2324
*
2425
* Parameters:
@@ -38,7 +39,11 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
3839
*
3940
*/
4041
function parseVersion(versionStr, buildType) {
41-
validateBuildType(buildType);
42+
try {
43+
validateBuildType(buildType);
44+
} catch (e) {
45+
throw e;
46+
}
4247

4348
const match = extractMatchIfValid(versionStr);
4449
const [, version, major, minor, patch, prerelease] = match;
@@ -51,7 +56,11 @@ function parseVersion(versionStr, buildType) {
5156
prerelease,
5257
};
5358

54-
validateVersion(versionObject, buildType);
59+
try {
60+
validateVersion(versionObject, buildType);
61+
} catch (e) {
62+
throw e;
63+
}
5564

5665
return versionObject;
5766
}
@@ -125,7 +134,8 @@ function isStablePrerelease(version) {
125134
version.patch === '0' &&
126135
version.prerelease != null &&
127136
(version.prerelease.startsWith('rc.') ||
128-
version.prerelease.startsWith('rc-'))
137+
version.prerelease.startsWith('rc-') ||
138+
version.prerelease.match(/^(\d{8})-(\d{4})$/))
129139
);
130140
}
131141

0 commit comments

Comments
 (0)