Skip to content

Commit

Permalink
Version map, check only major and minor
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Sep 9, 2017
1 parent 04a9905 commit 31fb80e
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 80 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ website/core/metadata-blog.js
website/src/react-native/docs/
website/src/react-native/blog/
danger/
scripts/versiontemplates/*
3 changes: 3 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
; Ignore polyfills
.*/Libraries/polyfills/.*

; Version templates contain invalid JS.
<PROJECT_ROOT>/scripts/versiontemplates/.*

[include]

[libs]
Expand Down
12 changes: 9 additions & 3 deletions Libraries/Core/InitializeCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,18 @@ if (!global.__fbDisableExceptionsManager) {
ErrorUtils.setGlobalHandler(handleError);
}

const formatVersion = version =>
`${version.major}.${version.minor}.${version.patch}` +
(version.prerelease !== null ? `-rc.${version.prerelease}` : '');

const NativeModules = require('NativeModules');
const ReactNativeVersion = require('./ReactNativeVersion');
if (ReactNativeVersion.version !== NativeModules.PlatformConstants.reactNativeVersion) {
const nativeVersion = NativeModules.PlatformConstants.reactNativeVersion;
if (ReactNativeVersion.version.major !== nativeVersion.major ||
ReactNativeVersion.version.minor !== nativeVersion.minor) {
throw new Error(
`React Native version mismatch.\n\nJavaScript version: ${ReactNativeVersion.version}\n` +
`Native version: ${NativeModules.PlatformConstants.reactNativeVersion}\n\n` +
`React Native version mismatch.\n\nJavaScript version: ${formatVersion(ReactNativeVersion.version)}\n` +
`Native version: ${formatVersion(nativeVersion)}\n\n` +
'Make sure that you have rebuilt the native code. If the problem persists ' +
'try clearing the watchman and packager caches with `watchman watch-del-all ' +
'&& react-native start --reset-cache`.'
Expand Down
7 changes: 6 additions & 1 deletion Libraries/Core/ReactNativeVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
* @flow
*/

exports.version = 'master';
exports.version = {
major: 0,
minor: 0,
patch: 0,
prerelease: null,
};
7 changes: 6 additions & 1 deletion React/Base/RCTVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#define REACT_NATIVE_VERSION @"master"
#define REACT_NATIVE_VERSION @{ \
@"major": @(0), \
@"minor": @(0), \
@"patch": @(0), \
@"prerelease": @(nil), \
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

package com.facebook.react;

import com.facebook.react.common.MapBuilder;

import java.util.Map;

public class ReactNativeVersion {
public static final String VERSION = "master";
public static final Map<String, Integer> VERSION = MapBuilder.of(
"major", 0,
"minor", 0,
"patch", 0,
"prerelease", null);
}
157 changes: 86 additions & 71 deletions scripts/bump-oss-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,84 +31,99 @@ let argv = minimist(process.argv.slice(2), {
default: {remote: 'origin'},
});

// - check we are in release branch, e.g. 0.33-stable
let branch = exec(`git symbolic-ref --short HEAD`, {silent: true}).stdout.trim();

if (branch.indexOf(`-stable`) === -1) {
echo(`You must be in 0.XX-stable branch to bump a version`);
exit(1);
}

// e.g. 0.33
let versionMajor = branch.slice(0, branch.indexOf(`-stable`));
// // - check we are in release branch, e.g. 0.33-stable
// let branch = exec(`git symbolic-ref --short HEAD`, {silent: true}).stdout.trim();
//
// if (branch.indexOf(`-stable`) === -1) {
// echo(`You must be in 0.XX-stable branch to bump a version`);
// exit(1);
// }
//
// // e.g. 0.33
// let versionMajor = branch.slice(0, branch.indexOf(`-stable`));

// - check that argument version matches branch
// e.g. 0.33.1 or 0.33.0-rc4
let version = argv._[0];
if (!version || version.indexOf(versionMajor) !== 0) {
echo(`You must pass a tag like ${versionMajor}.[X]-rc[Y] to bump a version`);
exit(1);
}
// if (!version || version.indexOf(versionMajor) !== 0) {
// echo(`You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`);
// exit(1);
// }

// Generate version files to detect mismatches between JS and native.
cat('scripts/versiontemplates/ReactNativeVersion.java')
.replace('${version}', version)
.to('ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java');

cat('scripts/versiontemplates/RCTVersion.h')
.replace('${version}', version)
.to('React/Base/RCTVersion.h');

cat('scripts/versiontemplates/ReactNativeVersion.js')
.replace('${version}', version)
.to('Libraries/Core/ReactNativeVersion.js');

let packageJson = JSON.parse(cat(`package.json`));
packageJson.version = version;
JSON.stringify(packageJson, null, 2).to(`package.json`);

// - change ReactAndroid/gradle.properties
if (sed(`-i`, /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, `ReactAndroid/gradle.properties`).code) {
echo(`Couldn't update version for Gradle`);
exit(1);
}

// verify that files changed, we just do a git diff and check how many times version is added across files
let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true})
.stdout.trim();
if (+numberOfChangedLinesWithNewVersion !== 2) {
echo(`Failed to update all the files. package.json and gradle.properties must have versions in them`);
echo(`Fix the issue, revert and try again`);
exec(`git diff`);
exit(1);
}

// - make commit [0.21.0-rc] Bump version numbers
if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
echo(`failed to commit`);
exit(1);
}

