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

Default Branch should be triggered branch not Master #38

Open
Snazzie opened this issue Dec 5, 2019 · 10 comments
Open

Default Branch should be triggered branch not Master #38

Snazzie opened this issue Dec 5, 2019 · 10 comments

Comments

@Snazzie
Copy link

Snazzie commented Dec 5, 2019

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 }}
@DavidGOrtega
Copy link

DavidGOrtega commented Dec 18, 2019

or

branch=${GITHUB_REF#refs/heads/} 

inside your action

@koppor
Copy link
Contributor

koppor commented Jan 2, 2020

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

@Snazzie
Copy link
Author

Snazzie commented Jan 2, 2020

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

@koppor
Copy link
Contributor

koppor commented Jan 2, 2020

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)

@Snazzie
Copy link
Author

Snazzie commented Jan 2, 2020

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
Copy link
Author

Snazzie commented Jan 2, 2020

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.

chfw added a commit to moremoban/yehua that referenced this issue Jan 23, 2020
@jcislinsky
Copy link

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.

@Gummibeer
Copy link

@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

tsvi added a commit to tsvi/py-libhdate that referenced this issue Mar 1, 2020
As noted here ad-m/github-push-action#38, by default
the push is done to the master branch. As master is locked down, the push should
be done to the pull requests branch
tsvi added a commit to tsvi/py-libhdate that referenced this issue Mar 1, 2020
As noted here ad-m/github-push-action#38, by default
the push is done to the master branch. As master is locked down, the push should
be done to the pull requests branch
tsvi added a commit to py-libhdate/py-libhdate that referenced this issue Mar 1, 2020
* fix: when updating changlelog push back to pull request

As noted here ad-m/github-push-action#38, by default
the push is done to the master branch. As master is locked down, the push should
be done to the pull requests branch

* fix: Try by specifying ref on checkout as found in github comment

ref: ad-m/github-push-action#44 (comment)

* fix: add request to persist credentials when checking out

* Use fetch-depth set to 0

* Move back to use bumpversion

* Don't run pre commit on auto generated files

* WIP: recreate auto deployment
chfw added a commit to moremoban/yehua that referenced this issue May 8, 2020
* ✨ generate a hello world project from cookie cutter template on disk. related to #37

* 💚 make ci pass

* 🔥 drop python 2 support and test

* 💄 pump up the version

* 💚 adapting moban v0.7.0. moremoban/moban#362

* 🔥 remove pypy3 because it is based on python 3.5.3

* 🔥 replace nose with pytest

* 💚 pytest requires the package to be installed by default

* 🔬 test cookie cutter, hello world project generation. #37

* ✨ auto-genenerate yehua file from cookie cutter json. #37

* ✨ first ever pass on cookiecutter-pypackage. yes, this code now can generate a cookiecutter package from cookiecutter-pypackage offline. steps: 1) git clone cookiecutter-pypackage 2) yh -c cookiecutter-pypackage 3) answer the quesetions 4) you will have what you wanted. #37

* 💚 fix unwanted yaml dependency

* ✨ yes we need to use cookiecutter.extension.*

* ✨ use moban update in github action

* 🔨 problem solved

* 🔨 use python 3.7

* 🔨 commit to feature branch

* 📚 test moban update

* 📚 commit changes

* 📚 use default github token

* 📚 how could I about this without documentationgit add .github/workflows/moban-update.yml ad-m/github-push-action#38

* 📚 tweek it work?

* 📚 fix detached state. actions/checkout#6

* 📚 cannot i simply push

* 📚 use auto commit

* 📚 use checkout v2

* 📚 use checkout v2

* This is an auto-commit

* 📚 test if auto commit would commit nothing or not

* 📚 test if auto commit would commit something

* 📚 test if auto commit would commit something

* This is an auto-commit

* ✨ add colon

* This is an auto-commit

* ✨ need if statement

* ✨ need if statement

* This is an auto-commit

* ✨ generate directly from a git repo. #37

* 🔥 remove unused imports

* 🔥 remove useless codes

* ✨ first working POC. yh -c cookiecutter-pypackage #37

* 💚 pass all unit tests

* 🔥 remove unused imports

* 💚 fix coding style

* ✨ minor tweak to support git url. python filesytem did the magic! #37

* 💚 test cookiecutter package as git repo

* 💚 add gitfs2 as test requirements

* This is an auto-commit

* 💚 add gitfs2 as test requirements

* This is an auto-commit

* ✨ seemless integration with cookiecutter. simply replace cookiecutter with yh. the rest will follow. #37

* This is an auto-commit

* 🔨 code refactoring

* 🔨 code refactoring

* This is an auto-commit

* 🔥 remove unused imports

Co-authored-by: chfw <[email protected]>
kamioftea pushed a commit to kamioftea/advent-of-code-2021 that referenced this issue Dec 2, 2021
@yasirroni
Copy link

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?

@ZPascal
Copy link
Collaborator

ZPascal commented Apr 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants