Skip to content

Commit

Permalink
feat: BASE to undefined if HEAD~1 does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Aug 28, 2024
1 parent 5ba8bac commit ddc3f66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
13 changes: 9 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
24 changes: 11 additions & 13 deletions find-successful-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit ddc3f66

Please sign in to comment.