Skip to content

Commit 43d5236

Browse files
committed
Cherry-pick "Refactor Publish pipeline (take 2)"
1 parent 6603783 commit 43d5236

File tree

6 files changed

+84
-101
lines changed

6 files changed

+84
-101
lines changed

.ado/apple-pr.yml

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -238,37 +238,7 @@ jobs:
238238
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
239239
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
240240

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.TargetBranchName'], '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
241+
- template: templates/apple-job-publish.yml
242+
parameters:
243+
build_type: 'dry-run'
269244

270-
- task: CmdLine@2
271-
displayName: Print tarball output
272-
inputs:
273-
script: |
274-
npm publish --dry-run

.ado/publish.yml

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ variables:
2121
value: production,externalfacing
2222

2323
jobs:
24-
- job: NPMPublishRNM
25-
displayName: NPM Publish React Native macOS
24+
- job: RNGithubNpmJSPublish
25+
displayName: NPM Publish React-native-macos
2626
pool:
2727
vmImage: $(VmImageApple)
2828
variables:
@@ -38,74 +38,35 @@ jobs:
3838
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
3939
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
4040

41-
- template: templates/apple-tools-setup.yml
42-
43-
- template: templates/apple-install-dependencies.yml
44-
45-
- template: templates/apple-release-setup.yml
46-
47-
- task: CmdLine@2
48-
displayName: Set next version if release branch
49-
inputs:
50-
script: |
51-
VERSION=$(node .ado/get-next-semver-version.js)
52-
echo "Set version to: $VERSION"
53-
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main'))
54-
55-
- task: CmdLine@2
56-
displayName: Set latest tag if latest stable branch
57-
inputs:
58-
script: |
59-
LATEST=true
60-
echo "Set latest to: $LATEST"
61-
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main'))
62-
63-
- task: CmdLine@2
64-
displayName: Set release type to 'nightly'
65-
inputs:
66-
script: |
67-
RELEASE_TYPE=nightly
68-
echo "Set release type to: $RELEASE_TYPE"
69-
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
70-
71-
- task: CmdLine@2
72-
displayName: Set release type to 'release'
73-
inputs:
74-
script: |
75-
RELEASE_TYPE=release
76-
echo "Set release type to: $RELEASE_TYPE"
77-
condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/main'))
78-
79-
- task: CmdLine@2
80-
displayName: Prepare package for release
81-
inputs:
82-
script: |
83-
if [[ -z "$VERSION" ]]; then
84-
VERSION=$(grep '"version"' package.json | cut -d '"' -f 4 | head -1)
85-
echo "Using the version from the package.json: $VERSION"
86-
fi
87-
node ./scripts/prepare-package-for-release.js -v "$VERSION" -l $LATEST
88-
condition: and(succeeded(), ne(variables['Build.TargetBranch'], 'refs/heads/main'))
41+
- ${{ if eq(variables['isMain'], true) }}:
42+
- template: templates/apple-job-publish.yml
43+
parameters:
44+
build_type: nightly
45+
- ${{ elseif eq(variables['isReleaseBranch'], true) }}:
46+
- template: templates/apple-job-publish.yml
47+
parameters:
48+
build_type: release
49+
- ${{ else }}:
50+
- task: CmdLine@2
51+
displayName: Unknown branch, skipping publish
52+
inputs:
53+
script: |
54+
echo "Skipping publish for branch $(Build.SourceBranchName)"
55+
exit 1
8956
9057
- task: AzureArtifacts.manifest-generator-task.manifest-generator-task.ManifestGeneratorTask@0
9158
displayName: 📒 Generate Manifest
9259
inputs:
9360
BuildDropPath: $(System.DefaultWorkingDirectory)
9461

95-
- task: CmdLine@2
96-
displayName: NPM Publish
97-
inputs:
98-
script: |
99-
node ./scripts/publish-npm.js --$RELEASE_TYPE
100-
10162
- task: PublishPipelineArtifact@1
10263
displayName: 📒 Publish Manifest
10364
inputs:
10465
artifactName: SBom-RNGithubNpmJSPublish-$(System.JobAttempt)
10566
targetPath: $(System.DefaultWorkingDirectory)/_manifest
10667

10768
- job: RNMacOSInitNpmJSPublish
108-
displayName: react-native-macos-init Publish to npmjs.org
69+
displayName: NPM Publish react-native-macos-init
10970
pool: cxeiss-ubuntu-20-04-large
11071
timeoutInMinutes: 90 # how long to run the job before automatically cancelling
11172
cancelTimeoutInMinutes: 5 # how much time to give 'run always even if cancelled tasks' before killing them
@@ -120,8 +81,6 @@ jobs:
12081
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
12182
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
12283

