Files
opentf/tools/find-dep-upgrades/model.go
Martin Atkins c923b80089 tools: find-dep-upgrades for suggesting an order to upgrade deps
We tend to get scared off from routine dependency upgrades because it's
hard to know where to start when we want to avoid upgrading too many things
at once and thus making it hard for us to understand the impact.

This tool makes a best effort to suggest an order of upgrades that lets us
upgrade one thing at a time when possible, and if not possible then at
least tries to minimize how many things get upgraded at once.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
2025-10-09 16:03:44 -07:00

41 lines
930 B
Go

// Copyright (c) The OpenTofu Authors
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package main
import (
"fmt"
"strings"
"github.com/apparentlymart/go-versions/versions"
)
// ModulePath is a string containing a Go module path.
type ModulePath string
// Version is a convenience alias for [versions.Version]
type Version = versions.Version
type UpgradeCandidate struct {
Module ModulePath
CurrentVersion Version
LatestVersion Version
}
type PendingUpgrade struct {
Module ModulePath
CurrentVersion Version
LatestVersion Version
Prereqs map[ModulePath]Version
}
func parseVersion(raw string) (Version, error) {
if !strings.HasPrefix(raw, "v") {
return versions.Unspecified, fmt.Errorf("missing 'v' prefix")
}
raw = raw[1:] // the "versions" library doesn't actually want the prefix
return versions.ParseVersion(raw)
}