vault/tools/pipeline/internal/cmd/generate_enos_dynamic_config.go
Ryan Cragun 3e9f84e666
[VAULT-36202] pipeline(releases): add releases list active-versions command (#30658)
While working on VAULT-34829 it became apparent that if our new backporter
could know which branches are active and which CE counterparts are active
then we could completely omit the need for `ce` backport labels and instead
automatically backport to corresponding CE branches that are active.

To facilitate that we can re-use our `.release/versions.hcl` file as it is
the current source of truth for our present backport assistant workflow.

Here we add a new `pipeline releases list versions` command that is capable
of decoding that file and optionally displaying it. It will be used in the
next PR that fully implements VAULT-34829.

As part of this work we refactors `pipeline releases` to include a new `list`
sub-command and moved both `list-active-versions` and `versions` to it.

We also include a few small fixes that were noticed:
  - `.release/verions.hcl` was not up-to-date
  - Our cached dynamic config was not getting recreated when the pipeline
    tool changed. That has been fixed so now dynamic config should always
    get recreated when the pipeline binary changes
  - We now initialize a git client when using the `github` sub-command.
    This will be used in more forthcoming work
  - Update our changed file detection to resolve some incorrect groupings
  - Add some additional changed file helpers that we be used in forthcoming
    work

Signed-off-by: Ryan Cragun <me@ryan.ec>
2025-05-20 11:10:24 -06:00

58 lines
2.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package cmd
import (
"context"
"github.com/hashicorp/vault/tools/pipeline/internal/pkg/generate"
"github.com/hashicorp/vault/tools/pipeline/internal/pkg/releases"
"github.com/spf13/cobra"
)
// skipVersionsDefault are versions that we skip by default. This list can grow as necessary.
var skipVersionsDefault = []string{
"1.16.0", // 1.16.0 artifacts were revoked, always skip it if it's in the range
}
var genEnosDynamicConfigReq = &generate.EnosDynamicConfigReq{
VersionLister: releases.NewClient(),
}
func newGenerateEnosDynamicConfigCmd() *cobra.Command {
genCfg := &cobra.Command{
Use: "enos-dynamic-config",
Short: "Generate dynamic Enos configuration files",
Long: `Create branch specific Enos configuration dynamically. We do this to set the various
sample attribute variables on per-branch basis.`,
RunE: runGenerateEnosDynamicConfig,
}
genCfg.PersistentFlags().StringVarP(&genEnosDynamicConfigReq.VaultVersion, "version", "v", "", "The version of Vault")
genCfg.PersistentFlags().StringVarP(&genEnosDynamicConfigReq.VaultEdition, "edition", "e", "", "The edition of Vault. Can either be 'ce' or 'enterprise'")
genCfg.PersistentFlags().StringVarP(&genEnosDynamicConfigReq.EnosDir, "dir", "d", ".", "The enos directory to create the configuration in")
genCfg.PersistentFlags().UintVarP(&genEnosDynamicConfigReq.NMinus, "nminus", "n", 3, "Instead of setting a dedicated lower bound, calculate N-X from the upper")
genCfg.PersistentFlags().StringSliceVarP(&genEnosDynamicConfigReq.Skip, "skip", "s", skipVersionsDefault, "Skip these versions. Can be provided none-to-many times")
genCfg.PersistentFlags().StringVar(&genEnosDynamicConfigReq.FileName, "file", "enos-dynamic-config.hcl", "The name of the file to write the configuration into")
err := genCfg.MarkPersistentFlagRequired("edition")
if err != nil {
panic(err)
}
err = genCfg.MarkPersistentFlagRequired("version")
if err != nil {
panic(err)
}
return genCfg
}
func runGenerateEnosDynamicConfig(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true // Don't spam the usage on failure
_, err := genEnosDynamicConfigReq.Run(context.TODO())
return err
}