如何使用GitHub Action拒绝来自存储库成员的推送? [英] How can I reject push from repository members using GitHub Actions?

查看:177
本文介绍了如何使用GitHub Action拒绝来自存储库成员的推送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务如下:收到新的提交(通过一次推送)后,有必要执行github动作,该动作将通过ssh(使用git pullnpm test).然后,如果测试失败,则应取消此推送(其中的所有提交).

My task is as follows: Upon receive of a new commits (by single push), it is necessary to perform a github action, which would send the task to test on a test server via ssh (with git pull and npm test). Then, if testing fails, this push (all commits in it) should be canceled.

第一部分似乎没有问题,但是我不知道如何实现第二部分,即取消推送.谢谢您对这个问题的关注!

With the first part, it seems, there are no problems, but I can’t figure out how to implement the second part, that is, canceling the push. Thank you for your attention to the question!

推荐答案

您不能使用GitHub Actions来阻止推送;您将需要一个预接收钩子来执行此操作.尽管GitHub Enterprise Server(本地版本)支持,但是GitHub的云版本目前不支持.

You can't use GitHub Actions to prevent a push; you would need a pre-receive hook to do that. GitHub's cloud version doesn't currently support that, although GitHub Enterprise Server (the on-premises version) does.

但是,根据您对npm test的使用,可以执行的操作以及听起来可能要执行的操作是在push上运行CI作业并限制master分支.当拉取请求打开时,您可以使用GitHub Actions自动测试您的代码,并要求所有检查都通过后才能合并.由于master分支无法直接推送到,因此无法避免CI作业.

However, what you can do, and what it sounds like you probably want to do based on your use of npm test, is to run a CI job on push and restrict the master branch. You can use GitHub Actions to automatically test your code when a pull request is opened and require that all checks pass before it can be merged. Since the master branch cannot be pushed to directly, it wouldn't be possible to avoid the CI job.

如果您是该项目的唯一贡献者,则可以将分支推送到您的存储库,让CI作业运行,然后在作业通过时将其快速合并到master中.这还需要做更多的工作,但是您不必打开任何拉取请求.

If you're the only contributor to the project, you can just push your branch to your repository, let the CI job run, and then do a fast-forward merge into master if the job passes. This is a little more work, but you don't have to open any pull requests.

这篇关于如何使用GitHub Action拒绝来自存储库成员的推送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