Skip to content

Commit

Permalink
Deprecate "platform" filter in favour of "labels" (#2181)
Browse files Browse the repository at this point in the history
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
  • Loading branch information
6543 and qwerty287 authored Aug 9, 2023
1 parent 71666f0 commit 63d5c40
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
37 changes: 17 additions & 20 deletions docs/docs/20-usage/20-pipeline-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
12 changes: 12 additions & 0 deletions pipeline/frontend/yaml/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand Down
7 changes: 2 additions & 5 deletions pipeline/frontend/yaml/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -138,9 +135,9 @@ steps:
`

sampleYamlPipelineLegacyIgnore := `
platform: linux/amd64
platform: windows/amd64
labels:
platform: linux/arm64
platform: linux/amd64
steps:
say hello:
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/types/base/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion pipeline/frontend/yaml/types/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pipeline/stepBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type StepBuilder struct {

type Item struct {
Workflow *model.Workflow
Platform string
Labels map[string]string
DependsOn []string
RunsOn []string
Expand Down Expand Up @@ -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{}
Expand Down
1 change: 0 additions & 1 deletion server/pipeline/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63d5c40

Please sign in to comment.