cirrus-ci-docs icon indicating copy to clipboard operation
cirrus-ci-docs copied to clipboard

Support of Hash keys in YAML configuration of `only` (and `skip`)

Open AlexWayfer opened this issue 5 years ago • 6 comments

Description

It'd be nicer to have a more handful confiuguration.

Context

Current configuration

only: ($CIRRUS_BRANCH == 'master') || changesInclude('Gemfile', 'Rakefile', '.rspec', '**.{rb,yml}')

Wished configuration

only:
  branch: master
  changes:
    - Gemfile
    - Rakefile
    - .rspec
    - '**.{rb,yml}'

Anything Else

GitLab CI: https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic

AlexWayfer avatar Mar 02 '20 23:03 AlexWayfer

I don't think we'll add such syntax support to YAML. We are focusing on Starlark support where you'll be able do something like:

load("cirrus", "env", "changes_include")

def generate_tasks(ctx):
  if !should_generate_tasks():
    return []
   ...

def should_generate_tasks():
    if env.get("CIRRUS_BRANCH") == "master":
        return True
   if changes_include('Gemfile', 'Rakefile', '.rspec', '**.{rb,yml}'):
        return True
  return False

Once https://github.com/cirruslabs/cirrus-cli/issues/309 is resolved.

fkorotkov avatar Feb 23 '21 19:02 fkorotkov

I don't like it (I don't want to introduce a DSL, a programming language, into config, which can be just simple and "smart", as in the provided example), but… as you wish, of course.

AlexWayfer avatar Feb 23 '21 20:02 AlexWayfer

Agreed. But the following syntax is also not clear:

only:
  branch: master
  changes:
    - '**.{rb,yml}'

It can be interpreted in both ways:

  • Test only commit to master containing Ruby or YAML files.
  • Test each commit to master or to any other branch if commit contains Ruby or YAML files.

With the boolean expressions there is no guessing.

fkorotkov avatar Feb 23 '21 20:02 fkorotkov

Agreed. But the following syntax is also not clear:

only:
  branch: master
  changes:
    - '**.{rb,yml}'

It can be interpreted in both ways:

  • Test only commit to master containing Ruby or YAML files.
  • Test each commit to master or to any other branch if commit contains Ruby or YAML files.

With the boolean expressions there is no guessing.

I can agree. And only: is kind of work-around too. But there is why the documentation.

I think, we can make a nice intuitive syntax, better than from the example. But any boolean logic will not fit into data format (YAML) natively, I guess.

OK, a little thing from my personal project with data in a huge YAML, applied to this example: nested Arrays, the first level is OR, the second — AND. If you need just AND — you should have a root Array of one element. We have Hashes here, so there is even no need for Arrays at the second level. So, it would be like:

only:
  - branch: master
  - changes:
      - '**.{rb,yml}'

For imaginable example like "in master only when there are specific changes, and in any time with more specific changes":

only:
  - branch: master
    changes:
      - '**.{rb,yml}'
  - changes:
      - '.cirrus.y{a,}ml'

I hope you understand. But, again, I understand that some DSL will cover any problem, for example, NOT operator and complex nested logic.

AlexWayfer avatar Feb 23 '21 20:02 AlexWayfer

OK, let's keep it open and see if there will inputs from other users. Nested arrays also look a bit magical. 😅

fkorotkov avatar Feb 23 '21 20:02 fkorotkov

Nested arrays also look a bit magical.

Such good CI as Cirrus also looks a bit magical, but with proper documentation it's a pleasure to use it! 😅

AlexWayfer avatar Feb 24 '21 17:02 AlexWayfer

Closing since we haven't heard similar feedbacks. 😓

fkorotkov avatar Oct 10 '22 19:10 fkorotkov