docs icon indicating copy to clipboard operation
docs copied to clipboard

The github.ref does not contain fully-formed ref of the branch

Open trivikr opened this issue 2 years ago • 12 comments

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries

What part(s) of the article would you like to see updated?

The workflow run on my GitHub repo indicates that github.ref contains destination branch when PR is closed, and not refs/pull/<pr_number>/merge

Note that:

  • Workflow file says BRANCH=${{ github.ref }}
  • Workflow run prints BRANCH=main

Either the documentation needs to be updated to use the following solution instead:

BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

Or the backend code needs to be fixed to provide branch name in github.ref

Additional information

No response

trivikr avatar Dec 16 '22 01:12 trivikr

Thanks for opening this issue. A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

welcome[bot] avatar Dec 16 '22 01:12 welcome[bot]

@trivikr Thanks so much for opening an issue! I'll triage this for the team to take a look :eyes:

cmwilson21 avatar Dec 16 '22 14:12 cmwilson21

Thanks @cmwilson21

It would be awesome if the bug in github.ref itself is fixed. If that happens, the documentation is not required to be updated.

As per the documentation, the github.ref for pull_request should contain PR merge branch refs/pull/:prNumber/merge, but my tests shows main for closed activity.

trivikr avatar Dec 16 '22 18:12 trivikr

@trivikr Thanks for this additional info ✨

Just a heads up, several members of our team are out for the holidays. Someone will have eyes on this soon, until then, we appreciate your patience 💖

cmwilson21 avatar Dec 20 '22 14:12 cmwilson21

Sure. I'm not blocked, as I used github.event.pull_request.number to compute branch name. There is a workaround. This issue is created to either fix the issue in backend (recommended), or update the docs.

trivikr avatar Dec 20 '22 17:12 trivikr

Hey @trivikr, thank you for opening this! I've reached out to a subject matter expert about this, and will keep you updated with what our next steps will be. 🚀

SiaraMist avatar Jan 17 '23 22:01 SiaraMist

Thanks for opening an issue! We've triaged this issue for technical review by a subject matter expert :eyes:

github-actions[bot] avatar Jan 18 '23 14:01 github-actions[bot]

Hey @trivikr 👋

After talking with a subject matter expert, we've determined the best way to resolve this would be to update the example code in the doc you linked to use github.head_ref instead of github.ref. This will give you the source branch instead of the merge branch, which is where you'd want to delete the caches from when you are using this workflow.

So if we change:

REPO=${{ github.repository }}
BRANCH=${{ github.ref }}

to

REPO=${{ github.repository }}
BRANCH=${{ github.head_ref }}

the workflow should do what you want it to do. You can find the supporting documentation for the github context here: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context

Thank you for sharing this issue with us, and you or anyone else is welcome to open a PR to apply these changes! 🚀

SiaraMist avatar Jan 23 '23 19:01 SiaraMist

we've determined the best way to resolve this would be to update the example code in the doc you linked to use github.head_ref instead of github.ref

Using BRANCH=${{ github.head_ref }} does not work for my use case, as the value is source branch use-head-ref-branch-cache-cleanup and not merge branch refs/pull/362/merge.

Details in Pull Request: https://github.com/awslabs/aws-sdk-js-codemod/pull/362#issuecomment-1400882170

This will give you the source branch instead of the merge branch, which is where you'd want to delete the caches from when you are using this workflow.

I don't think works as caches are tied to merge branch as per documentation. https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache

trivikr avatar Jan 23 '23 19:01 trivikr

Hey @trivikr, I sent your question to our subject matter expert, and they are taking a look to get a better understanding of this. I do see what you are saying about how caches created on pull requests are linked to the merge ref instead of the source branch. I will update you when I have more information!

SiaraMist avatar Jan 24 '23 22:01 SiaraMist

Thanks for opening an issue! We've triaged this issue for technical review by a subject matter expert :eyes:

github-actions[bot] avatar Jan 25 '23 16:01 github-actions[bot]

در تاریخ چهارشنبه ۲۵ ژانویه ۲۰۲۳،‏ ۱:۵۲ ق.ظ Siara @.***> نوشت:

Hey @trivikr https://github.com/trivikr, I sent your question to our subject matter expert, and they are taking a look to get a better understanding of this. I do see what you are saying about how caches created on pull requests are linked to the merge ref instead of the source branch. I will update you when I have more information!

— Reply to this email directly, view it on GitHub https://github.com/github/docs/issues/22727#issuecomment-1402767288, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5EC2T7NLXW2FZKF7FC7SODWUBI37ANCNFSM6AAAAAATAL4ZSY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

yasraubi avatar Jan 25 '23 17:01 yasraubi

Hey @trivikr, I heard back from our subject matter expert and your proposed solution to update:

BRANCH=${{ github.ref }} to BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

in the example is a great one. You or anyone else is welcome to pick up this issue and implement that change. 💛 Thank you again for finding this error and working through it with us!

SiaraMist avatar Jan 31 '23 18:01 SiaraMist

Thanks! I've posted a PR to update cache cleanup example at https://github.com/github/docs/pull/23612

trivikr avatar Jan 31 '23 19:01 trivikr

Issue reported once more in:

  • #23600

Thanks for working out the fix!

andreasabel avatar Feb 02 '23 08:02 andreasabel