diff --git a/dist/index.js b/dist/index.js index 01d3178..6ec828a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -37923,13 +37923,18 @@ let BASE_SHA; process.stdout.write('\n'); process.stdout.write(`NOTE: You can instead make this a hard error by setting 'error-on-no-successful-workflow' on the action in your workflow.\n`); process.stdout.write('\n'); - const commitCountOutput = (0, child_process_1.spawnSync)('git', ['rev-list', '--count', `origin/${mainBranchName}`], { encoding: 'utf-8' }).stdout; - const commitCount = parseInt(stripNewLineEndings(commitCountOutput), 10); - const LAST_COMMIT_CMD = `origin/${mainBranchName}${commitCount > 1 ? '~1' : ''}`; + // Check if HEAD~1 exists, and if not, set BASE_SHA to undefined + const LAST_COMMIT_CMD = `origin/${mainBranchName}~1`; const baseRes = (0, child_process_1.spawnSync)('git', ['rev-parse', LAST_COMMIT_CMD], { encoding: 'utf-8', }); - BASE_SHA = baseRes.stdout; + if (baseRes.status !== 0 || !baseRes.stdout) { + process.stdout.write(`HEAD~1 does not exist. BASE_SHA is set to undefined.\n`); + BASE_SHA = undefined; + } + else { + BASE_SHA = baseRes.stdout; + } } core.setOutput('noPreviousBuild', 'true'); } diff --git a/find-successful-workflow.ts b/find-successful-workflow.ts index c2c1324..b9b4e66 100644 --- a/find-successful-workflow.ts +++ b/find-successful-workflow.ts @@ -94,23 +94,21 @@ let BASE_SHA: string; ); process.stdout.write('\n'); - const commitCountOutput = spawnSync( - 'git', - ['rev-list', '--count', `origin/${mainBranchName}`], - { encoding: 'utf-8' }, - ).stdout; - const commitCount = parseInt( - stripNewLineEndings(commitCountOutput), - 10, - ); + // Check if HEAD~1 exists, and if not, set BASE_SHA to undefined + const LAST_COMMIT_CMD = `origin/${mainBranchName}~1`; - const LAST_COMMIT_CMD = `origin/${mainBranchName}${ - commitCount > 1 ? '~1' : '' - }`; const baseRes = spawnSync('git', ['rev-parse', LAST_COMMIT_CMD], { encoding: 'utf-8', }); - BASE_SHA = baseRes.stdout; + + if (baseRes.status !== 0 || !baseRes.stdout) { + process.stdout.write( + `HEAD~1 does not exist. BASE_SHA is set to undefined.\n`, + ); + BASE_SHA = undefined; + } else { + BASE_SHA = baseRes.stdout; + } } core.setOutput('noPreviousBuild', 'true'); }