-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
333 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright © 2024 The Authors of uds-releaser | ||
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" | ||
) | ||
|
||
// 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", | ||
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 | ||
} | ||
|
||
err = version.MutateYamls(currentFlavor) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(mutateCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// gitlabCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// gitlabCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package gitlab | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/defenseunicorns/uds-releaser/src/types" | ||
"github.com/defenseunicorns/uds-releaser/src/utils" | ||
gitlab "github.com/xanzy/go-gitlab" | ||
) | ||
|
||
func TagAndRelease(flavor types.Flavor) error { | ||
repo, err := utils.OpenRepo() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
remote, err := repo.Remote("origin") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
remoteURL := remote.Config().URLs[0] | ||
|
||
// Parse the GitLab base URL from the remote URL | ||
var gitlabBaseURL string | ||
if strings.Contains(remoteURL, "gitlab.com") { | ||
gitlabBaseURL = "https://gitlab.com/api/v4" | ||
} else { | ||
// Extract the base URL for self-hosted GitLab instances | ||
parts := strings.Split(remoteURL, "/") | ||
if len(parts) > 2 { | ||
gitlabBaseURL = fmt.Sprintf("https://%s/api/v4", parts[2]) | ||
} else { | ||
return errors.New(fmt.Sprintf("error parsing gitlab base url from remote url: %s", remoteURL)) | ||
} | ||
} | ||
|
||
// Get the default branch of the current repository | ||
ref, err := repo.Head() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
defaultBranch := ref.Name().Short() | ||
|
||
// Create a new GitLab client | ||
gitlabClient, err := gitlab.NewClient(os.Getenv("CI_JOB_TOKEN"), gitlab.WithBaseURL(gitlabBaseURL)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
zarfPackageName, err := utils.GetPackageName() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// setup the release options | ||
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"), | ||
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 | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// Create the release | ||
release, _, err := gitlabClient.Releases.CreateRelease(os.Getenv("CI_PROJECT_ID"), releaseOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Release %s created\n", release.Name) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package utils | ||
|
||
import ( | ||
zarf "github.com/zarf-dev/zarf/src/api/v1alpha1" | ||
) | ||
|
||
func GetPackageName() (string, error) { | ||
var zarfPackage zarf.ZarfPackage | ||
err := LoadYaml("zarf.yaml", &zarfPackage) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return zarfPackage.Metadata.Name, nil | ||
} |
Oops, something went wrong.