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

when evaluation string filter #312

Closed
anbraten opened this issue Sep 17, 2021 · 5 comments · Fixed by #1213
Closed

when evaluation string filter #312

anbraten opened this issue Sep 17, 2021 · 5 comments · Fixed by #1213
Labels
pipeline-config related to pipeline config files (.yaml)

Comments

@anbraten
Copy link
Member

anbraten commented Sep 17, 2021

Clear and concise description of the problem

Currently Woodpecker already has quite some options for when to filter steps, but there are already some more requested adding all kind of exceptions would require quite some maintenance in the future.

Suggested solution

Woodpecker could introduce artithmetic/string expressions to evaluate if a step should be executed replacing the current yml options. This could be done by some library like govaluate. By adding all kind of meta-data available for a step as variables and adding a few special functions a user could simply write own expressions like this example:

woodpecker.event == "tag" && contains(toLowerCase(woodpecker.commit.message), "[skip ci"])

A similar feature is available for Github Actions

@anbraten anbraten added the pipeline-config related to pipeline config files (.yaml) label Sep 19, 2021
@6543
Copy link
Member

6543 commented Sep 29, 2021

drone did something similar with its new pipeline config format:
https://github.com/go-gitea/gitea/blob/7815f244d6254f85fca439b0bbfaf63c0e263ea4/.drone.yml#L5-L13

for expressions I would say we should not do that, instead add support for Starlark as it's already in used:

that way we have two options: a nice readable simple strait forward condig - or a powerful scripting lang to generate config dynamicaly

@6543
Copy link
Member

6543 commented Sep 29, 2021

it the starlark part in drone is apache2 ... we might just can copy it? no: https://github.com/drone/drone-convert-starlark/blob/master/LICENSE.md

but underplaying lib is: https://github.com/bazelbuild/bazel-gazelle

@anbraten
Copy link
Member Author

it the starlark part in drone is apache2 ... we might just can copy it? no: https://github.com/drone/drone-convert-starlark/blob/master/LICENSE.md

Damn.


I like the starlark approach, but on the other hand we wont drop the yml support and IMO there are already quite some special when options like when.path.ignore_message (docs) and some similar possibilities have already been asked for: #125, #224, #304

My suggestion for the long term would be:

  • add some new field to when called something like: if or condition which can take an expression as string
  • add some variables like commit title, commit sha, commit author, tag, ref, step-id, ... to the context variables
  • change when to accept an array to be able to define multiple when conditions as some kind of OR (the conditions inside a current when are evaluated as AND)
  • deprecate some very special options like: when.path.ignore_message
  • add step when conditions to pipeline as well (context of variables could be different as some values of a step could not be available and some additional values could be added)

Maybe may example (contains(toLowerCase(woodpecker.commit.message)) was a bit drastic with adding something like this contains function 😉 . I would only start with standard expressions like == .
This would in addition match how Github, Gitlab, ... have it so migration would maybe be simpler for new users.

@6543
Copy link
Member

6543 commented Sep 30, 2021

the easiest way to add or: A | B => !(!A & !B) if we make branch= or ref= to condition matching -> where branch: !ignore|!release/** would work

but if we add to mouch of that syntax thing ... I realy like to fokus adding starlark - and not add more specail build in options

@anbraten anbraten changed the title Next level when filters when evaluation string option Jan 12, 2022
@anbraten anbraten changed the title when evaluation string option when evaluation string filter Jan 12, 2022
@x80486
Copy link

x80486 commented Jun 9, 2022

While my intent on linking all these is not to make Woodpecker CI the same as the others, I think the GitLab CI solution around rules is pretty powerful and flexible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pipeline-config related to pipeline config files (.yaml)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants