|
I am trying to set up my workflow so it doesn’t run when opening/synching/reopening pull requests that are marked as draft. I have found that I can use on my job, but it will still run for a few seconds, and “fail”, leaving a red X on every commit on the PR until it is marked ready for reveiw. I could maybe add a dummy-job that has on it, and just echo something, but it will still run for a few seconds though. My test-workfow so far looks like this:
Will those seconds be added up and billed? Is there another or better way of getting around this? |
Replies: 25 comments 13 replies
|
jobs.<id>.if is broken currently, that’s why you get “fail” instead of “skip” status. |
|
Ah, okay. So if I just leave it as-is and they fix the issue it won’t be a problem? |
|
Yeah, if you don’t mind extra notifications. I’m not touching mine waiting for a fix - beauty of betas :] |
|
I can confirm that this works for me now: Thanks for pointing it out! |
|
Because of this, I have found a better way for myself. See |
This isn’t working for me. Github actions are run anyways. |
Is working but it has 2 drawbacks: - The check is reported as successful even though it didn’t actually run - When the PR is switched from “draft” to “ready” the CI does not run again and the check is still marked as successful so a user is able to merge the PR without having the check actually pass. |
|
@julioromano |
|
|
@julioromano But I do not see my suggested solution in your configuration 🙄. |
|
Sorry brainfart :slight_smile: I edited it. I pasted wrong code while trying other solutions. |
|
@julioromano I think it is not working because you have these two lines here, which is not what I suggested.
You should remove them. It should look like this: |
|
I tested it, still not very practical : it would run action once after undrafting or review request, but not for further pushes on the PR (e.g. when the reviewer asked changes and the developer pushes them). When your actions are running tests or lint… it’s not ideal. |
|
Just invite the reviewer again (small refresh button next to the name). It is not really good, but works. Unlike other things. |
|
It seems to me that you should just use both: So it won’t run while draft, but it does run when undrafting and for future updates. |
|
@natario1’s solution works very well! Thanks! I have one issue though: When I press “Ready for review”, it takes a couple of seconds for the new run to trigger. During that time the check is marked as passed. It’s enough time to easily merge the pull request. This makes it possible to accidentally bypass the branch protection rule that the check must pass before merging. 😱 |
|
natario1:
This would be a simpler solution
|
|
@chenrui333 nope, your simpler version won’t work, see the official notes: docs.github.com Events that trigger workflows - GitHub Docs//docs.github.com/en/actions/reference/events-that-trigger-workflows |
|
You can add an additional job that fails if pull request is a draft to prevent the bypass problem: Example: |
|
Using the following trigger options worked for me. You have to first open PRs as Draft but whenever you turn it Ready for review CI workflows will be executed. on:
push:
branches:
- main
pull_request:
branches: [main]
paths:
- "**"
- "!/*.md"
- "!/**.md"
types:
- ready_for_review |
|
This took us a while to figure out, but if you want the to work, make sure your workflow has the right permission to read PRs in the repo. Without that, it won't trigger. |
|
I need the ability to to run CI on a draft PR when the PR is for changes to the GHA code itself and I don't want/need review/feedback in early stages of GHA code fixes/features. In fact, I'm running a CI build right now on a draft PR to test a GHA change. |
|
As it is now, the workarounds are too ad hoc for us. It should be possible to have the github actions not start at all as long as the PR is draft and have it start as soon as you get the ready for review event. It should also start immediately if the PR is opened not as a draft. |
|
here's how I'm currently doing it: on:
push:
branches:
- 'main'
- 'development'
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
branches:
- '**'
jobs:
build:
if: github.event.pull_request.draft == false && github.base_ref != 'main' |
|
The |
jobs.<id>.if is broken currently, that’s why you get “fail” instead of “skip” status.