Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

YAML anchors cause linter failure when paths is set #18

Closed
staylor opened this issue Mar 4, 2020 · 5 comments
Closed

YAML anchors cause linter failure when paths is set #18

staylor opened this issue Mar 4, 2020 · 5 comments

Comments

@staylor
Copy link

staylor commented Mar 4, 2020

Drone configs allow YAML anchors:

drone_gcs_cache_common: &drone_gcs_cache_common
  image: homerovalle/drone-gcs-cache
  settings:
    bucket: foo
    restore: true
  environment:
    GCS_CACHE_JSON_KEY:
      from_secret: gcs_cache_json_key

then in practice:

- name: restore_master_caches
  <<: *drone_gcs_cache_common
  when:
    event: push
    branch: master

- name: restore_pr_caches
  <<: *drone_gcs_cache_common
  when:
    event: pull_request

However, if combined with use of when: paths:, YAML anchors declared in the config cause Linter errors - they are apparently interpreted as steps with no name attribute.

Given:

kind: pipeline
type: docker
name: test

drone_gcs_cache_common: &drone_gcs_cache_common
  image: homerovalle/drone-gcs-cache
  settings:
    bucket: foo
    restore: true

steps:
- name: foo
  image: node:12.14.1
  commands: 
  - npm i
  when:
    paths:
      include:
      - README.md

This will break immediately when run by Drone:

Linter: invalid or missing step name

If the when block is removed completely: everything works.
when also works when paths is not present.

Help?

@bradrydzewski
Copy link

Try changing the ordering of the anchor. I seem to recall there was a bug in the Go yaml parser where ordering of the anchor matters when unmarshaling into map[string]interface{}. @jimsheldon do you remember us having a similar conversation?

- - name: restore_master_caches
+ - <<: *drone_gcs_cache_common 
+   name: restore_master_caches
    when:
      event: push
      branch: master

A good way to debug and see what is happening under the hood is to use the command line tools to see a before and after. I am not sure the minimum input required for this particular plugin but you could start with the following:

export DRONE_CONVERT_ENDPOINT=https://...
export DRONE_CONVERT_SECRET=...

drone plugins convert --path=.drone.yml \
  --before=<before sha> \
  --after=<after sha> \
  --repository=foo/bar

This will return the converted yaml.

@tonglil
Copy link
Contributor

tonglil commented Mar 24, 2020

Oh wow, I think that worked!
Will do more testing and report back.

@jimsheldon
Copy link

Thanks @bradrydzewski, yes I think we discussed this at one point.

@tonglil Brad's comment describes the issue, in our testing we have seen reordering fix the problem.

I would love to create an issue, or subscribe to an existing issue in the Go yaml parser. Brad, are you aware of any existing issues? The buildkite fork does not support issues.

@jimsheldon
Copy link

I have added documentation for this work around here https://github.com/meltwater/drone-convert-pathschanged/tree/9168edcd073b54e000ba4f8daad1e3e6d5afc7d9#yaml-anchors

Closing this out

@tonglil
Copy link
Contributor

tonglil commented Apr 10, 2020

@jimsheldon thank you for following up and documenting the workaround.

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

No branches or pull requests

4 participants