config

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForEachPipelineStep added in v0.4.0

func ForEachPipelineStep(cfg *melange.Configuration, fn func(step *melange.Pipeline))

ForEachPipelineStep calls fn for every step of the top-level pipeline, then of each subpackage's pipeline, in order.

Types

type BumpStep added in v0.3.0

type BumpStep struct {
	Index     int      // pipeline index
	Action    string   // "bump" or "go/bump"
	Language  string   // parsed with.language entry ("" when absent)
	GoVersion string   // parsed with.go-version entry ("" when absent)
	NoTidy    bool     // with.tidy is literally false (the input defaults to true)
	Work      bool     // with.work is literally true (go/bump only: gobump's go.work mode)
	Modroots  []string // parsed with.modroot entries; defaults to ["."] when absent
	Deps      []string // parsed with.deps entries ("module@version")
	Replaces  []string // parsed with.replaces entries ("old=new@version")
}

BumpStep describes a bump or go/bump pipeline step and its parsed with-fields.

func (BumpStep) EffectiveLanguage added in v0.4.0

func (s BumpStep) EffectiveLanguage() string

EffectiveLanguage is the language the step bumps: its with.language, or "go" when absent (legacy go/bump and language-less bump steps are Go).

type BumpStepSpec added in v0.3.0

type BumpStepSpec struct {
	Action   string   // "bump" or "go/bump"
	Language string   // omitted from YAML when empty
	Modroots []string // omitted when just ["."]; block scalar list otherwise
	Deps     []string // block scalar list
	Replaces []string // block scalar list
}

