()
| 28 | ) |
| 29 | |
| 30 | func newAttestationInitCmd() *cobra.Command { |
| 31 | var ( |
| 32 | force bool |
| 33 | contractRevision int |
| 34 | attestationDryRun bool |
| 35 | workflowName string |
| 36 | projectName string |
| 37 | projectVersion string |
| 38 | useLatestVersion bool |
| 39 | projectVersionRelease bool |
| 40 | existingVersion bool |
| 41 | newWorkflowcontract string |
| 42 | collectors []string |
| 43 | markAsLatest bool |
| 44 | ) |
| 45 | |
| 46 | cmd := &cobra.Command{ |
| 47 | Use: "init", |
| 48 | Short: "start attestation crafting process", |
| 49 | Annotations: map[string]string{ |
| 50 | useAPIToken: trueString, |
| 51 | supportsFederatedAuthAnnotation: trueString, |
| 52 | confirmWhenUserToken: trueString, |
| 53 | }, |
| 54 | PreRunE: func(cmd *cobra.Command, _ []string) error { |
| 55 | if workflowName == "" { |
| 56 | return errors.New("workflow name is required, set it via --workflow flag") |
| 57 | } |
| 58 | |
| 59 | // load version from the file if not set and not using --latest-version |
| 60 | if projectVersion == "" && !useLatestVersion { |
| 61 | // load the cfg from the file |
| 62 | cfg, path, err := loadDotChainloopConfigWithParentTraversal() |
| 63 | // we do gracefully load, if not found, or any other error we continue |
| 64 | if err != nil { |
| 65 | logger.Debug().Msgf("failed to load chainloop config: %s", err) |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | logger.Debug().Msgf("loaded version %s from config file %s", cfg.ProjectVersion, path) |
| 70 | |
| 71 | projectVersion = cfg.ProjectVersion |
| 72 | } |
| 73 | |
| 74 | if useLatestVersion && projectVersion != "" { |
| 75 | return errors.New("--latest-version and --version are mutually exclusive") |
| 76 | } |
| 77 | |
| 78 | if cmd.Flags().Changed("mark-latest") && useLatestVersion { |
| 79 | return errors.New("--mark-latest and --latest-version are mutually exclusive") |
| 80 | } |
| 81 | |
| 82 | if projectVersion == "" && projectVersionRelease { |
| 83 | return errors.New("project version is required when using --release") |
| 84 | } |
| 85 | |
| 86 | if existingVersion && projectVersion == "" { |
| 87 | return errors.New("project version is required when using --existing-version") |
no test coverage detected