woodpecker icon indicating copy to clipboard operation
woodpecker copied to clipboard

Added support for pipeline root.when conditions

Open LamaAni opened this issue 3 years ago • 16 comments

Closes #283

As a ci user I would like to set a file/yaml global when condition, to disable pipeline runs. This allows easier to write control for the pipeline events, branches and metadata.

Changes

  • [ ] add root when conditions:
    • [ ] branch
    • [ ] repo
    • [ ] event
    • [ ] tag
    • [ ] platform
    • [ ] instance
    • [ ] path
  • [x] add docs
  • [ ] update yaml schema
  • [ ] wait for #686

Fixes

  1. In hook.go, when one of the yaml(s) was filtered by branch the hook would not fire. Changed to if all are filtered hook is not fired.
  2. changed function name 'branchFiltered' -> 'checkIfFiltered'

LamaAni avatar Feb 09 '22 18:02 LamaAni

Codecov Report

Merging #770 (2695014) into master (7db7e97) will increase coverage by 0.14%. The diff coverage is 100.00%.

:exclamation: Current head 2695014 differs from pull request most recent head d6d0f9e. Consider uploading reports for the commit d6d0f9e to get more accurate results

@@            Coverage Diff             @@
##           master     #770      +/-   ##
==========================================
+ Coverage   49.57%   49.71%   +0.14%     
==========================================
  Files          86       86              
  Lines        6548     6557       +9     
==========================================
+ Hits         3246     3260      +14     
+ Misses       3111     3106       -5     
  Partials      191      191              
Impacted Files Coverage Δ
server/shared/procBuilder.go 85.13% <100.00%> (+0.51%) :arrow_up:
server/logging/log.go 54.65% <0.00%> (+5.81%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Feb 09 '22 20:02 codecov-commenter

@6543 From the current changes I don't think this would be breaking.

anbraten avatar Feb 09 '22 21:02 anbraten

I'll look at this code diff asap I'm ready to release v0.15.0 :)

6543 avatar Feb 10 '22 18:02 6543

I'm thinking of adding support for multiple root when conditions. E.g.

when:
- event:
    - pull_request
    - release
- branch: master

This would allow both things to be captured, e.g. Either on master, or on pr and release. @anbraten @6543 What do you think?

LamaAni avatar Feb 24 '22 21:02 LamaAni

@LamaAni We thought about such a change as well #686. Would be quite helpful I think. I would suggest we try to merge this change and then change both root-level when and step-level when to be an array or at least to allow to enter an array somehow.

anbraten avatar Feb 24 '22 21:02 anbraten

@anbraten We can use a whenArray for now :) And just add it to both without breaking.

As I suggested in the issue I think a redesign of the yaml config is necessary, mostly since it dose not follow yaml guidelines and treats some dicts as lists (with name). Then, in yaml 2.0 we can do a proper fix for this.

LamaAni avatar Feb 24 '22 21:02 LamaAni

@anbraten @6543 Added support for when array. To allow multiple whens. This would be a temp step before cleaning it?

LamaAni avatar Feb 28 '22 23:02 LamaAni

I'll shortly have a look ...

to the "whenArray" ... we could do this similar to how it's done with the "path" config ... first try to pars it as map ... witch should fail if its an array, then parse it as array ... save this as array internally in all cases ...

6543 avatar Mar 01 '22 03:03 6543

@6543 I'll give that a go. And see what we get.

LamaAni avatar Mar 01 '22 03:03 LamaAni

@6543 Updated to auto detect array.

LamaAni avatar Mar 01 '22 16:03 LamaAni

ok ... pipeline/schema/schema.json needs an update & we need good documentation :)

6543 avatar Mar 01 '22 16:03 6543

ok ... pipeline/schema/schema.json needs an update & we need good documentation :)

Would you mind adding that @6543 I am not sure what the configuration looks like. Also, we should add the validation as an array no?

LamaAni avatar Mar 01 '22 16:03 LamaAni

ok I'll push it to this branch ...

6543 avatar Mar 01 '22 16:03 6543

I'm going to split out the two changes ... A: root.when B: multi-when

6543 avatar Jun 15 '22 21:06 6543

Deployment of preview was successful: https://woodpecker-ci-woodpecker-pr-770.surge.sh

woodpecker-bot avatar Aug 09 '22 21:08 woodpecker-bot

I'm going to split out the two changes ... A: root.when B: multi-when

=> #1087

anbraten avatar Aug 09 '22 22:08 anbraten

I think this should do it, but I like to have some more unit tests for pipeline.when filters ... ... so when I do refactor It wont break

6543 avatar Sep 01 '22 13:09 6543

conflicts ...

6543 avatar Sep 19 '22 20:09 6543