Fall back to GITHUB_SHA env var if git is not available #84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There have been problems regarding a new dependency on being able to run git commands. In some environment git is not present, or a
.gitdirectory is not created unless git is a high-enough version. In other cases people want to analyze without a full checkout, for example analysing container images.This PR means we still try to use git to get the current commit, because we need to do this in the case of PR integration. However if that fails for any reason then we almost silently give up and just return the commit SHA from the environment.
I argue this will be correct in almost all situations, and even if it was incorrect the fallout from alerts appearing on the wrong commit is not too bad in the case of pull requests and likely understandable to the user.
I've tested this with a self-hosted runner that did not have a high enough version of git, and it failed on the
mainbranch but succeeded with this branch.Merge / deployment checklist