-
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? |
Beta Was this translation helpful? Give feedback.
Replies: 23 comments 8 replies
-
jobs.<id>.if is broken currently, that’s why you get “fail” instead of “skip” status. |
Beta Was this translation helpful? Give feedback.
-
Ah, okay. So if I just leave it as-is and they fix the issue it won’t be a problem? |
Beta Was this translation helpful? Give feedback.
-
Yeah, if you don’t mind extra notifications. I’m not touching mine waiting for a fix - beauty of betas :] |
Beta Was this translation helpful? Give feedback.
-
I can confirm that this works for me now:
Thanks for pointing it out! |
Beta Was this translation helpful? Give feedback.
-
Because of this, I have found a better way for myself.
See |
Beta Was this translation helpful? Give feedback.
-
This isn’t working for me. Github actions are run anyways. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@julioromano |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@julioromano But I do not see my suggested solution in your configuration 🙄. |
Beta Was this translation helpful? Give feedback.
-
Sorry brainfart :slight_smile: I edited it. I pasted wrong code while trying other solutions. |
Beta Was this translation helpful? Give feedback.
-
@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:
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Just invite the reviewer again (small refresh button next to the name). It is not really good, but works. Unlike other things. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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. 😱 |
Beta Was this translation helpful? Give feedback.
-
natario1:
This would be a simpler solution
|
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
You can add an additional job that fails if pull request is a draft to prevent the bypass problem: Example:
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
jobs.<id>.if is broken currently, that’s why you get “fail” instead of “skip” status.