-
-
Notifications
You must be signed in to change notification settings - Fork 521
Prefer map syntax for services #5988
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
Draft
6543
wants to merge
14
commits into
woodpecker-ci:main
Choose a base branch
from
6543-forks:types.services.serialize.as.map
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+116
−14
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e61d60f
workflow config: prefer map syntax for services
6543 afd6971
linter: cover more services config options
6543 93e6d21
docs: fix environment syntax
6543 38140a7
prettier
6543 1b1a176
more tests for re-serialize
6543 80c565a
linter: cover more
6543 bad19ab
fix pre-commit
6543 1b088bb
Apply suggestions from code review
6543 06ffd81
Merge branch 'main' into types.services.serialize.as.map
6543 77280d9
aww
6543 058d959
check duplicates
6543 8241902
fix
6543 f3f4cc4
Merge branch 'main' into types.services.serialize.as.map
6543 ea2f507
Merge branch 'main' into types.services.serialize.as.map
6543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright 2026 Woodpecker Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package types | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // ContainerMap contains collection of containers. | ||
| type ContainerMap struct { | ||
| ContainerMap map[string]*Container | ||
| Duplicated []string | ||
| } | ||
|
|
||
| // UnmarshalYAML implements the Unmarshaler interface. | ||
| func (c *ContainerMap) UnmarshalYAML(value *yaml.Node) error { | ||
| c.ContainerMap = make(map[string]*Container, len(value.Content)/2+1) | ||
| switch value.Kind { | ||
| // We support maps ... | ||
| case yaml.MappingNode: | ||
| for i, n := range value.Content { | ||
| if i%2 == 1 { | ||
| container := &Container{} | ||
| if err := n.Decode(container); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // service name is host name so we set it as name | ||
| container.Name = fmt.Sprintf("%v", value.Content[i-1].Value) | ||
| if container.Name == "" { | ||
| return fmt.Errorf("container map does not allow empty key item") | ||
| } | ||
|
|
||
| c.ContainerMap[container.Name] = container | ||
| } | ||
| } | ||
|
|
||
| // ... and lists | ||
| case yaml.SequenceNode: | ||
| for i, n := range value.Content { | ||
| container := &Container{} | ||
| if err := n.Decode(container); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if container.Name == "" { | ||
| container.Name = fmt.Sprintf("step-%d", i) | ||
| } | ||
|
|
||
| if _, exist := c.ContainerMap[container.Name]; exist { | ||
| c.Duplicated = append(c.Duplicated, container.Name) | ||
| } else { | ||
| c.ContainerMap[container.Name] = container | ||
| } | ||
| } | ||
|
|
||
| default: | ||
| return fmt.Errorf("yaml node type[%d]: '%s' not supported", value.Kind, value.Tag) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // MarshalYAML implements custom Yaml marshaling. | ||
| func (c ContainerMap) MarshalYAML() (any, error) { | ||
| // we just relay on the map key for names | ||
| for _, v := range c.ContainerMap { | ||
| v.Name = "" | ||
| } | ||
| return c.ContainerMap, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to put this into the parsing code? I think the linter should check separately for duplicated entries and for parsing just use the
ContainerList