Skip to content

Commit 1d38a9d

Browse files
committed
feat: Automate releases to GitHub (#83)
fix: adjust oot-release script for stable releases (#85)
1 parent 63a353d commit 1d38a9d

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

scripts/new-github-release-url.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function newGithubReleaseUrl(options = {}) {
2+
let repoUrl;
3+
if (options.repoUrl) {
4+
repoUrl = options.repoUrl;
5+
} else if (options.user && options.repo) {
6+
repoUrl = `https://github.com/${options.user}/${options.repo}`;
7+
} else {
8+
throw new Error('You need to specify either the `repoUrl` option or both the `user` and `repo` options');
9+
}
10+
11+
const url = new URL(`${repoUrl}/releases/new`);
12+
13+
const types = [
14+
'tag',
15+
'target',
16+
'title',
17+
'body',
18+
'isPrerelease',
19+
];
20+
21+
for (let type of types) {
22+
const value = options[type];
23+
if (value === undefined) {
24+
continue;
25+
}
26+
27+
if (type === 'isPrerelease') {
28+
type = 'prerelease';
29+
}
30+
31+
url.searchParams.set(type, value);
32+
}
33+
34+
return url.toString();
35+
}
36+
37+
module.exports = newGithubReleaseUrl;

scripts/oot-release.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
'use strict';
88

99
const forEachPackage = require('./monorepo/for-each-package');
10+
const newGithubReleaseUrl = require('./new-github-release-url');
1011
const {applyPackageVersions, publishPackage} = require('./npm-utils');
12+
const {failIfTagExists} = require('./release-utils');
1113
const updateTemplatePackage = require('./update-template-package');
14+
const {execSync} = require('child_process');
1215
const fs = require('fs');
1316
const path = require('path');
1417
const {cat, echo, exit} = require('shelljs');
1518
const yargs = require('yargs');
1619

20+
const REPO_ROOT = path.resolve(__dirname, '../');
21+
1722
/**
1823
* This script updates core packages to the version of React Native that we are basing on,
1924
* updates internal visionOS packages and releases them.
@@ -89,6 +94,7 @@ function releaseOOT(
8994
oneTimePassword,
9095
tag = 'latest',
9196
) {
97+
const isNightly = tag === 'nightly';
9298
const allPackages = getPackages();
9399
const corePackages = Object.keys(allPackages).filter(packageName =>
94100
packageName.startsWith('@react-native/'),
@@ -102,25 +108,55 @@ function releaseOOT(
102108
{},
103109
);
104110

111+
const visionOSPackagesVersions = visionOSPackages.reduce(
112+
(acc, pkg) => ({...acc, [pkg]: newVersion}),
113+
{},
114+
);
115+
105116
// Update `packges/react-native` package.json and all visionOS packages
106-
visionOSPackages.forEach(pkg => {
107-
echo(`Setting ${pkg} version to ${newVersion} `);
108-
setPackage(allPackages[pkg], newVersion, corePackagesVersions);
109-
});
117+
if (isNightly) {
118+
visionOSPackages.forEach(pkg => {
119+
echo(`Setting ${pkg} version to ${newVersion} `);
120+
setPackage(allPackages[pkg], newVersion, corePackagesVersions);
121+
});
122+
} else {
123+
visionOSPackages.forEach(pkg => {
124+
echo(`Setting ${pkg} version to ${newVersion} `);
125+
setPackage(allPackages[pkg], newVersion, visionOSPackagesVersions);
126+
});
127+
}
110128

111129
// Update template package.json
112130
updateTemplatePackage({
113131
'react-native': reactNativeVersion,
114-
...corePackagesVersions,
115-
...visionOSPackages.reduce((acc, pkg) => ({...acc, [pkg]: newVersion}), {}),
132+
...visionOSPackagesVersions,
116133
});
134+
135+
if (isNightly) {
136+
updateTemplatePackage(corePackagesVersions);
137+
}
138+
117139
echo(`Updating template and it's dependencies to ${reactNativeVersion}`);
118140

141+
echo('Building packages...\n');
142+
execSync('node ./scripts/build/build.js', {
143+
cwd: REPO_ROOT,
144+
stdio: [process.stdin, process.stdout, process.stderr],
145+
});
146+
119147
// Release visionOS packages only if OTP is passed
120148
if (!oneTimePassword) {
121149
return;
122150
}
123151

152+
const gitTag = `v${newVersion}-visionos`;
153+
failIfTagExists(gitTag, 'release');
154+
// Create git tag
155+
execSync(`git tag -a ${gitTag} -m "Release ${newVersion}"`, {
156+
cwd: REPO_ROOT,
157+
stdio: [process.stdin, process.stdout, process.stderr],
158+
});
159+
124160
const results = visionOSPackages
125161
.map(npmPackage => {
126162
return path.join(__dirname, '..', allPackages[npmPackage]);
@@ -144,6 +180,19 @@ function releaseOOT(
144180
', ',
145181
)} to npm with version: ${newVersion}`,
146182
);
183+
184+
const releaseURL = newGithubReleaseUrl({
185+
tag: gitTag,
186+
title: `Release ${newVersion}`,
187+
repo: 'react-native-visionos',
188+
user: 'callstack',
189+
});
190+
191+
echo('\n\n');
192+
echo('-------------------------------------------\n');
193+
echo(`Create a new release here: ${releaseURL}\n`);
194+
echo('-------------------------------------------');
195+
147196
return exit(0);
148197
}
149198
}

0 commit comments

Comments
 (0)