Deprecate "platform" filter in favour of "labels" (#2181)

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
6543 2023-08-09 16:09:44 +02:00 committed by GitHub
parent 71666f0500
commit 63d5c40afd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 30 deletions

View file

@ -603,26 +603,6 @@ Woodpecker has integrated support for matrix builds. Woodpecker executes a separ
For more details check the [matrix build docs](./30-matrix-workflows.md).
## `platform`
To configure your pipeline to only be executed on an agent with a specific platform, you can use the `platform` key.
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`.
Example:
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`.
```diff
+platform: linux/arm64
steps:
build:
image: golang
commands:
- go build
- go test
```
## `labels`
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:
- go test
```
### Filter by platform
To configure your pipeline to only be executed on an agent with a specific platform, you can use the `platform` key.
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`.
Example:
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`.
```diff
+labels:
+ platform: linux/arm64
steps:
[...]
```
## `variables`
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.

View file

@ -7,6 +7,7 @@ Some versions need some changes to the server configuration or the pipeline conf
- Drop deprecated `CI_BUILD_*`, `CI_PREV_BUILD_*`, `CI_JOB_*`, `*_LINK`, `CI_SYSTEM_ARCH`, `CI_REPO_REMOTE` built-in environment variables
- Drop deprecated `pipeline:` keyword for steps in yaml config
- Drop deprecated `branches:` keyword for global branch filter
- Deprecate `platform:` filter in favor of `labels:`, [read more](./20-usage/20-pipeline-syntax.md#filter-by-platform)
## 1.0.0

View file

@ -605,6 +605,10 @@ For more details check the [matrix build docs](./30-matrix-workflows.md).
## `platform`
:::warning
will be deprecated with v1.1.0 in favor of labels.
:::
To configure your pipeline to only be executed on an agent with a specific platform, you can use the `platform` key.
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`.

View file

@ -6,6 +6,7 @@ import (
"codeberg.org/6543/xyaml"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types"
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/types/base"
)
// ParseBytes parses the configuration from bytes b.
@ -26,6 +27,17 @@ func ParseBytes(b []byte) (*types.Workflow, error) {
return nil, fmt.Errorf("\"pipeline:\" got removed, user \"steps:\"")
}
// support deprecated platform filter
if out.PlatformDontUseIt != "" {
if out.Labels == nil {
out.Labels = make(base.SliceOrMap)
}
if _, set := out.Labels["platform"]; !set {
out.Labels["platform"] = out.PlatformDontUseIt
}
out.PlatformDontUseIt = ""
}
return out, nil
}

View file

@ -125,11 +125,8 @@ func TestParse(t *testing.T) {
}
func TestParseLegacy(t *testing.T) {
// adjust with https://github.com/woodpecker-ci/woodpecker/pull/2181
sampleYamlPipelineLegacy := `
platform: linux/amd64
labels:
platform: linux/arm64
steps:
say hello:
@ -138,9 +135,9 @@ steps:
`
sampleYamlPipelineLegacyIgnore := `
platform: linux/amd64
platform: windows/amd64
labels:
platform: linux/arm64
platform: linux/amd64
steps:
say hello:

View file

@ -6,7 +6,7 @@ import (
"strings"
)
// SliceOrMap represents a slice or a map of strings.
// SliceOrMap represents a map of strings, string slice are converted into a map
type SliceOrMap map[string]string
// UnmarshalYAML implements the Unmarshaler interface.

View file

@ -9,7 +9,6 @@ type (
// Workflow defines a workflow configuration.
Workflow struct {
When constraint.When `yaml:"when,omitempty"`
Platform string `yaml:"platform,omitempty"`
Workspace Workspace `yaml:"workspace,omitempty"`
Clone ContainerList `yaml:"clone,omitempty"`
Steps ContainerList `yaml:"steps,omitempty"`
@ -18,10 +17,14 @@ type (
DependsOn []string `yaml:"depends_on,omitempty"`
RunsOn []string `yaml:"runs_on,omitempty"`
SkipClone bool `yaml:"skip_clone"`
// Undocumented
Cache base.StringOrSlice `yaml:"cache,omitempty"`
Networks WorkflowNetworks `yaml:"networks,omitempty"`
Volumes WorkflowVolumes `yaml:"volumes,omitempty"`
// Deprecated
PlatformDontUseIt string `yaml:"platform,omitempty"` // TODO: remove after v1.2.x version
// Deprecated
BranchesDontUseIt *constraint.List `yaml:"branches,omitempty"` // TODO: remove after v1.1.x version
// Deprecated

View file

@ -54,7 +54,6 @@ type StepBuilder struct {
type Item struct {
Workflow *model.Workflow
Platform string
Labels map[string]string
DependsOn []string
RunsOn []string
@ -171,7 +170,6 @@ func (b *StepBuilder) genItemForWorkflow(workflow *model.Workflow, axis matrix.A
Labels: parsed.Labels,
DependsOn: parsed.DependsOn,
RunsOn: parsed.RunsOn,
Platform: parsed.Platform,
}
if item.Labels == nil {
item.Labels = map[string]string{}

View file

@ -37,7 +37,6 @@ func queuePipeline(repo *model.Repo, pipelineItems []*pipeline.Item) error {
for k, v := range item.Labels {
task.Labels[k] = v
}
task.Labels["platform"] = item.Platform
task.Labels["repo"] = repo.FullName
task.Dependencies = taskIds(item.DependsOn, pipelineItems)
task.RunOn = item.RunsOn