diff --git a/go.mod b/go.mod index 271582d..b1b586c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,10 @@ go 1.22.6 require ( github.com/defenseunicorns/uds-cli v0.16.0 + github.com/go-git/go-git/v5 v5.12.0 + github.com/goccy/go-yaml v1.12.0 github.com/spf13/cobra v1.8.1 + github.com/xanzy/go-gitlab v0.109.0 github.com/zarf-dev/zarf v0.39.0 ) @@ -24,6 +27,7 @@ require ( github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/invopop/jsonschema v0.12.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect @@ -34,6 +38,7 @@ require ( github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/skeema/knownhosts v1.2.2 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.27.0 // indirect @@ -48,11 +53,3 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) - -require ( - github.com/go-git/go-git/v5 v5.12.0 - github.com/goccy/go-yaml v1.12.0 - github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/pflag v1.0.5 // indirect - github.com/xanzy/go-gitlab v0.109.0 -) diff --git a/main.go b/main.go index 82b308e..56313c4 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 The Authors of uds-releaser +Copyright © 2024 Defense Unicorns Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/cmd/check.go b/src/cmd/check.go index 5bfa74f..a8bc6df 100644 --- a/src/cmd/check.go +++ b/src/cmd/check.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 The Authors of uds-releaser +Copyright © 2024 Defense Unicorns Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,10 +23,12 @@ import ( "github.com/spf13/cobra" ) +var boolOutput bool + // checkCmd represents the check command var checkCmd = &cobra.Command{ - Use: "check [ flavor ]", - Short: "check if release is necessary for given flavor", + Use: "check flavor", + Short: "Check if release is necessary for given flavor", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { releaserConfig, err := utils.LoadReleaserConfig() @@ -48,15 +50,24 @@ var checkCmd = &cobra.Command{ return err } if tagExists { - fmt.Printf("Version %s is already tagged\n", versionAndFlavor) - return errors.New("no release necessary") + if boolOutput { + fmt.Println("false") + } else { + fmt.Printf("Version %s is already tagged\n", versionAndFlavor) + return errors.New("no release necessary") + } } else { - fmt.Printf("Version %s is not tagged\n", versionAndFlavor) - return nil + if boolOutput { + fmt.Println("true") + } else { + fmt.Printf("Version %s is not tagged\n", versionAndFlavor) + } } + return nil }, } func init() { + checkCmd.Flags().BoolVarP(&boolOutput, "boolean", "b", false, "Switch the output string to a true/false based on if a release is necessary. True if a release is necessary, false if not.") rootCmd.AddCommand(checkCmd) } diff --git a/src/cmd/gitlab.go b/src/cmd/release.go similarity index 85% rename from src/cmd/gitlab.go rename to src/cmd/release.go index 4eeee67..f1397d1 100644 --- a/src/cmd/gitlab.go +++ b/src/cmd/release.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 The Authors of uds-releaser +Copyright © 2024 Defense Unicorns Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,13 +23,7 @@ import ( // gitlabCmd represents the gitlab command var gitlabCmd = &cobra.Command{ - Use: "gitlab", - Short: "Collection of commands for releasing on GitLab", -} - -// releaseCmd represents the release command -var releaseCmd = &cobra.Command{ - Use: "release [ flavor ]", + Use: "gitlab flavor", Short: "Create a tag and release on GitLab based on flavor", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -49,7 +43,13 @@ var releaseCmd = &cobra.Command{ }, } +// releaseCmd represents the release command +var releaseCmd = &cobra.Command{ + Use: "release platform", + Short: "Collection of commands for releasing on different platforms", +} + func init() { - rootCmd.AddCommand(gitlabCmd) - gitlabCmd.AddCommand(releaseCmd) + rootCmd.AddCommand(releaseCmd) + releaseCmd.AddCommand(gitlabCmd) } diff --git a/src/cmd/root.go b/src/cmd/root.go index 4ca6579..12b032e 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 The Authors of uds-releaser +Copyright © 2024 Defense Unicorns Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/src/cmd/mutate.go b/src/cmd/show.go similarity index 72% rename from src/cmd/mutate.go rename to src/cmd/show.go index 3f0b191..7fe14e2 100644 --- a/src/cmd/mutate.go +++ b/src/cmd/show.go @@ -1,5 +1,5 @@ /* -Copyright © 2024 The Authors of uds-releaser +Copyright © 2024 Defense Unicorns Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,15 +16,16 @@ limitations under the License. package cmd import ( + "fmt" + "github.com/defenseunicorns/uds-releaser/src/utils" - "github.com/defenseunicorns/uds-releaser/src/version" "github.com/spf13/cobra" ) -// mutateCmd represents the mutate command -var mutateCmd = &cobra.Command{ - Use: "mutate [ flavor ]", - Short: "Mutate version fields in the zarf.yaml and uds-bundle.yaml based on flavor", +// showCmd represents the show command +var showCmd = &cobra.Command{ + Use: "show flavor", + Short: "Show the current version for a given flavor", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { releaserConfig, err := utils.LoadReleaserConfig() @@ -39,10 +40,12 @@ var mutateCmd = &cobra.Command{ rootCmd.SilenceUsage = true - return version.MutateYamls(currentFlavor) + fmt.Printf("%s-%s\n", currentFlavor.Version, currentFlavor.Name) + + return nil }, } func init() { - rootCmd.AddCommand(mutateCmd) + rootCmd.AddCommand(showCmd) } diff --git a/src/cmd/update-yaml.go b/src/cmd/update-yaml.go new file mode 100644 index 0000000..670a7ba --- /dev/null +++ b/src/cmd/update-yaml.go @@ -0,0 +1,49 @@ +/* +Copyright © 2024 Defense Unicorns + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package cmd + +import ( + "github.com/defenseunicorns/uds-releaser/src/utils" + "github.com/defenseunicorns/uds-releaser/src/version" + "github.com/spf13/cobra" +) + +// updateYamlCmd represents the updateyaml command +var updateYamlCmd = &cobra.Command{ + Use: "update-yaml flavor", + Aliases: []string{"u"}, + Short: "Update the version fields in the zarf.yaml and uds-bundle.yaml based on flavor", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + releaserConfig, err := utils.LoadReleaserConfig() + if err != nil { + return err + } + + currentFlavor, err := utils.GetFlavorConfig(args[0], releaserConfig) + if err != nil { + return err + } + + rootCmd.SilenceUsage = true + + return version.UpdateYamls(currentFlavor) + }, +} + +func init() { + rootCmd.AddCommand(updateYamlCmd) +} diff --git a/src/gitlab/release.go b/src/gitlab/release.go index 7ea921d..b3510f7 100644 --- a/src/gitlab/release.go +++ b/src/gitlab/release.go @@ -64,21 +64,8 @@ func TagAndRelease(flavor types.Flavor) error { releaseOpts := &gitlab.CreateReleaseOptions{ Name: gitlab.Ptr(fmt.Sprintf("%s %s-%s", zarfPackageName, flavor.Version, flavor.Name)), TagName: gitlab.Ptr(fmt.Sprintf("%s-%s", flavor.Version, flavor.Name)), - Description: gitlab.Ptr("Release description"), + Description: gitlab.Ptr(fmt.Sprintf("%s %s-%s", zarfPackageName, flavor.Version, flavor.Name)), Ref: gitlab.Ptr(defaultBranch), - Assets: &gitlab.ReleaseAssetsOptions{ - Links: []*gitlab.ReleaseAssetLinkOptions{ - { - Name: gitlab.Ptr("zarf.yaml"), // TODO - URL: gitlab.Ptr("https://example.com/zarf.yaml"), // TODO - LinkType: gitlab.Ptr(gitlab.PackageLinkType), - }, - { - Name: gitlab.Ptr("uds-bundle.yaml"), // TODO - URL: gitlab.Ptr("https://example.com/uds-bundle.yaml"), // TODO - }, - }, - }, } fmt.Printf("Creating release %s-%s\n", flavor.Version, flavor.Name) diff --git a/src/version/mutate.go b/src/version/yaml.go similarity index 82% rename from src/version/mutate.go rename to src/version/yaml.go index ce2e7d6..04beb9a 100644 --- a/src/version/mutate.go +++ b/src/version/yaml.go @@ -9,16 +9,16 @@ import ( zarf "github.com/zarf-dev/zarf/src/api/v1alpha1" ) -func MutateYamls(flavor types.Flavor) error { - packageName, err := mutateZarfYaml(flavor) +func UpdateYamls(flavor types.Flavor) error { + packageName, err := updateZarfYaml(flavor) if err != nil { return err } - return mutateBundleYaml(flavor, packageName) + return updateBundleYaml(flavor, packageName) } -func mutateZarfYaml(flavor types.Flavor) (packageName string, err error) { +func updateZarfYaml(flavor types.Flavor) (packageName string, err error) { var zarfPackage zarf.ZarfPackage err = utils.LoadYaml("zarf.yaml", &zarfPackage) if err != nil { @@ -37,7 +37,7 @@ func mutateZarfYaml(flavor types.Flavor) (packageName string, err error) { return zarfPackage.Metadata.Name, nil } -func mutateBundleYaml(flavor types.Flavor, packageName string) error { +func updateBundleYaml(flavor types.Flavor, packageName string) error { var bundle uds.UDSBundle err := utils.LoadYaml("bundle/uds-bundle.yaml", &bundle) if err != nil { diff --git a/tasks.yaml b/tasks.yaml index 7fdb504..edbcbba 100644 --- a/tasks.yaml +++ b/tasks.yaml @@ -1,4 +1,4 @@ -# Copyright © 2024 The Authors of uds-releaser +# Copyright © 2024 Defense Unicorns # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.