Skip to content

Commit

Permalink
feat: Automate releases to GitHub (#83)
Browse files Browse the repository at this point in the history
fix: adjust oot-release script for stable releases (#85)
  • Loading branch information
okwasniewski committed Aug 23, 2024
1 parent ff91511 commit 84ca829
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 6 deletions.
37 changes: 37 additions & 0 deletions scripts/new-github-release-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function newGithubReleaseUrl(options = {}) {
let repoUrl;
if (options.repoUrl) {
repoUrl = options.repoUrl;
} else if (options.user && options.repo) {
repoUrl = `https://github.com/${options.user}/${options.repo}`;
} else {
throw new Error('You need to specify either the `repoUrl` option or both the `user` and `repo` options');
}

const url = new URL(`${repoUrl}/releases/new`);

const types = [
'tag',
'target',
'title',
'body',
'isPrerelease',
];

for (let type of types) {
const value = options[type];
if (value === undefined) {
continue;
}

if (type === 'isPrerelease') {
type = 'prerelease';
}

url.searchParams.set(type, value);
}

return url.toString();
}

module.exports = newGithubReleaseUrl;
61 changes: 55 additions & 6 deletions scripts/oot-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
'use strict';

const forEachPackage = require('./monorepo/for-each-package');
const newGithubReleaseUrl = require('./new-github-release-url');
const {applyPackageVersions, publishPackage} = require('./npm-utils');
const {failIfTagExists} = require('./release-utils');
const updateTemplatePackage = require('./update-template-package');
const {execSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const {cat, echo, exit} = require('shelljs');
const yargs = require('yargs');

const REPO_ROOT = path.resolve(__dirname, '../');

/**
* This script updates core packages to the version of React Native that we are basing on,
* updates internal visionOS packages and releases them.
Expand Down Expand Up @@ -89,6 +94,7 @@ function releaseOOT(
oneTimePassword,
tag = 'latest',
) {
const isNightly = tag === 'nightly';
const allPackages = getPackages();
const corePackages = Object.keys(allPackages).filter(packageName =>
packageName.startsWith('@react-native/'),
Expand All @@ -102,25 +108,55 @@ function releaseOOT(
{},
);

const visionOSPackagesVersions = visionOSPackages.reduce(
(acc, pkg) => ({...acc, [pkg]: newVersion}),
{},
);

// Update `packges/react-native` package.json and all visionOS packages
visionOSPackages.forEach(pkg => {
echo(`Setting ${pkg} version to ${newVersion} `);
setPackage(allPackages[pkg], newVersion, corePackagesVersions);
});
if (isNightly) {
visionOSPackages.forEach(pkg => {
echo(`Setting ${pkg} version to ${newVersion} `);
setPackage(allPackages[pkg], newVersion, corePackagesVersions);
});
} else {
visionOSPackages.forEach(pkg => {
echo(`Setting ${pkg} version to ${newVersion} `);
setPackage(allPackages[pkg], newVersion, visionOSPackagesVersions);
});
}

// Update template package.json
updateTemplatePackage({
'react-native': reactNativeVersion,
...corePackagesVersions,
...visionOSPackages.reduce((acc, pkg) => ({...acc, [pkg]: newVersion}), {}),
...visionOSPackagesVersions,
});

if (isNightly) {
updateTemplatePackage(corePackagesVersions);
}

echo(`Updating template and it's dependencies to ${reactNativeVersion}`);

echo('Building packages...\n');
execSync('node ./scripts/build/build.js', {
cwd: REPO_ROOT,
stdio: [process.stdin, process.stdout, process.stderr],
});

// Release visionOS packages only if OTP is passed
if (!oneTimePassword) {
return;
}

const gitTag = `v${newVersion}-visionos`;
failIfTagExists(gitTag, 'release');
// Create git tag
execSync(`git tag -a ${gitTag} -m "Release ${newVersion}"`, {
cwd: REPO_ROOT,
stdio: [process.stdin, process.stdout, process.stderr],
});

const results = visionOSPackages
.map(npmPackage => {
return path.join(__dirname, '..', allPackages[npmPackage]);
Expand All @@ -144,6 +180,19 @@ function releaseOOT(
', ',
)} to npm with version: ${newVersion}`,
);

const releaseURL = newGithubReleaseUrl({
tag: gitTag,
title: `Release ${newVersion}`,
repo: 'react-native-visionos',
user: 'callstack',
});

echo('\n\n');
echo('-------------------------------------------\n');
echo(`Create a new release here: ${releaseURL}\n`);
echo('-------------------------------------------');

return exit(0);
}
}
Expand Down

0 comments on commit 84ca829

Please sign in to comment.