Skip to content

Commit 63d5c40

Browse files
6543qwerty287
andauthored
Deprecate "platform" filter in favour of "labels" (woodpecker-ci#2181)
Co-authored-by: qwerty287 <[email protected]>
1 parent 71666f0 commit 63d5c40

File tree

9 files changed

+41
-30
lines changed

9 files changed

+41
-30
lines changed

docs/docs/20-usage/20-pipeline-syntax.md

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -603,26 +603,6 @@ Woodpecker has integrated support for matrix builds. Woodpecker executes a separ
603603

604604
For more details check the [matrix build docs](./30-matrix-workflows.md).
605605

606-
## `platform`
607-
608-
To configure your pipeline to only be executed on an agent with a specific platform, you can use the `platform` key.
609-
Have a look at the official [go docs](https://go.dev/doc/install/source) for the available platforms. The syntax of the platform is `GOOS/GOARCH` like `linux/arm64` or `linux/amd64`.
610-
611-
Example:
612-
613-
Assuming we have two agents, one `arm` and one `amd64`. Previously this pipeline would have executed on **either agent**, as Woodpecker is not fussy about where it runs the pipelines. By setting the following option it will only be executed on an agent with the platform `linux/arm64`.
614-
615-
```diff
616-
+platform: linux/arm64
617-
618-
steps:
619-
build:
620-
image: golang
621-
commands:
622-
- go build
623-
- go test
624-
```
625-
626606
## `labels`
627607

628608
You can set labels for your pipeline to select an agent to execute the pipeline on. An agent will pick up and run a pipeline when **every** label assigned to a pipeline matches the agents labels.
@@ -648,6 +628,23 @@ steps:
648628
- go test
649629
```
650630
631+
### Filter by platform
632+
633+
To configure your pipeline to only be executed on an agent with a specific platform, you can use the `platform` key.
634+
Have a look at the official [go docs](https://go.dev/doc/install/source) for the available platforms. The syntax of the platform is `GOOS/GOARCH` like `linux/arm64` or `linux/amd64`.
635+
636+
Example:
637+
638+
Assuming we have two agents, one `linux/arm` and one `linux/amd64`. Previously this pipeline would have executed on **either agent**, as Woodpecker is not fussy about where it runs the pipelines. By setting the following option it will only be executed on an agent with the platform `linux/arm64`.
639+
640+
```diff
641+
+labels:
642+
+ platform: linux/arm64
643+
644+
steps:
645+
[...]
646+
```
647+
651648
## `variables`
652649

653650
Woodpecker supports [YAML anchors & aliases](https://yaml.org/spec/1.2.2/#3222-anchors-and-aliases) in the pipeline configuration. These can be used as variables to not repeat yourself.

docs/docs/91-migrations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Some versions need some changes to the server configuration or the pipeline conf
77
- Drop deprecated `CI_BUILD_*`, `CI_PREV_BUILD_*`, `CI_JOB_*`, `*_LINK`, `CI_SYSTEM_ARCH`, `CI_REPO_REMOTE` built-in environment variables
88
- Drop deprecated `pipeline:` keyword for steps in yaml config
99
- Drop deprecated `branches:` keyword for global branch filter
10+
- Deprecate `platform:` filter in favor of `labels:`, [read more](./20-usage/20-pipeline-syntax.md#filter-by-platform)
1011

1112
## 1.0.0
1213

docs/versioned_docs/version-1.0/20-usage/20-pipeline-syntax.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ For more details check the [matrix build docs](./30-matrix-workflows.md).
605605

606606
## `platform`
607607

608+
:::warning
609+
will be deprecated with v1.1.0 in favor of labels.
610+
:::
611+
608612
To configure your pipeline to only be executed on an agent with a specific platform, you can use the `platform` key.
609613
Have a look at the official [go docs](https://go.dev/doc/install/source) for the available platforms. The syntax of the platform is `GOOS/GOARCH` like `linux/arm64` or `linux/amd64`.
610614

pipeline/frontend/yaml/parse.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"codeberg.org/6543/xyaml"
77

88
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
9+
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base"
910
)
1011

1112
// ParseBytes parses the configuration from bytes b.
@@ -26,6 +27,17 @@ func ParseBytes(b []byte) (*types.Workflow, error) {
2627
return nil, fmt.Errorf("\"pipeline:\" got removed, user \"steps:\"")
2728
}
2829

30+
// support deprecated platform filter
31+
if out.PlatformDontUseIt != "" {
32+
if out.Labels == nil {
33+
out.Labels = make(base.SliceOrMap)
34+
}
35+
if _, set := out.Labels["platform"]; !set {
36+
out.Labels["platform"] = out.PlatformDontUseIt
37+
}
38+
out.PlatformDontUseIt = ""
39+
}
40+
2941
return out, nil
3042
}
3143

pipeline/frontend/yaml/parse_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,8 @@ func TestParse(t *testing.T) {
125125
}
126126

127127
func TestParseLegacy(t *testing.T) {
128-
// adjust with https://github.com/woodpecker-ci/woodpecker/pull/2181
129128
sampleYamlPipelineLegacy := `
130129
platform: linux/amd64
131-
labels:
132-
platform: linux/arm64
133130
134131
steps:
135132
say hello:
@@ -138,9 +135,9 @@ steps:
138135
`
139136

140137
sampleYamlPipelineLegacyIgnore := `
141-
platform: linux/amd64
138+
platform: windows/amd64
142139
labels:
143-
platform: linux/arm64
140+
platform: linux/amd64
144141
145142
steps:
146143
say hello:

pipeline/frontend/yaml/types/base/map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
// SliceOrMap represents a slice or a map of strings.
9+
// SliceOrMap represents a map of strings, string slice are converted into a map
1010
type SliceOrMap map[string]string
1111

1212
// UnmarshalYAML implements the Unmarshaler interface.

pipeline/frontend/yaml/types/workflow.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ type (
99
// Workflow defines a workflow configuration.
1010
Workflow struct {
1111
When constraint.When `yaml:"when,omitempty"`
12-
Platform string `yaml:"platform,omitempty"`
1312
Workspace Workspace `yaml:"workspace,omitempty"`
1413
Clone ContainerList `yaml:"clone,omitempty"`
1514
Steps ContainerList `yaml:"steps,omitempty"`
@@ -18,10 +17,14 @@ type (
1817
DependsOn []string `yaml:"depends_on,omitempty"`
1918
RunsOn []string `yaml:"runs_on,omitempty"`
2019
SkipClone bool `yaml:"skip_clone"`
20+
2121
// Undocumented
2222
Cache base.StringOrSlice `yaml:"cache,omitempty"`
2323
Networks WorkflowNetworks `yaml:"networks,omitempty"`
2424
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`
25+
26+
// Deprecated
27+
PlatformDontUseIt string `yaml:"platform,omitempty"` // TODO: remove after v1.2.x version
2528
// Deprecated
2629
BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove after v1.1.x version
2730
// Deprecated

pipeline/stepBuilder.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ type StepBuilder struct {
5454

5555
type Item struct {
5656
Workflow *model.Workflow
57-
Platform string
5857
Labels map[string]string
5958
DependsOn []string
6059
RunsOn []string
@@ -171,7 +170,6 @@ func (b *StepBuilder) genItemForWorkflow(workflow *model.Workflow, axis matrix.A
171170
Labels: parsed.Labels,
172171
DependsOn: parsed.DependsOn,
173172
RunsOn: parsed.RunsOn,
174-
Platform: parsed.Platform,
175173
}
176174
if item.Labels == nil {
177175
item.Labels = map[string]string{}

server/pipeline/queue.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ func queuePipeline(repo *model.Repo, pipelineItems []*pipeline.Item) error {
3737
for k, v := range item.Labels {
3838
task.Labels[k] = v
3939
}
40-
task.Labels["platform"] = item.Platform
4140
task.Labels["repo"] = repo.FullName
4241
task.Dependencies = taskIds(item.DependsOn, pipelineItems)
4342
task.RunOn = item.RunsOn

0 commit comments

Comments
 (0)