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

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

Closed
1 task done
trivikr opened this issue Dec 16, 2022 · 15 comments · Fixed by #23612
Closed
1 task done

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

trivikr opened this issue Dec 16, 2022 · 15 comments · Fixed by #23612
Labels
actions This issue or pull request should be reviewed by the docs actions team content This issue or pull request belongs to the Docs Content team help wanted Anyone is welcome to open a pull request to fix this issue.

Comments

@trivikr
Copy link
Contributor

trivikr commented Dec 16, 2022

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 trivikr added the content This issue or pull request belongs to the Docs Content team label Dec 16, 2022
@welcome
Copy link

welcome bot commented Dec 16, 2022

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.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team. label Dec 16, 2022
@cmwilson21 cmwilson21 removed the triage Do not begin working on this issue until triaged by the team. label Dec 16, 2022
@cmwilson21
Copy link
Contributor

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

@cmwilson21 cmwilson21 added actions This issue or pull request should be reviewed by the docs actions team waiting for review Issue/PR is waiting for a writer's review labels Dec 16, 2022
@trivikr
Copy link
Contributor Author

trivikr commented Dec 16, 2022

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.

@cmwilson21
Copy link
Contributor

@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 💖

@trivikr
Copy link
Contributor Author

trivikr commented Dec 20, 2022

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.

@lucascosti lucascosti assigned lucascosti and SiaraMist and unassigned lucascosti Jan 17, 2023
@SiaraMist
Copy link
Contributor

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. 🚀

@cmwilson21 cmwilson21 added the needs SME This proposal needs review from a subject matter expert. label Jan 18, 2023
@github-actions
Copy link
Contributor

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

@SiaraMist
Copy link
Contributor

SiaraMist commented Jan 23, 2023

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 SiaraMist added help wanted Anyone is welcome to open a pull request to fix this issue. and removed needs SME This proposal needs review from a subject matter expert. labels Jan 23, 2023
@docubot docubot added this to Help wanted in Docs open source board Jan 23, 2023
@SiaraMist SiaraMist removed the waiting for review Issue/PR is waiting for a writer's review label Jan 23, 2023
@SiaraMist SiaraMist removed their assignment Jan 23, 2023
@trivikr
Copy link
Contributor Author

trivikr commented Jan 23, 2023

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: awslabs/aws-sdk-js-codemod#362 (comment)

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

@SiaraMist
Copy link
Contributor

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!

@cmwilson21 cmwilson21 added the needs SME This proposal needs review from a subject matter expert. label Jan 25, 2023
@github-actions

This comment was marked as resolved.

@cmwilson21 cmwilson21 removed the needs SME This proposal needs review from a subject matter expert. label Jan 25, 2023
@yasraubi

This comment was marked as spam.

@SiaraMist
Copy link
Contributor

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!

@trivikr
Copy link
Contributor Author

trivikr commented Jan 31, 2023

Thanks! I've posted a PR to update cache cleanup example at #23612

Docs open source board automation moved this from Help wanted to Done Jan 31, 2023
@andreasabel
Copy link
Contributor

Issue reported once more in:

Thanks for working out the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions This issue or pull request should be reviewed by the docs actions team content This issue or pull request belongs to the Docs Content team help wanted Anyone is welcome to open a pull request to fix this issue.
Development

Successfully merging a pull request may close this issue.

8 participants
@andreasabel @lucascosti @trivikr @cmwilson21 @SiaraMist @yasraubi and others