forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: set up proper publishing pipeline
- Loading branch information
Showing
8 changed files
with
1,097 additions
and
1,202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// @ts-check | ||
import { spawnSync } from "node:child_process"; | ||
import * as fs from "node:fs"; | ||
import * as util from "node:util"; | ||
|
||
/** @typedef {typeof import("../../nx.json")} NxConfig */ | ||
|
||
/** | ||
* @returns {NxConfig} | ||
*/ | ||
function loadNxConfig(configFile = "nx.json") { | ||
const nx = fs.readFileSync(configFile, { encoding: "utf-8" }); | ||
return JSON.parse(nx); | ||
} | ||
|
||
/** | ||
* @returns {string} | ||
*/ | ||
function getCurrentBranch() { | ||
const { stdout } = spawnSync("git", ["rev-parse", "--abbrev-ref", "HEAD"]); | ||
return stdout.toString().trim(); | ||
} | ||
|
||
/** | ||
* @param {string} branch | ||
*/ | ||
function isStableBranch(branch) { | ||
return /^\d+\.\d+-stable$/.test(branch); | ||
} | ||
|
||
/** | ||
* @param {NxConfig["release"]} config | ||
* @param {string} tag | ||
* @param {string} [prerelease] | ||
* @returns {asserts config is NxConfig["release"]} | ||
*/ | ||
function enablePublishing(config, tag, prerelease) { | ||
/** @type {string[]} */ | ||
const errors = []; | ||
|
||
const { currentVersionResolverMetadata, preid } = config.version.generatorOptions; | ||
if (preid !== prerelease) { | ||
errors.push(`'release.version.generatorOptions.preid' must be set to '${prerelease || ""}'`); | ||
} | ||
|
||
if (currentVersionResolverMetadata.tag !== tag) { | ||
errors.push(`'release.version.generatorOptions.currentVersionResolverMetadata.tag' must be set to '${tag}'`); | ||
} | ||
|
||
if (errors.length > 0) { | ||
for (const e of errors) { | ||
console.error("❌", e); | ||
} | ||
throw new Error("Nx Release is not correctly configured for the current branch"); | ||
} | ||
|
||
console.log(`##vso[task.setvariable variable=publish_react_native_macos]1`); | ||
} | ||
|
||
function main({ "release-candidate": releaseCandidate }) { | ||
const branch = getCurrentBranch(); | ||
if (!branch) { | ||
throw new Error("Could not get current branch"); | ||
} | ||
|
||
const { defaultBase, release } = loadNxConfig(); | ||
if (branch === defaultBase) { | ||
enablePublishing(release, "nightly", "nightly"); | ||
} else if (isStableBranch(branch)) { | ||
enablePublishing(release, "v" + branch, releaseCandidate ? "rc" : undefined); | ||
} | ||
} | ||
|
||
const { values } = util.parseArgs({ | ||
args: process.argv.slice(2), | ||
options: { | ||
"release-candidate": { | ||
type: "boolean", | ||
default: true | ||
} | ||
}, | ||
strict: true, | ||
allowNegative: true, | ||
}); | ||
|
||
main(values); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
parameters: | ||
build_type: '' | ||
|
||
steps: | ||
- script: | | ||
yarn install | ||
displayName: Install npm dependencies | ||
- script: | | ||
# If this is a stable branch, add `--no-release-candidate` when going stable | ||
node .ado/scripts/prepublish-check.mjs | ||
displayName: Verify release config | ||
- script: | | ||
yarn nx release --dry-run | ||
displayName: Version and publish packages (dry run) | ||
condition: ne(variables['publish_react_native_macos'], '1') | ||
- script: | | ||
#yarn nx release --yes | ||
yarn nx release --dry-run | ||
displayName: Version and publish packages | ||
condition: eq(variables['publish_react_native_macos'], '1') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "./node_modules/nx/schemas/nx-schema.json", | ||
"defaultBase": "main", | ||
"targetDefaults": { | ||
"build": { | ||
"dependsOn": [ | ||
"^build" | ||
] | ||
} | ||
}, | ||
"release": { | ||
"projects": [ | ||
"packages/react-native", | ||
"packages/react-native-macos-init", | ||
"packages/virtualized-lists" | ||
], | ||
"projectsRelationship": "independent", | ||
"versionPlans": true, | ||
"version": { | ||
"generatorOptions": { | ||
"currentVersionResolver": "registry", | ||
"currentVersionResolverMetadata": { | ||
"tag": "nightly" | ||
}, | ||
"preid": "nightly", | ||
"skipLockFileUpdate": true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.