Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions scripts/set-rn-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ let argv = yargs

const buildType = argv.buildType;
const version = argv.toVersion;
validateBuildType(buildType);

try {
validateBuildType(buildType);
} catch (e) {
throw e;
}
Comment on lines +42 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectively, @cortinico noticed that this should be the default behavior... @kelset do you think we can remove this try-catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

during my testing, adding this seemed to have an effect so that exec() would catch the error correctly. I can remove but honestly, what's the problem with having it?


let major,
minor,
Expand All @@ -47,8 +52,7 @@ let major,
try {
({major, minor, patch, prerelease} = parseVersion(version, buildType));
} catch (e) {
echo(e.message);
exit(1);
throw e;
}

const tmpVersioningFolder = fs.mkdtempSync(
Expand Down
18 changes: 11 additions & 7 deletions scripts/test-e2e-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
const {exec, exit, pushd, popd, pwd, cd, cp} = require('shelljs');
const yargs = require('yargs');
const fs = require('fs');
const {getBranchName} = require('./scm-utils');

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

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

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

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

if (exitCode !== 0) {
console.error(
`Failed to set the RN version. Version ${releaseVersion} is not valid for ${buildType}`,
);
process.exit(exitCode);
}

// Generate native files for Android
generateAndroidArtifacts(releaseVersion);

Expand Down
18 changes: 14 additions & 4 deletions scripts/version-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
* Some examples of valid versions are:
* - stable: 0.68.1
* - stable prerelease: 0.70.0-rc.0
* - nightly: 0.0.0-20221116-2018-0bc4547fc | 0.0.0
* - e2e-test: X.Y.Z-20221116-2018
* - nightly: 0.0.0-20221116-2018-0bc4547fc
* - dryrun: 1000.0.0
*
* Parameters:
Expand All @@ -38,7 +39,11 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
*
*/
function parseVersion(versionStr, buildType) {
validateBuildType(buildType);
try {
validateBuildType(buildType);
} catch (e) {
throw e;
}

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

validateVersion(versionObject, buildType);
try {
validateVersion(versionObject, buildType);
} catch (e) {
throw e;
}

return versionObject;
}
Expand Down Expand Up @@ -125,7 +134,8 @@ function isStablePrerelease(version) {
version.patch === '0' &&
version.prerelease != null &&
(version.prerelease.startsWith('rc.') ||
version.prerelease.startsWith('rc-'))
version.prerelease.startsWith('rc-') ||
version.prerelease.match(/^(\d{8})-(\d{4})$/))
);
}

Expand Down