How can I do if github.event.action in ['foo', 'bar'] using GitHub Actions? I want to limit some actions from https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#release and the list of possible values is quite long.
Using || makes the entire construct huge, especially if you already need to combine it with other conditions.
you can accomplish that with GitHub functions:
contains(fromJson('["bar", "foo"]'), github.event.action)
sources:
example:
...
jobs:
some-job:
# runs on pull_request if action is "opened" or "synchronize"
if: github.event_name == 'pull_request' && contains(fromJson('["opened", "synchronize"]'), github.event.action)
...
...
The closest one you can use is
${{ contains(github.event.action, 'foo') || contains(github.event.action, 'bar') }}
Documentation
contains( search, item )
Returns true if search contains item. If search is an array, this function returns true if the item is an element in the array. If search is a string, this function returns true if the item is a substring of search. This function is not case sensitive. Casts values to a string.
Example using an array
contains(github.event.actions, 'bug')
Example using a string
contains('Hello world', 'llo') returns true
Reference: https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#contains
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