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

Enable push to a protected branch #29

Open
pditommaso opened this issue Aug 15, 2021 · 4 comments
Open

Enable push to a protected branch #29

pditommaso opened this issue Aug 15, 2021 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@pditommaso
Copy link

Thanks for this nice action!

When adding it to my GitHub action file it turns out it's unable to push it because the master branch is protected.

/usr/bin/git push
remote: error: GH006: Protected branch update failed for refs/heads/master.        
remote: error: 2 of 2 required status checks are expected. At least 1 approving review is required by reviewers with write access.        
To https://github.com/nextflow-io/nextflow
 ! [remote rejected] master -> master (protected branch hook declined)
error: failed to push some refs to 'https://github.com/nextflow-io/nextflow'
(node:1610) UnhandledPromiseRejectionWarning: Error: The process '/usr/bin/git' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/githubocto/repo-visualizer/main/index.js:935:21)
    at ExecState.CheckComplete (/home/runner/work/_actions/githubocto/repo-visualizer/main/index.js:921:16)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/githubocto/repo-visualizer/main/index.js:824:21)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

I've managed to make it work by pushing to a different branch. However, it would be desirable to have some kind of option to allow pushing also to a protected branch if the committing user is allowed to.

@pditommaso
Copy link
Author

Update, also pushing to a separate branch has side-effects

To https://github.com/nextflow-io/nextflow
 ! [rejected]          repo-visualizer -> repo-visualizer (non-fast-forward)
error: failed to push some refs to 'https://github.com/nextflow-io/nextflow'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
(node:1736) UnhandledPromiseRejectionWarning: Error: The process '/usr/bin/git' failed with exit code 1
    at ExecState._setResult (/home/runner/work/_actions/githubocto/repo-visualizer/main/index.js:935:21)
    at ExecState.CheckComplete (/home/runner/work/_actions/githubocto/repo-visualizer/main/index.js:921:16)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/githubocto/repo-visualizer/main/index.js:824:21)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

@Wattenberger Wattenberger added good first issue Good for newcomers help wanted Extra attention is needed labels Aug 16, 2021
@ageorgou
Copy link
Contributor

I looked into this out of curiosity, and it seems that pushing to protected branches through GitHub Actions is not possible directly. See for example a similar discussion and a comment from GitHub staff. It looks like there is no intention of allowing Actions to bypass the protection (or at least wasn't at the time).

One workaround may be to create a PR (either as part of this action or as a separate step) and then merge it. Another alternative involves using a token by an admin user, and excluding admin users from the protection (though that can lead to weird behaviour because it look like the push was made by a real user, which can trigger workflows).

@filoxo
Copy link

filoxo commented May 12, 2022

GitHub now has a setting for this: https://github.blog/changelog/2021-11-19-allow-bypassing-required-pull-requests/
I haven't been able to make this work for my org yet but is worth taking a look at.

@chrisheninger
Copy link

I managed to work around this by pushing to a separate branch, then including the full URL to the raw SVG from that branch in my README.

GitHub Action:

      - uses: githubocto/repo-visualizer@main
        with:
          branch: diagram

README link:

![Visualization of this repo](https://github.com/org-name/repo-name/blob/diagram/diagram.svg?raw=true)

And everything should work splendidly! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants