From fb1285e8ca425379f76f8e19c5cabef148b59b8c Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Tue, 17 Jan 2023 12:58:17 -0800 Subject: [PATCH] Check that the `upstream` remote is correctly set before proceeding in release script --- scripts/release.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/release.js b/scripts/release.js index a08014063b9..4379c308b80 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -41,7 +41,8 @@ if (args.dry_run) { process.exit(1); } - // ensure git is on the main branch + // ensure git is on the correct remote and branch + await ensureUpstreamRemote(); await ensureMainBranch(); // run linting and unit tests @@ -136,6 +137,30 @@ function parseArguments() { }; } +async function ensureUpstreamRemote() { + try { + const upstreamRemote = execSync('git config --get remote.upstream.url') + .toString() + .trim(); + if ( + !( + upstreamRemote.endsWith(':elastic/eui.git') || // : for SSH, / for HTTPS + upstreamRemote.endsWith('/elastic/eui.git') + ) + ) { + console.error( + 'Your `upstream` remote must be pointed to https://github.com/elastic/eui.\nPlease run `git remote -v` to ensure you have an `upstream` remote pointed at the correct repo.\n' + ); + process.exit(1); + } + } catch { + console.error( + 'No `upstream` remote found.\nPlease run: `git remote add upstream git@github.com:elastic/eui.git`\n' + ); + process.exit(1); + } +} + async function ensureMainBranch() { // ignore main check in CI since it's checking out the HEAD commit instead if (process.env.CI === 'true') {