Skip to content

Commit c730181

Browse files
committed
chore: set up proper publishing pipeline
1 parent 2b33fbb commit c730181

File tree

8 files changed

+1097
-1204
lines changed

8 files changed

+1097
-1204
lines changed

.ado/jobs/npm-publish-dry-run.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ jobs:
1313
submodules: recursive # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
1414
persistCredentials: true # set to 'true' to leave the OAuth token in the Git config after the initial fetch
1515

16-
- template: /.ado/templates/apple-steps-publish.yml@self
17-
parameters:
18-
build_type: 'dry-run'
16+
- template: /.ado/templates/npm-publish.yml@self

.ado/scripts/prepublish-check.mjs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// @ts-check
2+
import { spawnSync } from "node:child_process";
3+
import * as fs from "node:fs";
4+
import * as util from "node:util";
5+
6+
/** @typedef {typeof import("../../nx.json")} NxConfig */
7+
8+
/**
9+
* @returns {NxConfig}
10+
*/
11+
function loadNxConfig(configFile = "nx.json") {
12+
const nx = fs.readFileSync(configFile, { encoding: "utf-8" });
13+
return JSON.parse(nx);
14+
}
15+
16+
/**
17+
* @returns {string}
18+
*/
19+
function getCurrentBranch() {
20+
const { stdout } = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
21+
return stdout.toString().trim();
22+
}
23+
24+
/**
25+
* @param {string} branch
26+
*/
27+
function isStableBranch(branch) {
28+
return /^\d+\.\d+-stable$/.test(branch);
29+
}
30+
31+
/**
32+
* @param {NxConfig["release"]} config
33+
* @param {string} tag
34+
* @param {string} [prerelease]
35+
* @returns {asserts config is NxConfig["release"]}
36+
*/
37+
function enablePublishing(config, tag, prerelease) {
38+
/** @type {string[]} */
39+
const errors = [];
40+
41+
const { currentVersionResolverMetadata, preid } = config.version.generatorOptions;
42+
if (preid !== prerelease) {
43+
errors.push(`'release.version.generatorOptions.preid' must be set to '${prerelease || ""}'`);
44+
}
45+
46+
if (currentVersionResolverMetadata.tag !== tag) {
47+
errors.push(`'release.version.generatorOptions.currentVersionResolverMetadata.tag' must be set to '${tag}'`);
48+
}
49+
50+
if (errors.length > 0) {
51+
for (const e of errors) {
52+
console.error("❌", e);
53+
}
54+
throw new Error("Nx Release is not correctly configured for the current branch");
55+
}
56+
57+
console.log(`##vso[task.setvariable variable=publish_react_native_macos]1`);
58+
}
59+
60+
function main({ "release-candidate": releaseCandidate }) {
61+
const branch = getCurrentBranch();
62+
if (!branch) {
63+
throw new Error("Could not get current branch");
64+
}
65+
66+
const { defaultBase, release } = loadNxConfig();
67+
if (branch === defaultBase) {
68+
enablePublishing(release, "nightly", "nightly");
69+
} else if (isStableBranch(branch)) {
70+
enablePublishing(release, "v" + branch, releaseCandidate ? "rc" : undefined);
71+
}
72+
}
73+
74+
const { values } = util.parseArgs({
75+
args: process.argv.slice(2),
76+
options: {
77+
"release-candidate": {
78+
type: "boolean",
79+
default: true
80+
}
81+
},
82+
strict: true,
83+
allowNegative: true,
84+
});
85+
86+
main(values);

.ado/templates/npm-publish.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
parameters:
2+
build_type: ''
3+
4+
steps:
5+
- script: |
6+
yarn install
7+
displayName: Install npm dependencies
8+
9+
- script: |
10+
# If this is a stable branch, add `--no-release-candidate` when going stable
11+
node .ado/scripts/prepublish-check.mjs
12+
displayName: Verify release config
13+
14+
- script: |
15+
yarn nx release --dry-run
16+
displayName: Version and publish packages (dry run)
17+
condition: ne(variables['publish_react_native_macos'], '1')
18+
19+
- script: |
20+
#yarn nx release --yes
21+
yarn nx release --dry-run
22+
displayName: Version and publish packages
23+
condition: eq(variables['publish_react_native_macos'], '1')

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,8 @@ vendor/
174174
.ado/Brewfile.lock.json
175175
.ado/verdaccio/htpasswd
176176
.ado/verdaccio/storage/.verdaccio-db.json
177+
178+
# Nx
179+
.nx/cache
180+
.nx/workspace-data
177181
# macOS]

nx.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"$schema": "./node_modules/nx/schemas/nx-schema.json",
3+
"defaultBase": "main",
4+
"targetDefaults": {
5+
"build": {
6+
"dependsOn": [
7+
"^build"
8+
]
9+
}
10+
},
11+
"release": {
12+
"projects": [
13+
"packages/react-native",
14+
"packages/react-native-macos-init",
15+
"packages/virtualized-lists"
16+
],
17+
"projectsRelationship": "independent",
18+
"versionPlans": true,
19+
"version": {
20+
"generatorOptions": {
21+
"currentVersionResolver": "registry",
22+
"currentVersionResolverMetadata": {
23+
"tag": "nightly"
24+
},
25+
"preid": "nightly",
26+
"skipLockFileUpdate": true
27+
}
28+
}
29+
}
30+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@babel/preset-flow": "^7.24.7",
5151
"@definitelytyped/dtslint": "^0.0.127",
5252
"@jest/create-cache-key-function": "^29.6.3",
53+
"@nx/js": "~20.0.0",
5354
"@pkgjs/parseargs": "^0.11.0",
5455
"@react-native/metro-babel-transformer": "0.76.0-main",
5556
"@react-native/metro-config": "0.76.0-main",
@@ -94,6 +95,7 @@
9495
"mkdirp": "^0.5.1",
9596
"node-fetch": "^2.2.0",
9697
"nullthrows": "^1.1.1",
98+
"nx": "~20.0.0",
9799
"prettier": "2.8.8",
98100
"prettier-plugin-hermes-parser": "0.23.1",
99101
"react": "19.0.0-rc-fb9a90fa48-20240614",

packages/react-native/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
},
113113
"dependencies": {
114114
"@jest/create-cache-key-function": "^29.6.3",
115-
"@react-native-mac/virtualized-lists": "0.76.0-main",
115+
"@react-native-mac/virtualized-lists": "workspace:*",
116116
"@react-native/assets-registry": "0.76.0-main",
117117
"@react-native/codegen": "0.76.0-main",
118118
"@react-native/community-cli-plugin": "0.76.0-main",

0 commit comments

Comments
 (0)