Skip to content

Commit 2f2cf22

Browse files
committed
Add NPM Publish Dry Run Job + Refactor publish.yml
1 parent 049360b commit 2f2cf22

16 files changed

+149
-148
lines changed

.ado/Brewfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
brew "watchman"
22
brew "xcbeautify"
3+
# macOS 12 doesn't have `realpath` but macOS 13 does. Remove this line when Azure Pipelines supports macOS 13 images.
4+
brew "coreutils"

.ado/apple-pr.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,52 @@ jobs:
223223
- template: templates/react-native-macos-init.yml
224224
parameters:
225225
configuration: $(configuration)
226+
227+
- job: NPMPublishDryRun
228+
displayName: NPM Publish Dry Run
229+
pool:
230+
vmImage: $(VmImageApple)
231+
timeoutInMinutes: 60 # how long to run the job before automatically cancelling
232+
cancelTimeoutInMinutes: 5 # how much time to give 'run always even if cancelled tasks' before killing them
233+
steps:
234+
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
235+
clean: true # whether to fetch clean each time
236+
# fetchDepth: 2 # the depth of commits to ask Git to fetch
237+
lfs: false # whether to download Git-LFS files
238+
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
239+
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
240+
241+
- template: templates/apple-tools-setup.yml
242+
243+
- template: templates/apple-install-dependencies.yml
244+
245+
- task: CmdLine@2
246+
displayName: Set next version if release branch
247+
inputs:
248+
script: |
249+
VERSION=$(node .ado/get-next-semver-version.js)
250+
echo "Set Version to: $VERSION"
251+
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'main'))
252+
253+
254+
- task: CmdLine@2
255+
displayName: Prepare package for release
256+
inputs:
257+
script: |
258+
if [[ -z "$VERSION" ]]; then
259+
VERSION=$(grep '"version"' package.json | cut -d '"' -f 4 | head -1)
260+
echo "Using the version from the package.json: $VERSION"
261+
fi
262+
node ./scripts/prepare-package-for-release.js -v "$VERSION" -l false --dry-run true
263+
264+
- task: CmdLine@2
265+
displayName: NPM Publish Dry Run
266+
inputs:
267+
script: |
268+
node ./scripts/publish-npm.js --dry-run
269+
270+
- task: CmdLine@2
271+
displayName: Print tarball output
272+
inputs:
273+
script: |
274+
npm publish --dry-run

.ado/bumpFileVersions.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

.ado/versionUtils.js renamed to .ado/get-next-semver-version.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function gatherVersionInfo() {
1919
return {pkgJson, releaseVersion, branchVersionSuffix};
2020
}
2121

