Skip to content

Commit

Permalink
refactor: update application to fit design doc (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
corang authored Oct 8, 2024
1 parent b94a98e commit 4465a76
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 55 deletions.
13 changes: 5 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
)
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
25 changes: 18 additions & 7 deletions src/cmd/check.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()
Expand All @@ -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)
}
20 changes: 10 additions & 10 deletions src/cmd/gitlab.go → src/cmd/release.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 {
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion src/cmd/root.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
19 changes: 11 additions & 8 deletions src/cmd/mutate.go → src/cmd/show.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()
Expand All @@ -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)
}
49 changes: 49 additions & 0 deletions src/cmd/update-yaml.go
Original file line number Diff line number Diff line change
@@ -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)
}
15 changes: 1 addition & 14 deletions src/gitlab/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions src/version/mutate.go → src/version/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tasks.yaml
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 4465a76

Please sign in to comment.