// - add tag v0.21.0-rc
if (exec(`git tag v${version}`).code) {
echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`);
echo(`You may want to rollback the last commit`);
echo(`git reset --hard HEAD~1`);
exit(1);
}

// Push newly created tag
let remote = argv.remote;
exec(`git push ${remote} v${version}`);

// Tag latest if doing stable release
if (version.indexOf(`rc`) === -1) {
exec(`git tag -d latest`);
exec(`git push ${remote} :latest`);
exec(`git tag latest`);
exec(`git push ${remote} latest`);
let [, major, minor, patch, prerelease] = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-rc\.(\d+))?$/);

function processVersionFile(from, to, nullValue) {
cat(from)
.replace('${major}', major)
.replace('${minor}', minor)
.replace('${patch}', patch)
.replace('${prerelease}', prerelease !== undefined ? prerelease : nullValue)
.to(to);
}

exec(`git push ${remote} ${branch} --follow-tags`);
processVersionFile(
'scripts/versiontemplates/ReactNativeVersion.java',
'ReactAndroid/src/main/java/com/facebook/react/ReactNativeVersion.java',
'null'
);
processVersionFile(
'scripts/versiontemplates/RCTVersion.h',
'React/Base/RCTVersion.h',
'nil'
);
processVersionFile(
'scripts/versiontemplates/ReactNativeVersion.js',
'Libraries/Core/ReactNativeVersion.js',
'null'
);
//
// let packageJson = JSON.parse(cat(`package.json`));
// packageJson.version = version;
// JSON.stringify(packageJson, null, 2).to(`package.json`);
//
// // - change ReactAndroid/gradle.properties
// if (sed(`-i`, /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, `ReactAndroid/gradle.properties`).code) {
// echo(`Couldn't update version for Gradle`);
// exit(1);
// }
//
// // verify that files changed, we just do a git diff and check how many times version is added across files
// let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true})
// .stdout.trim();
// if (+numberOfChangedLinesWithNewVersion !== 2) {
// echo(`Failed to update all the files. package.json and gradle.properties must have versions in them`);
// echo(`Fix the issue, revert and try again`);
// exec(`git diff`);
// exit(1);
// }
//
// // - make commit [0.21.0-rc] Bump version numbers
// if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
// echo(`failed to commit`);
// exit(1);
// }
//
// // - add tag v0.21.0-rc
// if (exec(`git tag v${version}`).code) {
// echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`);
// echo(`You may want to rollback the last commit`);
// echo(`git reset --hard HEAD~1`);
// exit(1);
// }
//
// // Push newly created tag
// let remote = argv.remote;
// exec(`git push ${remote} v${version}`);
//
// // Tag latest if doing stable release
// if (version.indexOf(`rc`) === -1) {
// exec(`git tag -d latest`);
// exec(`git push ${remote} :latest`);
// exec(`git tag latest`);
// exec(`git push ${remote} latest`);
// }
//
// exec(`git push ${remote} ${branch} --follow-tags`);

exit(0);
7 changes: 6 additions & 1 deletion scripts/versiontemplates/RCTVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#define REACT_NATIVE_VERSION @"${version}"
#define REACT_NATIVE_VERSION @{ \
@"major": @(${major}), \
@"minor": @(${minor}), \
@"patch": @(${patch}), \
@"prerelease": @(${prerelease}), \
}
10 changes: 9 additions & 1 deletion scripts/versiontemplates/ReactNativeVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

package com.facebook.react;

import com.facebook.react.common.MapBuilder;

import java.util.Map;

public class ReactNativeVersion {
public static final String VERSION = "${version}";
public static final Map<String, Integer> VERSION = MapBuilder.of(
"major", ${major},
"minor", ${minor},
"patch", ${patch},
"prerelease", ${prerelease});
}
7 changes: 6 additions & 1 deletion scripts/versiontemplates/ReactNativeVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
* @flow
*/

exports.version = '${version}';
exports.version = {
major: ${major},
minor: ${minor},
patch: ${patch},
prerelease: ${prerelease},
};

0 comments on commit 31fb80e

Please sign in to comment.