22-
function updateVersionsInFiles(patchVersionPrefix) {
22+
function getNextVersion(patchVersionPrefix) {
2323

2424
let {pkgJson, releaseVersion, branchVersionSuffix} = gatherVersionInfo();
2525

@@ -42,34 +42,9 @@ function updateVersionsInFiles(patchVersionPrefix) {
4242
}
4343

4444
pkgJson.version = releaseVersion;
45-
console.log(`Bumping files to version ${releaseVersion}`);
46-
execSync(`node ./scripts/set-rn-version.js --rnmpublish --to-version ${releaseVersion}`, {stdio: 'inherit', env: process.env});
4745

4846
return {releaseVersion, branchVersionSuffix};
4947
}
5048

51-
const workspaceJsonPath = path.resolve(require('os').tmpdir(), 'rnpkg.json');
52-
53-
function removeWorkspaceConfig() {
54-
let {pkgJson} = gatherVersionInfo();
55-
fs.writeFileSync(workspaceJsonPath, JSON.stringify(pkgJson, null, 2));
56-
delete pkgJson.private;
57-
delete pkgJson.workspaces;
58-
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
59-
console.log(`Removing workspace config from package.json to prepare to publish.`);
60-
}
61-
62-
function restoreWorkspaceConfig() {
63-
let pkgJson = JSON.parse(fs.readFileSync(workspaceJsonPath, "utf8"));
64-
fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
65-
console.log(`Restoring workspace config from package.json`);
66-
}
67-
68-
module.exports = {
69-
gatherVersionInfo,
70-
publishBranchName,
71-
pkgJsonPath,
72-
removeWorkspaceConfig,
73-
restoreWorkspaceConfig,
74-
updateVersionsInFiles
75-
}
49+
const nextVersion = getNextVersion().releaseVersion;
50+
console.log(nextVersion);

.ado/get-release-type.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @ts-check
2+
const fs = require("fs");
3+
const path = require("path");
4+
const semver = require('semver');
5+
const {execSync} = require('child_process');
6+
7+
const pkgJsonPath = path.resolve(__dirname, "../package.json");
8+
let publishBranchName = '';
9+
try {
10+
publishBranchName = process.env.BUILD_SOURCEBRANCH.match(/refs\/heads\/(.*)/)[1];
11+
} catch (error) {}
12+
13+
if (publishBranchName === 'main') {
14+
console.log('nightly');
15+
} else if (publishBranchName.endsWith('-stable')) {
16+
console.log('release');
17+
} else {
18+
process.exit(1);
19+
}

.ado/gitTagRelease.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

.ado/publish.yml

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ trigger:
1010
include:
1111
- main
1212
- 0.68-stable
13+
- 0.71-stable
1314
paths:
1415
exclude:
1516
- package.json
@@ -43,79 +44,62 @@ jobs:
4344
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
4445
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
4546

46-
- script: exit 1
47-
displayName: Validate variables
48-
condition: eq(variables.latestStableBranch, '')
49-
50-
- bash: echo "##vso[task.setvariable variable=npmDistTag]latest"
51-
displayName: Set dist-tag to latest
52-
condition: eq(variables['Build.SourceBranchName'], variables.latestStableBranch)
53-
54-
- bash: echo "##vso[task.setvariable variable=npmDistTag]canary"
55-
displayName: Set dist-tag to canary
56-
condition: eq(variables['Build.SourceBranchName'], 'main')
47+
- template: templates/apple-tools-setup.yml
5748

58-
- bash: echo "##vso[task.setvariable variable=npmDistTag]v${{variables['Build.SourceBranchName']}}"
59-
displayName: Set dist-tag to v0.x-stable
60-
condition: and(ne(variables['Build.SourceBranchName'], 'main'), ne(variables['Build.SourceBranchName'], variables.latestStableBranch))
49+
- template: templates/apple-install-dependencies.yml
6150

62-
- template: templates/apple-tools-setup.yml
51+
- template: templates/apple-release-setup.yml
6352

6453
- task: CmdLine@2
65-
displayName: yarn install
54+
displayName: Set next version if release branch
6655
inputs:
67-
script: yarn install --frozen-lockfile
56+
script: |
57+
VERSION=$(node .ado/get-next-semver-version.js)
58+
echo "Set version to: $VERSION"
59+
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'main'))
6860

6961
- task: CmdLine@2
70-
displayName: Bump stable package version
62+
displayName: Set release type
7163
inputs:
72-
script: node .ado/bumpFileVersions.js
73-
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'main'))
74-
64+
script: |
65+
RELEASE_TYPE=$(node .ado/get-next-release-type.js)
66+
echo "Set release type to: $RELEASE_TYPE"
67+
7568
- task: CmdLine@2
76-
displayName: Set canary package version
69+
displayName: Set latest tag if latest stable branch
7770
inputs:
78-
script: node scripts/set-rn-version.js --nightly --autogenerateVersionNumber
79-
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'main'))
71+
script: |
72+
LATEST=true
73+
echo "Set latest to: $LATEST"
74+
condition: eq(variables['Build.SourceBranchName'], $(latest_stable_branch))
8075

81-
# Publish will fail if package.json is marked as private
8276
- task: CmdLine@2
83-
displayName: Remove workspace config from package.json
77+
displayName: Prepare package for release
8478
inputs:
85-
script: node .ado/removeWorkspaceConfig.js
79+
script: |
80+
if [[ -z "$VERSION" ]]; then
81+
VERSION=$(grep '"version"' package.json | cut -d '"' -f 4 | head -1)
82+
echo "Using the version from the package.json: $VERSION"
83+
fi
84+
node ./scripts/prepare-package-for-release.js -v "$VERSION" -l $LATEST
8685
8786
- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
8887
displayName: 📒 Generate Manifest
8988
inputs:
9089
BuildDropPath: $(System.DefaultWorkingDirectory)
9190

91+
- task: CmdLine@2
92+
displayName: NPM Publish
93+
inputs:
94+
script: |
95+
node ./scripts/publish-npm.js --$RELEASE_TYPE
96+
9297
- task: PublishPipelineArtifact@1
9398
displayName: 📒 Publish Manifest
9499
inputs:
95100
artifactName: SBom-RNGithubNpmJSPublish-$(System.JobAttempt)
96101
targetPath: $(System.DefaultWorkingDirectory)/_manifest
97102

