-
Hi! I just wrote my first GitHub Action, which gets triggered when an issue is opened. I now want to change this so that the runner starts only when a particular label is assigned. I know I can use the trigger/type “labeled” for issues, but I want to look for a specific label. Is that possible? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 3 replies
-
Currently, GitHub Actions does NOT support to set labels filter for issues event. However, as a workaround, you can use if conditional to skip all jobs in the workflow when the label does not match the specific label. And you need to add the if conditional on every job.
More details, you can reference here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idif |
Beta Was this translation helpful? Give feedback.
-
Ah, I see, thanks a lot. I played a little with the if conditional and this works pretty well. It looks like that the job produces a “fail” if the condition is not met, right? This would give me an error message/email… I could add the conditional to each step and get rid of that, but this seems less obvious. Is the described behavior expected and intended? Btw. I found another way to test for any given label (since I now knew where to look thanks to your reply):
Don’t know if that is a good idea (since it could find <label_name> somewhere else in the issue data), but so far it works. |
Beta Was this translation helpful? Give feedback.
-
Yeah, in the past, if all jobs in a workflow were skipped with the if conditional , the workflow displayed as “skipped/no status” status with a grey icon. But now, it displays as failed and will send the notification email for the failed workflow run. |
Beta Was this translation helpful? Give feedback.
-
Or you can use:
It works in the case you put a label in a PR. |
Beta Was this translation helpful? Give feedback.
-
This is a great solution ! We are using this but now if shows a failed workflow instead of just not running it. Do you have a workaround ? |
Beta Was this translation helpful? Give feedback.
-
add a empty step that just echo some dummy text. Edit: Sorry I haven’t seen the date. |
Beta Was this translation helpful? Give feedback.
-
Hello! I have been trying to get labels in Github Actions with all the methods above and unable to do so. Did something change in the way those can be extracted from the PR? Currently, my actions trigger on push and labels are missing in the Github context Any help would be appreciated! Cheers |
Beta Was this translation helpful? Give feedback.
-
Hey. I searched for a while, but did not found any solution. Is it possible to check if the label was set by some specific account or even better by the codeowner(s)? |
Beta Was this translation helpful? Give feedback.
-
This is really disappointing - not being able to limit a workflow from running ends up polluting the list of ran actions pretty dramatically, because even if you conditionalize a job it will still show up in the list of actions just with a gray cross over it indicating it didn’t run. This is exceptionally problematic when conditionally running a large number of actions. |
Beta Was this translation helpful? Give feedback.
-
Just to save someone else some time: Problem 1As described here
So using path in
is out of the question unfortunately. BTW the code over at this example won't work either for all file types changed, the correct glob syntax will be We're getting around this by using the labeler action. The lint workflow now looks something like:
Problem 2There's a major difference between how
I bashed my head against this for about an hour trying to figure out how it's evaluating to true, and with some trial and error found that with @lmancilla 's original suggestion of TLDRBe mindful of which exact |
Beta Was this translation helpful? Give feedback.
Currently, GitHub Actions does NOT support to set labels filter for issues event.
However, as a workaround, you can use if conditional to skip all jobs in the workflow when the label does not match the specific label. And you need to add the if conditional on every job.
More details, you can reference here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idif