github-push-action
github-push-action copied to clipboard
Default Branch should be triggered branch not Master
The reason for this is because i was having hair pulling troubles trying to figure out how to get this action to push to the branch that triggered the script. Due to the complexity of github actions.
In addition, this Action name's "intent" is just push, which by default I would expect it to only push on the triggered branch, not merge to master.
Either it should by default push to trigger branch or give the example to do so in the readme file.
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref }}
or
branch=${GITHUB_REF#refs/heads/}
inside your action
+1 for defaulting to current branch. I like the solution by @DavidGOrtega. Could you please update the code and the README.md accordingly?
Out of curiosity, is there a difference between ${{ github.head_ref }} and ${GITHUB_REF#refs/heads/}?
The former is for the .yml file (Syntax: GitHub Actions), the latter is inside https://github.com/ad-m/github-push-action/blob/master/start.sh (Syntax: Bash).
The advantage of the latter approach is that the script will also work when triggered in a push. Otherwise, it will only work in a pull_request event. (As far as I did not do something wrong in my experiements this morning. There, the variable github.head_ref was empty in the case of a push event)
The former is for the
.ymlfile (Syntax: GitHub Actions), the latter is inside https://github.com/ad-m/github-push-action/blob/master/start.sh (Syntax: Bash).
Ahh fair enough
The advantage of the latter approach is that the script will also work when triggered in a
push. Otherwise, it will only work in apull_requestevent. (As far as I did not do something wrong in my experiements this morning. There, the variablegithub.head_refwas empty in the case of apushevent)
The former works for push for me. See action script.
Heres a screenshot of github action trigger that was successful in committing to master from a push onto master.
Do you know if an empty HEAD: defaults to master?
If so then thats probably how mine is working and my script isnt doing what i think its doing 😅.
im not familiar with git command line.
I set our CI to use this plugin to push only tags. So I didn't set branch and I thought that it will push only tags. But a very weird thing happened. Every time our workflow finished a deploy from any branch it 'force' pushes the current branch to the master. 😲
Maybe I did not read the documentation properly but I still think that if I don't specify the branch, it should push to the current or doesn't push branch at all.
@koppor
The former is for the
.ymlfile (Syntax: GitHub Actions), the latter is inside https://github.com/ad-m/github-push-action/blob/master/start.sh (Syntax: Bash).The advantage of the latter approach is that the script will also work when triggered in a
push. Otherwise, it will only work in apull_requestevent. (As far as I did not do something wrong in my experiements this morning. There, the variablegithub.head_refwas empty in the case of apushevent)
You can use the ref instead of head_ref for push events.
https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#github-context
branch: ${{ github.head_ref }} is to change on which branch it comes from. How to make it push on the committer fork instead of the upstream on pull request?
Hi @yasirroni,
if understand your question correctly, you wanna push inside an PR scenario in the fork, correct? You can try the following parameters:
branch: '${{ github.event.pull_request.head.repo.default_branch }}'
repository: '${{ github.event.pull_request.head.repo.full_name }}'