Expose an actual SHA for pull requests as CI_PR_SHA(_SHORT).

Default CI_SHA/GITHUB_SHA is the sha of _expect-to-be_ merge/squash/etc commit of the pull requests,
and it can be very confusing. If you mark you artifacts with it, its very hard to trace back what was the actual commit.

CI_PR_SHA is the way I solved it for my use cases and I can see im not the first one with this problem.

Fixes #30
This commit is contained in:
Vladimir Starkov 2022-07-12 10:21:56 +02:00
parent dae1d3475c
commit e59d29ab3b
3 changed files with 15 additions and 1 deletions

View file

@ -186,6 +186,13 @@ try {
const pullRequest = github.context.payload &&
github.context.payload.pull_request;
if (pullRequest) {
const prSha = github.event.pull_request.head.sha;
core.exportVariable('CI_PR_SHA_SHORT', getShaShort(prSha));
core.info(`Set CI_PR_SHA_SHORT=${process.env.CI_PR_SHA_SHORT}`);
core.exportVariable('CI_PR_SHA', prSha);
core.info(`Set CI_PR_SHA=${process.env.CI_PR_SHA}`);
const prNumber = pullRequest.number;
core.exportVariable('CI_PR_NUMBER', prNumber);
core.info(`Set CI_PR_NUMBER=${process.env.CI_PR_NUMBER}`);