diff --git a/src/index.js b/src/index.js index 2f0f849..1092f51 100644 --- a/src/index.js +++ b/src/index.js @@ -46,7 +46,6 @@ async function run(octokit, context, token) { stripHash: stripHash(getInput('strip-hash')) }); - const buildScript = getInput('build-script') || 'build'; const cwd = process.cwd(); let { packageManager, installScript } = await getPackageManagerAndInstallScript(cwd); @@ -54,14 +53,16 @@ async function run(octokit, context, token) { installScript = getInput('install-script'); } + const buildScript = getInput('build-script') || `${packageManager} run build`; + startGroup(`[current] Install Dependencies`); console.log(`Installing using ${installScript}`); await exec(installScript); endGroup(); startGroup(`[current] Build using ${packageManager}`); - console.log(`Building using ${packageManager} run ${buildScript}`); - await exec(`${packageManager} run ${buildScript}`); + console.log(`Building using ${buildScript}`); + await exec(buildScript); endGroup(); // In case the build step alters a JSON-file, .... @@ -69,9 +70,19 @@ async function run(octokit, context, token) { const newSizes = await plugin.readFromDisk(cwd); + function throwIfBaseRefMissing() { + if (!baseRef) { + if (context.eventName == 'push') { + throw new Error('missing context.payload.base.ref for push event'); + } else { + throw new Error('missing context.payload.pull_request.base.ref for pull_request event'); + } + } + } + startGroup(`[base] Checkout target branch`); try { - if (!baseRef) throw Error('missing context.payload.pull_request.base.ref'); + throwIfBaseRefMissing(); await exec(`git fetch -n origin ${baseRef}:${baseRef}`); console.log('successfully fetched base.ref'); } catch (e) { @@ -98,7 +109,7 @@ async function run(octokit, context, token) { console.log('checking out and building base commit'); try { - if (!baseRef) throw Error('missing context.payload.base.ref'); + throwIfBaseRefMissing(); await exec(`git reset --hard ${baseRef}`); } catch (e) { await exec(`git reset --hard ${baseSha}`);