From c78092bf9fa60a6e8193d9caff9da3ff53096dc9 Mon Sep 17 00:00:00 2001 From: Vibhav Bobade Date: Tue, 21 Apr 2026 15:48:08 +0530 Subject: [PATCH] feat(cli): allow setting project name in .chainloop.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend DotChainloopConfig to support a `project` field so that `chainloop attestation init` can read the project name from the config file when the --project flag is not provided. Precedence: CLI flag > .chainloop.yaml > default. Example .chainloop.yaml: project: my-project projectVersion: v1.2.0 Note: organization override from .chainloop.yaml is not included in this PR because the org is baked into the gRPC connection credentials during PersistentPreRunE, before att init's PreRunE runs. Supporting org override requires loading the config earlier in the command lifecycle — left for follow-up discussion. Fixes: chainloop-dev/chainloop#3063 Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Vibhav Bobade --- app/cli/cmd/attestation_init.go | 27 ++++++++++++++----------- app/cli/cmd/config.go | 1 + app/cli/documentation/cli-reference.mdx | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/cli/cmd/attestation_init.go b/app/cli/cmd/attestation_init.go index ed4525ee8..b741e3201 100644 --- a/app/cli/cmd/attestation_init.go +++ b/app/cli/cmd/attestation_init.go @@ -55,19 +55,23 @@ func newAttestationInitCmd() *cobra.Command { return errors.New("workflow name is required, set it via --workflow flag") } - // load version from the file if not set and not using --latest-version - if projectVersion == "" && !useLatestVersion { - // load the cfg from the file + // Load project name and version from .chainloop.yaml when the + // corresponding CLI flags are not provided. + // Precedence: CLI flag > .chainloop.yaml > default/auto-discovery. + if projectName == "" || (projectVersion == "" && !useLatestVersion) { cfg, path, err := loadDotChainloopConfigWithParentTraversal() - // we do gracefully load, if not found, or any other error we continue if err != nil { logger.Debug().Msgf("failed to load chainloop config: %s", err) - return nil + } else { + if projectName == "" && cfg.Project != "" { + logger.Debug().Msgf("loaded project %q from config file %s", cfg.Project, path) + projectName = cfg.Project + } + if projectVersion == "" && !useLatestVersion && cfg.ProjectVersion != "" { + logger.Debug().Msgf("loaded version %q from config file %s", cfg.ProjectVersion, path) + projectVersion = cfg.ProjectVersion + } } - - logger.Debug().Msgf("loaded version %s from config file %s", cfg.ProjectVersion, path) - - projectVersion = cfg.ProjectVersion } if useLatestVersion && projectVersion != "" { @@ -154,7 +158,7 @@ func newAttestationInitCmd() *cobra.Command { } if projectName == "" { - logger.Warn().Msg("DEPRECATION WARNING: --project not set, this will be required in the near future") + logger.Warn().Msg("DEPRECATION WARNING: project not set via --project flag or .chainloop.yaml, this will be required in the near future") } return output.EncodeOutput(flagOutputFormat, res, fullStatusTable) @@ -173,8 +177,7 @@ func newAttestationInitCmd() *cobra.Command { cmd.Flags().StringVar(&workflowName, "workflow-name", "", "name of the workflow to run the attestation") cobra.CheckErr(cmd.Flags().MarkDeprecated("workflow-name", "please use --workflow instead")) - cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow") - cobra.CheckErr(cmd.MarkFlagRequired("project")) + cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow (can also be set in .chainloop.yaml)") cmd.Flags().StringVar(&newWorkflowcontract, "contract", "", "name of an existing contract or the path/URL to a contract file, to attach it to the auto-created workflow (it doesn't update an existing one)") cmd.Flags().StringVar(&projectVersion, "version", "", "project version, i.e 0.1.0") diff --git a/app/cli/cmd/config.go b/app/cli/cmd/config.go index e49233965..12e0f756f 100644 --- a/app/cli/cmd/config.go +++ b/app/cli/cmd/config.go @@ -161,4 +161,5 @@ func isDir(filename string) bool { type DotChainloopConfig struct { ProjectVersion string `yaml:"projectVersion"` + Project string `yaml:"project"` } diff --git a/app/cli/documentation/cli-reference.mdx b/app/cli/documentation/cli-reference.mdx index c8d3914c6..26ceb5869 100755 --- a/app/cli/documentation/cli-reference.mdx +++ b/app/cli/documentation/cli-reference.mdx @@ -328,7 +328,7 @@ Options --existing-version return an error if the version doesn't exist in the project -h, --help help for init --latest-version use the latest existing project version instead of specifying one ---project string name of the project of this workflow +--project string name of the project of this workflow (can also be set in .chainloop.yaml) --release promote the provided version as a release --remote-state Store the attestation state remotely -f, --replace replace any existing in-progress attestation