Skip to content

Commit

Permalink
melange bump: move the reset / bump epoch logic up and inline version
Browse files Browse the repository at this point in the history
Signed-off-by: James Rawlings <[email protected]>
  • Loading branch information
rawlingsj committed Oct 16, 2023
1 parent 9d19228 commit ad2acc0
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions pkg/renovate/bump/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func New(opts ...Option) renovate.Renovator {
return func(ctx context.Context, rc *renovate.RenovationContext) error {
log.Printf("attempting to bump version to %s", bcfg.TargetVersion)

// Find the package.version node first and change it.
packageNode, err := renovate.NodeFromMapping(rc.Configuration.Root().Content[0], "package")
if err != nil {
return err
Expand All @@ -85,24 +84,13 @@ func New(opts ...Option) renovate.Renovator {
return err
}

resetEpoch := true
if versionNode.Value == bcfg.TargetVersion {
resetEpoch = false
}
versionNode.Value = bcfg.TargetVersion
versionNode.Style = yaml.FlowStyle
versionNode.Tag = "!!str"

// Update the variable mapping with the target version
rc.Vars[config.SubstitutionPackageVersion] = bcfg.TargetVersion

// if the version is changing then reset the epoch to 0 else if the version is the same then increment the epoch by 1
epochNode, err := renovate.NodeFromMapping(packageNode, "epoch")
if err != nil {
return err
}

// if the version is changing then reset the epoch to 0 else if the version is the same then increment the epoch by 1
if resetEpoch {
if versionNode.Value != bcfg.TargetVersion {
epochNode.Value = "0"
} else {
epoch, err := strconv.Atoi(epochNode.Value)
Expand All @@ -112,6 +100,11 @@ func New(opts ...Option) renovate.Renovator {
epochNode.Value = fmt.Sprintf("%d", epoch+1)
}

versionNode.Value = bcfg.TargetVersion
versionNode.Style = yaml.FlowStyle
versionNode.Tag = "!!str"

rc.Vars[config.SubstitutionPackageVersion] = bcfg.TargetVersion
rc.Vars[config.SubstitutionPackageEpoch] = epochNode.Value

// Recompute variable transforms
Expand Down

0 comments on commit ad2acc0

Please sign in to comment.