Skip to content

Commit

Permalink
feat: Automate releases to GitHub (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Feb 13, 2024
1 parent 2a6b19c commit bf3facc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 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;
24 changes: 24 additions & 0 deletions scripts/oot-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
const forEachPackage = require('./monorepo/for-each-package');
const {applyPackageVersions, publishPackage} = require('./npm-utils');
const updateTemplatePackage = require('./update-template-package');
const {failIfTagExists} = require('./release-utils');
const {execSync} = require('child_process');
const fs = require('fs');
const path = require('path');
const {cat, echo, exit} = require('shelljs');
const yargs = require('yargs');
const newGithubReleaseUrl = require('./new-github-release-url');

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

Expand Down Expand Up @@ -130,6 +132,15 @@ function releaseOOT(
return;
}

const gitTag = `v${newVersion}`;
failIfTagExists(tag, '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 @@ -153,6 +164,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 bf3facc

Please sign in to comment.