How to get base ref branch in a GitHub Actions workflow? #26243
-
I want to know against which base a branch has a pull request open (if any). For example I have a In the docs, it says we can see the base ref with
Is there a way to know the base ref on every push to This is my code, but this only works once when I create the PR (and not on every push):
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
merc1er:
No, because a push doesn’t have a “base ref”, just a before and after state on the branch that’s being pushed. If you want to act based on a PR you need to use one of the PR-related events (or iterate over PRs using the API, but that could get messy and run afoul of rate limits). |
Beta Was this translation helpful? Give feedback.
-
So, I have special code that looks to see if a git push has a corresponding open PR:
check-spelling/check-spelling/blob/624e4ede7c93c6255ad80c08395fc1687b6a3e10/unknown-words.sh#L41-L47
check-spelling/check-spelling/blob/624e4ede7c93c6255ad80c08395fc1687b6a3e10/unknown-words.sh#L60-L66
check-spelling/check-spelling/blob/624e4ede7c93c6255ad80c08395fc1687b6a3e10/unknown-words.sh#L74-L75
You can do all sorts of magical things. Whether you should is a different story. In my case, I like that my action/workflow can run on both |
Beta Was this translation helpful? Give feedback.
No, because a push doesn’t have a “base ref”, just a before and after state on the branch that’s being pushed.
If you want to act based on a PR you need to use one of the PR-related events (or iterate over PRs using the API, but that could get messy and run afoul of rate limits).