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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With