Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(yaml): support collapsing of multiple anchor keys in step #391

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ecrupper
Copy link
Contributor

#386 introduced a regression(?) where the following step configurations were no longer valid:

  - name: alpha
    <<: *alpine-image
    <<: *event-push
    commands:
      - echo alpha

go-yaml asserts that the proper usage of multiple anchors in a single map is to list them:

  - name: beta
    <<: [ *alpine-image, *event-push ]
    commands:
      - echo beta

Given how many current users leverage the first configuration, this PR aims to support that format even with the upgrade to go-yaml v3.

@ecrupper ecrupper requested a review from a team as a code owner September 24, 2024 17:50
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 4 lines in your changes missing coverage. Please review.

Project coverage is 95.99%. Comparing base (2d20d54) to head (af6cf50).

Files with missing lines Patch % Lines
yaml/service.go 88.88% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #391      +/-   ##
==========================================
- Coverage   96.02%   95.99%   -0.04%     
==========================================
  Files          69       69              
  Lines        5382     5440      +58     
==========================================
+ Hits         5168     5222      +54     
- Misses        138      140       +2     
- Partials       76       78       +2     
Files with missing lines Coverage Δ
yaml/step.go 97.29% <100.00%> (+1.74%) ⬆️
yaml/service.go 88.23% <88.88%> (-1.51%) ⬇️

Copy link
Member

@wass3rw3rk wass3rw3rk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we essentially have same code in two places? should we create a helper function?

value := tmpService.Content[i+1]

// check if key is an anchor reference
if strings.EqualFold(key.Value, "<<") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EqualFold() seems unnecessary here (and in the other location).

Copy link
Contributor

@plyr4 plyr4 Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the equalfold is necessary you could use a switch case comparison for some extra speed

switch key.Value {
case "<<":

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it's a simple key.Value == "<<", no? there are no casing concerns.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, switch is faster tho (jump tables) but its negligible (with over 1 billion iterations it measures like 3% faster)

// iterate through map contents (key, value)
for i := 0; i < len(tmpService.Content); i += 2 {
key := tmpService.Content[i]
value := tmpService.Content[i+1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im assuming this cant panic? i couldnt get it to be nil while testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the same spirit, the length is guaranteed to be an even number? (i think so?) :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I believe the map type check will always make this an even length

@wass3rw3rk
Copy link
Member

changing this to draft for now until we revisit

@wass3rw3rk wass3rw3rk marked this pull request as draft September 26, 2024 19:18
wass3rw3rk added a commit to go-vela/server that referenced this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants