Skip to content

Commit

Permalink
[0.64] Fix publish builds by removing workspace from package.json bef…
Browse files Browse the repository at this point in the history
…ore publish (#866)

* Some more changes for bringing up RN64 in devmain Android (#861)

* Build & Packaging changes for bringing up RN64 in devmain

* Fixing gradle clean

* Disable gradle clean in PR builds

* Fix for submit button disappearing bug in comments (#862)

* Add the missing android folder to files in package.json

* Fix for submit button disappear bug in comments

Co-authored-by: Mayuresh Gharpure <Mayuresh.Gharpure@microsoft.com>

* fix: ensure scripts always have Unix newlines (#860)

* Fix for publishing from stable branches

* remove workspace info before publishing too

* Update rntester lock file when bumping package version

* Apply #875

* Allow newer cocoapod version

Co-authored-by: Anandraj <anandrag@microsoft.com>
Co-authored-by: Mayuresh Gharpure <gharpuremayuresh@gmail.com>
Co-authored-by: Mayuresh Gharpure <Mayuresh.Gharpure@microsoft.com>
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
  • Loading branch information
5 people authored Oct 28, 2021
1 parent 0e09744 commit 1dc7d83
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 229 deletions.
2 changes: 1 addition & 1 deletion .ado/npmOfficePack.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function doPublish(fakeMode) {
if (!onlyTagSource) {
// -------- Generating Android Artifacts with JavaDoc
const depsEnvPrefix = "REACT_NATIVE_BOOST_PATH=" + path.join(process.env.BUILD_SOURCESDIRECTORY, "build_deps");
const gradleCommand = path.join(process.env.BUILD_SOURCESDIRECTORY, "gradlew") + " installArchives";
const gradleCommand = path.join(process.env.BUILD_SOURCESDIRECTORY, "gradlew") + " installArchives -Pparam=\"excludeLibs\"";
exec( depsEnvPrefix + " " + gradleCommand );

// undo uncommenting javadoc setting
Expand Down
18 changes: 18 additions & 0 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@ jobs:
script: node scripts/bump-oss-version.js --nightly
condition: eq(variables['Build.SourceBranchName'], 'master')

# Publish will fail if package.json is marked as private
- task: CmdLine@2
displayName: Remove workspace config from package.json
inputs:
script: node .ado/removeWorkspaceConfig.js

- script: npm publish --tag $(npmDistTag) --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$(npmAuthToken)
displayName: Publish react-native-macos to npmjs.org

# Put the private flag back so that the removal does not get committed by the tag release step
- task: CmdLine@2
displayName: Restore package.json workspace config
inputs:
script: node .ado/restoreWorkspaceConfig.js

- task: CmdLine@2
displayName: 'Tag published release'
inputs:
Expand Down Expand Up @@ -137,6 +149,12 @@ jobs:
inputs:
script: node .ado/bumpOfficeFileVersions.js

# Publish will fail if package.json is marked as private
- task: CmdLine@2
displayName: Remove workspace config from package.json
inputs:
script: node .ado/removeWorkspaceConfig.js

- task: CmdLine@2
displayName: gradlew installArchives
inputs:
Expand Down
3 changes: 3 additions & 0 deletions .ado/removeWorkspaceConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-check
const {removeWorkspaceConfig} = require('./versionUtils');
removeWorkspaceConfig();
3 changes: 3 additions & 0 deletions .ado/restoreWorkspaceConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-check
const {restoreWorkspaceConfig} = require('./versionUtils');
restoreWorkspaceConfig();
25 changes: 23 additions & 2 deletions .ado/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const fs = require("fs");
const path = require("path");
const semver = require('semver');
const {execSync} = require('child_process');

const pkgJsonPath = path.resolve(__dirname, "../package.json");
let publishBranchName = '';
Expand Down Expand Up @@ -41,15 +42,35 @@ function updateVersionsInFiles(patchVersionPrefix) {
}

pkgJson.version = releaseVersion;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Updating package.json to version ${releaseVersion}`);
console.log(`Bumping files to version ${releaseVersion}`);
execSync(`node ./scripts/bump-oss-version.js --rnmpublish ${releaseVersion}`, {stdio: 'inherit'});

return {releaseVersion, branchVersionSuffix};
}


const workspaceJsonPath = path.resolve(require('os').tmpdir(), 'rnpkg.json');

function removeWorkspaceConfig() {
let {pkgJson} = gatherVersionInfo();
fs.writeFileSync(workspaceJsonPath, JSON.stringify(pkgJson, null, 2));
delete pkgJson.private;
delete pkgJson.workspaces;
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Removing workspace config from package.json to prepare to publish.`);
}

function restoreWorkspaceConfig() {
let pkgJson = JSON.parse(fs.readFileSync(workspaceJsonPath, "utf8"));
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
console.log(`Restoring workspace config from package.json`);
}

module.exports = {
gatherVersionInfo,
publishBranchName,
pkgJsonPath,
removeWorkspaceConfig,
restoreWorkspaceConfig,
updateVersionsInFiles
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Ensure scripts always have Unix newlines, even on Windows.
*.command text eol=lf
*.sh text eol=lf
# Windows files should use crlf line endings
# https://help.github.com/articles/dealing-with-line-endings/
*.bat text eol=crlf
Loading

0 comments on commit 1dc7d83

Please sign in to comment.