123-
- template: templates/apple-tools-setup.yml
124-
12584
- template: templates/apple-install-dependencies.yml
12685

12786
- template: templates/apple-release-setup.yml
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
parameters:
2+
build_type: ''
3+
4+
steps:
5+
- template: apple-tools-setup.yml
6+
7+
- template: apple-install-dependencies.yml
8+
9+
# Only set up our release environment if we're not doing a dry run
10+
- ${{ if ne( parameters['build_type'], 'dry-run') }}:
11+
- template: apple-release-setup.yml
12+
13+
- task: CmdLine@2
14+
displayName: Set build type to ${{parameters.build_type}}
15+
inputs:
16+
script: |
17+
BUILD_TYPE=${{parameters.build_type}}
18+
echo "Set build type: $BUILD_TYPE"
19+
20+
# Extra steps needed for *-stable releases
21+
- ${{ if eq( parameters['build_type'], 'release') }}:
22+
- task: CmdLine@2
23+
displayName: Set next version
24+
inputs:
25+
script: |
26+
VERSION=$(node .ado/get-next-semver-version.js)
27+
echo "Set version: $VERSION"
28+
29+
- task: CmdLine@2
30+
displayName: Set build type to ${{parameters.build_type}}
31+
inputs:
32+
script: |
33+
BUILD_TYPE=release
34+
echo "Set build type: $BUILD_TYPE"
35+
36+
- task: CmdLine@2
37+
displayName: Set latest tag
38+
inputs:
39+
script: |
40+
LATEST=true
41+
echo "Set latest to: $LATEST"
42+
43+
- task: CmdLine@2
44+
displayName: Prepare and tag package for release
45+
inputs:
46+
script: |
47+
if [[ -z "$VERSION" ]]; then
48+
VERSION=$(grep '"version"' package.json | cut -d '"' -f 4 | head -1)
49+
echo "Using the version from the package.json: $VERSION"
50+
fi
51+
node ./scripts/prepare-package-for-release.js -v "$VERSION" -l $LATEST
52+
53+
- task: CmdLine@2
54+
displayName: NPM Publish
55+
inputs:
56+
script: |
57+
node ./scripts/publish-npm.js --${{ parameters.build_type }}

.ado/variables/vars.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ 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'
5+
isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
6+
isReleaseBranch: $[endsWith(variables['Build.SourceBranchName'], '-stable')]

scripts/prepare-package-for-release.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const {echo, exec, exit} = require('shelljs');
2222
const yargs = require('yargs');
2323
const {isReleaseBranch, parseVersion} = require('./version-utils');
2424
const {failIfTagExists} = require('./release-utils');
25+
const {getBranchName} = require('./scm-utils'); // [macOS]
2526

2627
const argv = yargs
2728
.option('r', {
@@ -44,11 +45,7 @@ const argv = yargs
4445
default: false,
4546
}).argv;
4647

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]
48+
const branch = getBranchName(); // [macOS] Don't rely on CircleCI environment variables.
5249
const remote = argv.remote;
5350
const releaseVersion = argv.toVersion;
5451
const isLatest = argv.latest;

scripts/publish-npm.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ const os = require('os');
5252
const path = require('path');
5353
const yargs = require('yargs');
5454

55-
// [macOS] Use git to get the tag name, rather than relying on CircleCI environment variables.
56-
const buildTag = exec('git tag --points-at HEAD');
55+
const buildTag = exec('git tag --points-at HEAD'); // [macOS] Don't rely on CircleCI environment variables.
5756
const otp = process.env.NPM_CONFIG_OTP;
5857
const tmpPublishingFolder = fs.mkdtempSync(
5958
path.join(os.tmpdir(), 'rn-publish-'),
@@ -105,7 +104,7 @@ const rawVersion =
105104
nightlyBuild
106105
? '0.0.0'
107106
: // For pre-release and stable releases, we use the git tag of the version we're releasing (set in set-rn-version)
108-
buildTag.substring(0, str.indexOf('-microsft')); // [macOS] Strip off the "-microsoft" suffix from the tag name.
107+
buildTag.substring(0, buildTag.indexOf('-microsft')); // [macOS] Strip off the "-microsoft" suffix from the tag name.
109108

110109
let version,
111110
major,

0 commit comments

Comments
 (0)