mirror of
https://github.com/FranzDiebold/github-env-vars-action.git
synced 2024-12-27 17:34:51 -05:00
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:
parent
dae1d3475c
commit
e59d29ab3b
3 changed files with 15 additions and 1 deletions
7
.github/workflows/demo.yml
vendored
7
.github/workflows/demo.yml
vendored
|
@ -28,6 +28,8 @@ jobs:
|
|||
echo "CI_BASE_REF=$CI_BASE_REF"
|
||||
echo "CI_SHA_SHORT=$CI_SHA_SHORT"
|
||||
echo "CI_SHA=$CI_SHA"
|
||||
echo "CI_PR_SHA_SHORT=$CI_PR_SHA_SHORT"
|
||||
echo "CI_PR_SHA=$CI_PR_SHA"
|
||||
echo "CI_PR_NUMBER=$CI_PR_NUMBER"
|
||||
echo "CI_PR_ID=$CI_PR_ID"
|
||||
echo "CI_PR_TITLE=$CI_PR_TITLE"
|
||||
|
@ -77,6 +79,8 @@ jobs:
|
|||
echo "CI_BASE_REF=$Env:CI_BASE_REF"
|
||||
echo "CI_SHA_SHORT=$Env:CI_SHA_SHORT"
|
||||
echo "CI_SHA=$Env:CI_SHA"
|
||||
echo "CI_PR_SHA_SHORT=$Env:CI_PR_SHA_SHORT"
|
||||
echo "CI_PR_SHA=$Env:CI_PR_SHA"
|
||||
echo "CI_PR_NUMBER=$Env:CI_PR_NUMBER"
|
||||
echo "CI_PR_ID=$Env:CI_PR_ID"
|
||||
echo "CI_PR_TITLE=$Env:CI_PR_TITLE"
|
||||
|
@ -122,10 +126,11 @@ jobs:
|
|||
echo "CI_REF=$CI_REF"
|
||||
echo "CI_HEAD_REF_SLUG=$CI_HEAD_REF_SLUG"
|
||||
echo "CI_HEAD_REF=$CI_HEAD_REF"
|
||||
echo "CI_BASE_REF_SLUG=$CI_BASE_REF_SLUG"
|
||||
echo "CI_BASE_REF=$CI_BASE_REF"
|
||||
echo "CI_SHA_SHORT=$CI_SHA_SHORT"
|
||||
echo "CI_SHA=$CI_SHA"
|
||||
echo "CI_PR_SHA_SHORT=$CI_PR_SHA_SHORT"
|
||||
echo "CI_PR_SHA=$CI_PR_SHA"
|
||||
echo "CI_PR_NUMBER=$CI_PR_NUMBER"
|
||||
echo "CI_PR_ID=$CI_PR_ID"
|
||||
echo "CI_PR_TITLE=$CI_PR_TITLE"
|
||||
|
|
|
@ -30,6 +30,8 @@ A [GitHub Action](https://github.com/features/actions) to expose useful environm
|
|||
| `CI_BASE_REF` | Only set for forked repositories / pull request. The branch of the base repository / the base branch name. Copy of `GITHUB_BASE_REF` - for reasons of completeness. | `main` |
|
||||
| `CI_SHA_SHORT` | The shortened commit SHA (8 characters) that triggered the workflow. | `ffac537e` |
|
||||
| `CI_SHA` | The commit SHA that triggered the workflow. Copy of `GITHUB_SHA` - for reasons of completeness. | `ffac537e6cbbf934b08745a378932722df287a53` |
|
||||
| `CI_PR_SHA_SHORT` | The shortened latest commit SHA in the pull request's base branch. Short version of `CI_PR_SHA`. Only set for pull requests. | `010b249` |
|
||||
| `CI_PR_SHA` | The latest commit SHA in the pull request's base branch. Long version of `CI_PR_SHA_SHORT`. Only set for pull requests. | `010b2491902d50e8623934f5bc43763ff5991642` |
|
||||
| `CI_PR_NUMBER` | The number of the pull request. Only set for pull requests. | `42` |
|
||||
| `CI_PR_ID` | Copy of `CI_PR_NUMBER` for completeness. | `42` |
|
||||
| `CI_PR_TITLE` | The title of the pull request. Only set for pull requests. | `Add feature xyz.` |
|
||||
|
|
7
index.js
7
index.js
|
@ -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}`);
|
||||
|
|
Loading…
Reference in a new issue