BumpStepSpec describes a bump/go-bump pipeline step to insert via InsertBumpPipelineStep. String/slice fields that are empty (or, for Modroots, just ["."] - the pipeline's own default) are omitted from the emitted YAML entirely rather than written as empty/default values.

type GoPackagePin added in v0.3.0

type GoPackagePin struct {
	Path       string // goccy yaml path, e.g. "$.pipeline[3].with.go-package" or "$.subpackages[2].pipeline[0].with.go-package"
	Subpackage string // subpackage name for messages; "" for top-level
	Value      string // raw string value (possibly templated)
	Uses       string // the step's uses: value ("go/build" or "go/install")
	Modroot    string // raw with.modroot (possibly templated); "." when absent - go/build only, go/install has none
}

GoPackagePin locates one go/build|go/install step's with.go-package value.

type GoToolchainStep added in v0.4.0

type GoToolchainStep struct {
	GoPackagePin
	WithPath string
	HasPin   bool
}

GoToolchainStep is one go/build|go/install step with a with block, pinned (HasPin, GoPackagePin.Value set) or not. WithPath addresses its with block (e.g. "$.subpackages[1].pipeline[0].with"), for SpliceIntoWith.

type Loader

type Loader struct{}

Loader handles loading and saving melange configurations while preserving YAML structure

func NewLoader

func NewLoader() *Loader

NewLoader creates a new config loader

func (*Loader) ClonePipelineStepAfter added in v0.4.0

func (l *Loader) ClonePipelineStepAfter(yamlContent []byte, pipelineIndex int, blankLineBetweenSteps bool) ([]byte, error)

ClonePipelineStepAfter duplicates the source text of top-level pipeline step pipelineIndex (from its "- " line to its last content line, comments inside the step included) as a new step directly after it, separated by a blank line when blankLineBetweenSteps. The clone is at pipelineIndex+1.

func (*Loader) EnvironmentPackages added in v0.4.0

func (l *Loader) EnvironmentPackages(yamlContent []byte) ([]string, error)

EnvironmentPackages returns the top-level environment.contents.packages entries (strings only), in order.

func (*Loader) FindBumpSteps added in v0.3.0

func (l *Loader) FindBumpSteps(yamlContent []byte) ([]BumpStep, error)

FindBumpSteps finds all bump and go/bump pipeline steps, in pipeline order, with their modroot and deps fields parsed.

func (*Loader) FindGoPackagePins added in v0.3.0

func (l *Loader) FindGoPackagePins(yamlContent []byte) ([]GoPackagePin, error)

FindGoPackagePins walks the top-level pipeline and every subpackage's pipeline for go/build and go/install steps carrying a string with.go-package pin, returning one GoPackagePin per pin found - in top-level-then-subpackage, then pipeline order. Steps without a go-package field are not returned; there's nothing to edit. Each pin's Path is a goccy yaml path directly usable with UpdateField to rewrite it in place.

func (*Loader) FindGoToolchainSteps added in v0.4.0

func (l *Loader) FindGoToolchainSteps(yamlContent []byte) ([]GoToolchainStep, error)

FindGoToolchainSteps walks the top-level pipeline and every subpackage's pipeline for go/build and go/install steps that have a with block, in top-level-then-subpackage, then pipeline order. A step whose go-package is not a string (absent, null, numeric) has HasPin false.

func (*Loader) FindPipelinesByUse

func (l *Loader) FindPipelinesByUse(yamlContent []byte, useType string) ([]int, error)

FindPipelinesByUse finds pipeline indices that use a specific pipeline type

func (*Loader) GetBumpDeps added in v0.4.0

func (l *Loader) GetBumpDeps(yamlContent []byte, pipelineIndex int) ([]string, error)

GetBumpDeps extracts the deps field from a bump or go/bump pipeline

func (*Loader) GetBumpModroots added in v0.3.0

func (l *Loader) GetBumpModroots(yamlContent []byte, pipelineIndex int) ([]string, error)

GetBumpModroots extracts the modroot field from a bump/go-bump pipeline step. When the field is absent, it defaults to ["."], matching the pipeline's own default (the current directory).

func (*Loader) GetBumpReplaces added in v0.3.0

func (l *Loader) GetBumpReplaces(yamlContent []byte, pipelineIndex int) ([]string, error)

GetBumpReplaces extracts the replaces field ("old=new@version" entries) from a bump or go/bump pipeline step.

func (*Loader) GetPackageInfo

func (l *Loader) GetPackageInfo(yamlContent []byte) (name, version string, epoch int64, err error)

GetPackageInfo extracts package name and version from YAML content

func (*Loader) GetPipelineWithField

func (l *Loader) GetPipelineWithField(yamlContent []byte, pipelineIndex int) (map[string]string, error)

GetPipelineWithField gets the with field map for a specific pipeline.

It reads the with block off the comment-preserving AST (rather than via yaml.Unmarshal) so that non-string scalars surface their raw token text instead of being dropped or coerced. An UNQUOTED "go-version: 1.30" parses as a YAML float; unmarshalling would either drop it (map[string]string only keeps string values) or, worse, coerce it through float64 to "1.3" - a 27-minor corruption of a pinned toolchain. Reading the AST token keeps the text exactly as written ("1.30"). Values with no meaningful scalar text (null, sequences, nested mappings) are skipped, matching the prior reader.

func (*Loader) HasBlankLinesBetweenPipelineSteps added in v0.3.0

func (l *Loader) HasBlankLinesBetweenPipelineSteps(yamlContent []byte) bool

HasBlankLinesBetweenPipelineSteps reports whether the YAML separates pipeline steps with blank lines. Callers that remove steps before inserting must capture this from the ORIGINAL content - a stripped pipeline may no longer have two adjacent steps to detect the convention from.

func (*Loader) IncrementEpoch

func (l *Loader) IncrementEpoch(yamlContent []byte) ([]byte, error)

IncrementEpoch increments the epoch field by 1

func (*Loader) InsertBumpPipelineStep added in v0.3.0

func (l *Loader) InsertBumpPipelineStep(yamlContent []byte, pipelineIndex int, spec BumpStepSpec, blankLineBetweenSteps bool) ([]byte, error)

InsertBumpPipelineStep inserts a bump or go/bump step with block-scalar deps and replaces lists and, for multi-root bumps, a block-scalar modroot list. blankLineBetweenSteps says whether the file's convention separates pipeline steps with a blank line (see HasBlankLinesBetweenPipelineSteps) - it's the caller's to supply because yamlContent may already have had steps removed, leaving nothing to detect the original convention from.

func (*Loader) InsertPipelineStep

func (l *Loader) InsertPipelineStep(yamlContent []byte, pipelineIndex int, pipelineStep map[string]any) ([]byte, error)

InsertPipelineStep inserts a new pipeline step at the specified index

func (*Loader) LoadWithPreservation

func (l *Loader) LoadWithPreservation(ctx context.Context, path string) (*config.Configuration, []byte, error)

LoadWithPreservation loads a melange config while preserving YAML structure and comments

func (*Loader) RemovePipelineStep

func (l *Loader) RemovePipelineStep(yamlContent []byte, pipelineIndex int) ([]byte, error)

RemovePipelineStep removes a single pipeline step by index while preserving formatting

func (*Loader) RemovePipelineWithField added in v0.3.0

func (l *Loader) RemovePipelineWithField(yamlContent []byte, pipelineIndex int, field string) ([]byte, error)

RemovePipelineWithField removes a single field from a pipeline step's with map, preserving the rest of the step and surrounding formatting.

func (*Loader) RemovePipelineWithFieldLines added in v0.4.0

func (l *Loader) RemovePipelineWithFieldLines(yamlContent []byte, pipelineIndex int, field string) ([]byte, error)

RemovePipelineWithFieldLines removes a top-level pipeline step's with.<field> from the source text: the key's own lines (an inline comment included) and the comment lines directly above it at the key's indentation, which describe it. Every other byte is preserved. Absent field: unchanged.

func (*Loader) Save

func (l *Loader) Save(path string, content []byte, backupSuffix string) error

Save saves the updated YAML content to file, optionally creating a backup backupSuffix: suffix for backup files (empty = no backup) Returns error if save failed, nil if no changes needed or save successful

func (*Loader) SaveWithBackup

func (l *Loader) SaveWithBackup(path string, content []byte) error

SaveWithBackup saves the updated YAML content to file with backup

func (*Loader) SetBumpModroots added in v0.4.0

func (l *Loader) SetBumpModroots(yamlContent []byte, pipelineIndex int, roots []string) ([]byte, error)

SetBumpModroots sets a top-level bump step's with.modroot to roots: a single "." removes the field (the pipeline default), a single other root is a plain scalar, several roots a block scalar list.

func (*Loader) SetEpoch

func (l *Loader) SetEpoch(yamlContent []byte, newEpoch int64) ([]byte, error)

SetEpoch sets the epoch field to a specific value

func (*Loader) SetEpochWithComment added in v0.3.0

func (l *Loader) SetEpochWithComment(yamlContent []byte, newEpoch int64, comment string) ([]byte, error)

SetEpochWithComment sets the epoch field and attaches an inline intent comment on the same line (`epoch: 2 # <comment>`), replacing any existing inline comment there. The value write goes through the same ReplaceWithReader path as SetEpoch - which discards the old value node and its inline comment - so the comment is attached to the freshly written value node afterwards, within the same parse/render cycle. An empty comment behaves exactly like SetEpoch.

func (*Loader) SetPipelineUses added in v0.4.0

func (l *Loader) SetPipelineUses(yamlContent []byte, pipelineIndex int, uses string) ([]byte, error)

SetPipelineUses rewrites a top-level pipeline step's `uses:` value in the source text (e.g. go/bump -> bump), leaving every other byte - including an inline comment on that line - untouched. The value must be a plain or quoted single-line scalar.

func (*Loader) SpliceIntoWith added in v0.4.0

func (l *Loader) SpliceIntoWith(yamlContent []byte, withPath string, insertedLines []string) ([]byte, error)

SpliceIntoWith inserts insertedLines (already relative to the with block's own indentation - the first line typically "field: ..." and any further lines its continuation) after the last existing line of the with block at withPath (e.g. "$.subpackages[0].pipeline[2].with"), re-indenting each to match the block's first key. goccy's renderer does not reliably emit AST nodes appended to an existing mapping, so this locates the insertion point via the AST and splices correctly indented lines into the source text directly instead; every other byte is preserved.

func (*Loader) UpdateBumpStep added in v0.4.0

func (l *Loader) UpdateBumpStep(yamlContent []byte, pipelineIndex int, deps, replaces []string, goVersion string) ([]byte, error)

UpdateBumpStep updates a bump/go-bump step's deps, replaces and go-version fields in place. Both deps and replaces empty removes the whole step; deps empty with replaces present keeps the step (gobump accepts a replaces-only invocation) and removes just the deps field; an empty replaces list removes just that field. goVersion == "" leaves any existing go-version field untouched (it is never removed by this call); a non-empty goVersion upserts go-version as a quoted scalar so it can never round-trip as a YAML float.

func (*Loader) UpdateField

func (l *Loader) UpdateField(yamlContent []byte, path, newValue string) ([]byte, error)

UpdateField updates a specific field in the YAML while preserving structure

func (*Loader) UpdateFieldAsQuotedString

func (l *Loader) UpdateFieldAsQuotedString(yamlContent []byte, path string, newValue string) ([]byte, error)

UpdateFieldAsQuotedString updates a field with a double-quoted string value This is essential for fields like package.version where values like "1.0" must be rendered as strings to prevent YAML from interpreting them as numbers

func (*Loader) UpdateFieldWithBlockScalar

func (l *Loader) UpdateFieldWithBlockScalar(yamlContent []byte, path string, newValue string) ([]byte, error)

UpdateFieldWithBlockScalar updates a field to use block scalar format (|-)

func (*Loader) UpdateIntField

func (l *Loader) UpdateIntField(yamlContent []byte, path string, newValue int64) ([]byte, error)

UpdateIntField updates an integer field in the YAML

func (*Loader) UpdatePackageVersion

func (l *Loader) UpdatePackageVersion(yamlContent []byte, newVersion string) ([]byte, error)

UpdatePackageVersion updates the package version (epoch handling moved to EpochApplier)

func (*Loader) UpdatePipelineField

func (l *Loader) UpdatePipelineField(yamlContent []byte, pipelineIndex int, field, newValue string) ([]byte, error)

UpdatePipelineField updates a field within a specific pipeline

func (*Loader) UpsertPipelineWithBlockScalar added in v0.3.0

func (l *Loader) UpsertPipelineWithBlockScalar(yamlContent []byte, pipelineIndex int, field, value string) ([]byte, error)

UpsertPipelineWithBlockScalar sets a pipeline step's with.<field> to a block scalar (|-) value, creating the field when it doesn't exist yet. UpdateFieldWithBlockScalar alone can't create fields (yamlPath. ReplaceWithNode fails on a missing path), and goccy's renderer does not reliably emit AST nodes appended to an existing mapping - so the append case locates the end of the with block via the AST and splices correctly indented lines into the source text directly.

func (*Loader) UpsertPipelineWithQuotedString added in v0.3.0

func (l *Loader) UpsertPipelineWithQuotedString(yamlContent []byte, pipelineIndex int, field, value string) ([]byte, error)

UpsertPipelineWithQuotedString sets a pipeline step's with.<field> to a double-quoted scalar value, creating the field when it doesn't exist yet. Modeled on UpsertPipelineWithBlockScalar: yamlPath.ReplaceWithNode is a silent no-op on a missing path, so field existence is probed first via the type-blind pipelineWithHasField; when the field already exists, UpdateFieldAsQuotedString replaces it in place, otherwise the `field: "value"` line is spliced into the source text directly, since goccy's renderer does not reliably emit AST nodes appended to an existing mapping. Both paths embed value literally between double quotes (the replace path via createQuotedStringNode's rendered Origin, the splice path in the text itself), so value is validated up front either way.

func (*Loader) ValidateUpdatedConfig

func (l *Loader) ValidateUpdatedConfig(content []byte, tempPath string) error

ValidateUpdatedConfig validates that the updated YAML is still valid

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer provides variable rendering for melange configurations It builds a complete variable context and can render strings or entire configs

func NewRenderer

func NewRenderer(cfg *melange.Configuration) (*Renderer, error)

NewRenderer creates a new renderer for the given melange configuration

func (*Renderer) RenderOrRaw added in v0.4.0

func (r *Renderer) RenderOrRaw(ctx context.Context, value string) string

RenderOrRaw renders a value leniently: a value with no template expression, a nil renderer, or a render error all keep the raw value (the error is logged at debug). Callers that must know whether a value rendered completely check the result for a leftover "${{".

func (*Renderer) RenderString

func (r *Renderer) RenderString(template string) (string, error)

RenderString renders a template string with full variable substitution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL