mirror of
https://github.com/hashicorp/vault.git
synced 2026-02-03 20:40:45 -05:00
* [VAULT-40043]: pipeline: add `go diff mod` command Add a `pipeline go diff mod` command that is capable of comparing two go.mod files at a directive level. We also support strict or lax comparisons of several directives to flexible diff comparisons. This is especially useful when you want to compare two go.mod files that have some different dependencies (CE vs. Ent) but still want to compare versions of like dependencies. This command is not currently used in the pipeline but was useful in developing the diff library that is used. Subsequent work will use the library and be integrated into CI. * review feedback * one more comment fix --------- Signed-off-by: Ryan Cragun <me@ryan.ec> Co-authored-by: Ryan Cragun <me@ryan.ec>
29 lines
743 B
Go
29 lines
743 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package golang
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"golang.org/x/mod/modfile"
|
|
)
|
|
|
|
func diffToolchain(a *modfile.File, b *modfile.File) *Diff {
|
|
if (a == nil && b == nil) ||
|
|
(a.Toolchain == nil && b.Toolchain == nil) ||
|
|
((a.Toolchain != nil && b.Toolchain != nil) && (a.Toolchain.Name == b.Toolchain.Name)) {
|
|
|
|
return nil
|
|
}
|
|
|
|
diff := newDiffFromModFiles(a, b, DirectiveToolchain)
|
|
if a != nil && a.Toolchain != nil && a.Toolchain.Syntax != nil {
|
|
diff.Diff.A = []string{strings.Join(a.Toolchain.Syntax.Token, " ") + "\n"}
|
|
}
|
|
if b != nil && b.Toolchain != nil && b.Toolchain.Syntax != nil {
|
|
diff.Diff.B = []string{strings.Join(b.Toolchain.Syntax.Token, " ")}
|
|
}
|
|
|
|
return diff
|
|
}
|