Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow the use of if condition to trigger github events #357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

toVersus
Copy link

We could add if condition to trigger workflows with all the supported GitHub events. Please refer to the example repository below.
https://github.com/toVersus/github-actions-sandbox

However, when running actionlint on the example repository, it will return the following error:

actionlint
.github/workflows/action.yaml:3:5: unexpected key "if" for "branch_protection_rule" section. expected one of "branches", "branches-ignore", "paths", "paths-ignore", "tags", "tags-ignore", "types", "workflows" [syntax-check]
  |
3 |     if: true
  |     ^~~
(...)

This PR enables the linter to permit the use of if condition for triggering GitHub events.

@rhysd
Copy link
Owner

rhysd commented Oct 2, 2023

I couldn't find documentation for this syntax in any official documents:

Would you show some pointer? I'd like to confirm this is officially defined by GitHub.

@toVersus toVersus force-pushed the feat/support-github-events-if branch from c83ac9f to 18988e5 Compare October 3, 2023 00:31
@toVersus
Copy link
Author

toVersus commented Oct 3, 2023

I couldn't find documentation for this syntax in any official documents:

Unfortunately, I couldn't find the documentation either, so I demonstrated the behavior using the sample repository.
The specific use case is related to Digger with the following setup.

name: Terraform Digger

on:
  pull_request:
    branches: [ "main" ]
    types: [ closed, opened, synchronize, reopened ]
  issue_comment:
    types: [created]
    if: contains(github.event.comment.body, 'digger')
  workflow_dispatch:

jobs:
  (...)

I understand that this request may not be considered acceptable since it's not documented behavior. In that case, we will proceed by continuing to ignore the specifi linter error using the following command.

actionlint -color -ignore 'unexpected key "if" for "issue_comment" section'

@rhysd
Copy link
Owner

rhysd commented Feb 14, 2024

Okay, I'll ask it at the official forum.

@rhysd
Copy link
Owner

rhysd commented Feb 16, 2024

https://github.com/orgs/community/discussions/108504

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants