From 3adf9a386ac10ba797088713cd0d9f2a2aae60d4 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Wed, 29 Jul 2020 16:10:25 +0800 Subject: [PATCH] first good version. Signed-off-by: Chao Li --- 064-gate/proposal.md | 65 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/064-gate/proposal.md b/064-gate/proposal.md index 67ce8f30..57bba42a 100644 --- a/064-gate/proposal.md +++ b/064-gate/proposal.md @@ -50,27 +50,70 @@ For the above use case 2, `gate` can be used like: - gate: no-release-gate condition: no-release in ((.:mr_info.labels)) - fail: false + nofail: true ``` +## Step definition + Step `gate` takes a name for description of the gate, and takes the following parameters: * `condition` a boolean expression. when `condition` is true, abort the build. -* `fail` if `fail` is true, fail the build `condition` is true; otherwise abort the build -with succeeded result. +* `nofail` by default, if `condition` is true, the build will fail. If you just +want to silently quit the build (with succeeded result), then set `nofail` to +true. +* `objects` a list of objects defined as: + * `name` object name + * `file` file name to load the object. The file should be in json or yaml format. -# Open Questions +## Condition syntax -How to define `condition`? +After some research, I found the package https://github.com/PaesslerAG/gval can +be used for expression evaluation. It supports basic evalutation syntax, and can +be extended to support more operations. -Basically `condition` will be evaluated to a boolean value. -An expression may contains: +### Integer operations and comparisons + +```yaml +- load_var: mr_info + file: mr/data.json + +- gate: some-gate + condition: ( ( ((.:mr_info.error)) + ((.:mr_info.failure)) ) / 300 ) > 0.85 +``` + +### String operations and comparisons + +```yaml +- load_var: mr_info + file: mr/data.json + +- gate: some-gate + condition: "((.:mr_info.result))" == "success" +``` + +```yaml +- load_var: mr_info + file: mr/data.json + +- gate: some-gate + condition: prefix_with( "((.:mr_info.subject))", "WIP" ) +``` + +### JSON object operations + +```yaml +- gate: some-gate + condition: "no-release" in mr_info.lables + objects: + - name: mr_info + file: mr/data.json +``` + + +# Open Questions -* integer comparison -* string comparison -* not logic -* check if an item is in a list +Any suggestions to condition syntax? # Answered Questions