98-
- script: npm publish --tag $(npmDistTag) --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$(npmAuthToken)
99-
displayName: Publish react-native-macos to npmjs.org
100-
101-
# Put the private flag back so that the removal does not get committed by the tag release step
102-
- task: CmdLine@2
103-
displayName: Restore package.json workspace config
104-
inputs:
105-
script: node .ado/restoreWorkspaceConfig.js
106-
107-
- task: CmdLine@2
108-
displayName: 'Tag published release'
109-
inputs:
110-
script: node .ado/gitTagRelease.js
111-
env:
112-
BUILD_STAGINGDIRECTORY: $(Build.StagingDirectory)
113-
BUILD_SOURCEBRANCH: $(Build.SourceBranch)
114-
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
115-
githubApiToken: $(githubAuthToken)
116-
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'main'))
117-
118-
119103
- job: RNMacOSInitNpmJSPublish
120104
displayName: react-native-macos-init Publish to npmjs.org
121105
pool: cxeiss-ubuntu-20-04-large
@@ -132,17 +116,14 @@ jobs:
132116
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
133117
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
134118

135-
- template: templates/configure-git.yml
119+
- template: templates/apple-tools-setup.yml
136120

137-
- task: CmdLine@2
138-
displayName: yarn install
139-
inputs:
140-
script: |
141-
cd packages/react-native-macos-init
142-
yarn install --frozen-lockfile
121+
- template: templates/apple-install-dependencies.yml
122+
123+
- template: templates/apple-release-setup.yml
143124

144125
- task: CmdLine@2
145-
displayName: yarn build
126+
displayName: Build react-native-macos-init
146127
inputs:
147128
script: |
148129
cd packages/react-native-macos-init

.ado/removeWorkspaceConfig.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

.ado/restoreWorkspaceConfig.js

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
steps:
2+
- task: CmdLine@2
3+
displayName: yarn install
4+
inputs:
5+
script: yarn install --frozen-lockfile
6+
7+
- task: CmdLine@2
8+
displayName: bundle install
9+
inputs:
10+
script: |
11+
cd packages/rn-tester
12+
bundle install
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
21
steps:
3-
42
- task: CmdLine@2
53
displayName: Configure git
64
inputs:
75
script: |
86
git config --global user.email "[email protected]"
97
git config --global user.name "React-Native Bot"
8+
9+
- task: CmdLine@2
10+
displayName: Set NPM Auth Token
11+
inputs:
12+
script: |
13+
echo "//registry.npmjs.org/:_authToken=${npmAuthToken}" > ~/.npmrc

.ado/templates/apple-tools-setup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
steps:
22
- task: NodeTool@0
33
inputs:
4-
versionSource: 'fromFile' # 'spec' | 'fromFile'. Required. Source of version. Default: spec.
4+
versionSource: 'fromFile'
55
versionFilePath: '.node-version'
66

77
- task: UseRubyVersion@0

.ado/variables/vars.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ variables:
22
VmImageApple: internal-macos12
33
slice_name: 'Xcode_14.2'
44
xcode_version: '/Applications/Xcode_14.2.app'
5+
latest_stable_branch: '0.71-stable'

scripts/prepare-package-for-release.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ const argv = yargs
4444
default: false,
4545
}).argv;
4646

47-
const branch = process.env.CIRCLE_BRANCH;
47+
// [macOS Use git to get the branch name, rather than relying on CircleCI env vars.
48+
const branch = exec('git rev-parse --abbrev-ref HEAD', {
49+
silent: true,
50+
}).stdout.trim();
51+
// // macOS]
4852
const remote = argv.remote;
4953
const releaseVersion = argv.toVersion;
5054
const isLatest = argv.latest;
@@ -102,7 +106,8 @@ if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) {
102106
}
103107

104108
// Add tag v0.21.0-rc.1
105-
if (exec(`git tag -a v${version} -m "v${version}"`).code) {
109+
// [macOS] Add "-microsoft" suffix to tag to distinguish from React Native Core.
110+
if (exec(`git tag -a v${version}-microsoft -m "v${version}-microsoft"`).code) {
106111
echo(
107112
`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`,
108113
);

0 commit comments

Comments
 (0)