From 0fe4ee90d3608c831a37f8ecb296142ef5344439 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 19 Jan 2021 17:33:57 +0100 Subject: [PATCH] scripts/check-if-release: fix diff and tweak to handle new and removed packages --- scripts/check-if-release.js | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/scripts/check-if-release.js b/scripts/check-if-release.js index 57a0ad792c..dcfc862e48 100755 --- a/scripts/check-if-release.js +++ b/scripts/check-if-release.js @@ -58,25 +58,44 @@ async function main() { 'diff', '--name-only', parentRef, - 'packages/*/package.json', - 'plugins/*/package.json', + "'packages/*/package.json'", + "'plugins/*/package.json'", ); const packageList = diff.split(/^(.*)$/gm).filter(s => s.trim()); const packageVersions = await Promise.all( packageList.map(async path => { - const { name, version: newVersion } = JSON.parse( - await fs.readFile(path, 'utf8'), - ); - const { version: oldVersion } = JSON.parse( - await runPlain('git', 'show', `${parentRef}:${path}`), - ); + let name; + let newVersion; + let oldVersion; + + try { + const data = JSON.parse( + await runPlain('git', 'show', `${parentRef}:${path}`), + ); + name = data.name; + oldVersion = data.version; + } catch { + oldVersion = ''; + } + + try { + const data = JSON.parse(await fs.readFile(path, 'utf8')); + name = data.name; + newVersion = data.version; + } catch (error) { + if (error.code === 'ENOENT') { + newVersion = ''; + } + } + return { name, oldVersion, newVersion }; }), ); const newVersions = packageVersions.filter( - ({ oldVersion, newVersion }) => oldVersion !== newVersion, + ({ oldVersion, newVersion }) => + oldVersion !== newVersion && newVersion !== '', ); if (newVersions.length === 0) { @@ -89,7 +108,7 @@ async function main() { const maxLength = Math.max(...newVersions.map(_ => _.name.length)); for (const { name, oldVersion, newVersion } of newVersions) { console.log( - ` ${name.padEnd(maxLength, ' ')} ${oldVersion} -> ${newVersion}`, + ` ${name.padEnd(maxLength, ' ')} ${oldVersion} to ${newVersion}`, ); } console.log(`::set-output name=needs_release::true`);