YAML anchors cause linter failure when `paths` is set
staylor opened this issue · 5 comments
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?
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.
Oh wow, I think that worked!
Will do more testing and report back.
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.
I have added documentation for this work around here https://github.com/meltwater/drone-convert-pathschanged/tree/9168edcd073b54e000ba4f8daad1e3e6d5afc7d9#yaml-anchors
Closing this out
@jimsheldon thank you for following up and documenting the workaround.