Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make checked out ref available to other steps #281

Closed
jwgmeligmeyling opened this issue Jun 16, 2020 · 8 comments · Fixed by #1180
Closed

Make checked out ref available to other steps #281

jwgmeligmeyling opened this issue Jun 16, 2020 · 8 comments · Fixed by #1180

Comments

@jwgmeligmeyling
Copy link

jwgmeligmeyling commented Jun 16, 2020

Pull requests events by default check out the merge commit ref. Alternatively, the pull request head can be checkout using:

- uses: actions/checkout@v2
  with:
    ref: ${{ github.event.pull_request.head.sha }}

However, in successive actions it is not possible to detect whether the action uses another ref. github.context.sha still references the merge commit. See for example the discussion on: jwgmeligmeyling/pmd-github-action#2

It would be nice if actions/checkout@v2 somehow made the checkout ref available as output or exported variable.

Or am I overlooking an existing approach to obtain the checked out commit SHA?

@ericsciple
Copy link
Contributor

ericsciple commented Jun 18, 2020

git log -1 '--format=format:%H' works to get the current commit SHA

Although it assumes the sources were fetched using git (mainline). However when git 2.18 or higher isn't in the PATH, the tarball is downloaded instead.

@jwgmeligmeyling
Copy link
Author

Exactly, so that's why that would only be a partial solution 😄 I think it also won't work in for example some Docker based tasks (unless the containers ship git). And obviously you need to execute the command in the work dir.

@Simran-B
Copy link

Looks like the short SHA is readily available:

const archiveVersion = archiveFileNames[0] // The top-level folder name includes the short SHA

But getting the full one would require an API call I suppose?

@lucacome
Copy link
Contributor

+1 for having the commit as an output of the action.

@lucacome
Copy link
Contributor

I've opened #1180 to output ref and commit. Let me know what you think 🙏

@hvithval
Copy link

it would be nice to be able to access the actual commit-SHA/ SHORT_SHA and not the one that is created from the checkout source code step.
image

@jwgmeligmeyling
Copy link
Author

it would be nice to be able to access the actual commit-SHA/ SHORT_SHA and not the one that is created from the checkout source code step.

That is already available as github.event.pull_request.head.sha.

@joshmgross
Copy link
Member

This is now available in https://github.com/actions/checkout/releases/tag/v4.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants