It would be helpful for creating cache keys if we could get the exact commit hash of a ref that might float like 'master'.
I'm not opposed to adding, but curious more info about the scenario? Including the SHA in the cache key seems wrong since it will change every run.
I'm thinking of scenarios like npm. Restoring from cache will cover most packages, even when some packages change between runs. The branch seems like a better approach (e.g master vs legacy).
Workaround today is the set-output command. Something like echo "::set-output name=sha::$(git rev-parse HEAD)"
Sure, here鈥檚 the scenario:
We need to build the protobuf repo as part of CI for a protoc plugin. To run the conformance test. We want to follow master on the protobuf repo because they add new tests all the time. The CI workflow is happening inside a docker image provided by the Swift project which has an old version of git so the checkout action is using the http api instead of git, so we can鈥檛 run git rev-parse (I tried this first). If I use the branch name in the cache key then we potentially miss updates to the protobuf conformance test until the cache expires.
@toffaletti thanks that helps!
Here is a workaround to determine the SHA, and then pass the same SHA into the checkout step:
steps:
- id: get-sha
run: |
echo ::set-output name=sha::$( curl -u "u:${{github.token}}" https://api.github.com/repos/some-owner/some-repo/git/ref/heads/master | jq .object.sha | tr -d '"' )
- uses: actions/checkout@v2
with:
ref: ${{ steps.get-sha.outputs.sha }}
I second the idea of this feature.
In my use case we checkout many repos to build them and do some integration testing. Having the sha in the output will simplify caching some intermediate build steps.
In my use case i checkout another branch and I want the commit sha for surefire-report
I would like to use the SHA to tag docker images. If I am reading this correctly, I could do that with this feature.
This would also be valuable to us on being able to grab the SHA of the container build on merge (HEAD^1)
can one run a shell script and output the last tag + the number of commits since the last tag, to have a notion of "newer" + the sha to have a clear reference to the source code without tag, sample output would be 1.7.94-57-g2167aa34 or 1.7.94.r57.g2167aa34:
麓麓麓
git describe --long --tags | sed 's/([^-]-g)/1/'
git describe --long --tags | sed 's/([^-]-g)/r1/;s/-/./g'
麓麓
Most helpful comment
I would like to use the SHA to tag docker images. If I am reading this correctly, I could do that with this feature.