github-push-action icon indicating copy to clipboard operation
github-push-action copied to clipboard

Default Branch should be triggered branch not Master

Open Snazzie opened this issue 5 years ago • 10 comments

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 }}

Snazzie avatar Dec 05 '19 21:12 Snazzie

or

branch=${GITHUB_REF#refs/heads/} 

inside your action

DavidGOrtega avatar Dec 18 '19 23:12 DavidGOrtega

+1 for defaulting to current branch. I like the solution by @DavidGOrtega. Could you please update the code and the README.md accordingly?

koppor avatar Jan 02 '20 06:01 koppor

Out of curiosity, is there a difference between ${{ github.head_ref }} and ${GITHUB_REF#refs/heads/}?

Snazzie avatar Jan 02 '20 10:01 Snazzie

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)

koppor avatar Jan 02 '20 10:01 koppor

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

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 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 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. Screenshot from Gyazo

Snazzie avatar Jan 02 '20 11:01 Snazzie

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.

Snazzie avatar Jan 02 '20 11:01 Snazzie

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.

jcislinsky avatar Jan 31 '20 05:01 jcislinsky

@koppor

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)

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

Gummibeer avatar Feb 08 '20 16:02 Gummibeer

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?

yasirroni avatar Apr 14 '22 23:04 yasirroni

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 }}'

ZPascal avatar Apr 16 '22 18:04 ZPascal