debian-forge-composer/internal/osbuild/osbuild.go
Tomáš Hozza acfceb74b2 osbuild: add variadic version of Pipeline.AddStage() method
This will allow to conveniently add multiple stages to the pipeline at
once, which is useful if a generator function wrapping some
functionality generates more than one `Stage`.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2023-02-22 12:17:36 +01:00

47 lines
1.4 KiB
Go

// Package osbuild provides primitives for representing and (un)marshalling
// OSBuild (schema v2) types.
package osbuild
// A Manifest represents an OSBuild source and pipeline manifest
type Manifest struct {
Version string `json:"version"`
Pipelines []Pipeline `json:"pipelines"`
Sources Sources `json:"sources"`
}
// A Pipeline represents an OSBuild pipeline
type Pipeline struct {
Name string `json:"name,omitempty"`
// The build environment which can run this pipeline
Build string `json:"build,omitempty"`
Runner string `json:"runner,omitempty"`
// Sequence of stages that produce the filesystem tree, which is the
// payload of the produced image.
Stages []*Stage `json:"stages,omitempty"`
}
// SetBuild sets the pipeline and runner for generating the build environment
// for a pipeline.
func (p *Pipeline) SetBuild(build string) {
p.Build = build
}
// AddStage appends a stage to the list of stages of a pipeline. The stages
// will be executed in the order they are appended.
// If the argument is nil, it is not added.
func (p *Pipeline) AddStage(stage *Stage) {
if stage != nil {
p.Stages = append(p.Stages, stage)
}
}
// AddStages appends multiple stages to the list of stages of a pipeline. The
// stages will be executed in the order they are appended.
// If the argument is nil, it is not added.
func (p *Pipeline) AddStages(stages ...*Stage) {
for _, stage := range stages {
p.AddStage(stage)
}
}