Skip to content

Commit

Permalink
feat: enable github tag signing by skipping manually created tags (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
corang authored Oct 30, 2024
1 parent 966fc91 commit c850b6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
22 changes: 1 addition & 21 deletions src/platforms/github/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Platform struct{}

func (Platform) TagAndRelease(flavor types.Flavor, tokenVarName string) error {
remoteURL, _, ref, err := utils.GetRepoInfo()
remoteURL, _, err := utils.GetRepoInfo()
if err != nil {
return err
}
Expand All @@ -40,26 +40,6 @@ func (Platform) TagAndRelease(flavor types.Flavor, tokenVarName string) error {
tagName := fmt.Sprintf("%s-%s", flavor.Version, flavor.Name)
releaseName := fmt.Sprintf("%s %s", zarfPackageName, tagName)

tag := createGitHubTag(tagName, releaseName, ref.Hash().String())

createdTag, _, err := githubClient.Git.CreateTag(context.Background(), owner, repoName, tag)
if err != nil {
return err
}

// Create a reference for the tag
tagRef := &github.Reference{
Ref: github.String("refs/tags/" + tagName),
Object: &github.GitObject{
SHA: createdTag.SHA,
},
}

_, _, err = githubClient.Git.CreateRef(context.Background(), owner, repoName, tagRef)
if err != nil {
return err
}

// Create the release
release := &github.RepositoryRelease{
TagName: github.String(tagName),
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/gitlab/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type Platform struct{}

func (Platform) TagAndRelease(flavor types.Flavor, tokenVarName string) error {
remoteURL, defaultBranch, _, err := utils.GetRepoInfo()
remoteURL, defaultBranch, err := utils.GetRepoInfo()
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions src/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ func OpenRepo() (*git.Repository, error) {
return git.PlainOpen(".")
}

func GetRepoInfo() (remoteURL string, defaultBranch string, ref *plumbing.Reference, err error) {
func GetRepoInfo() (remoteURL string, defaultBranch string, err error) {
repo, err := OpenRepo()
if err != nil {
return "", "", ref, err
return "", "", err
}

remote, err := repo.Remote("origin")
if err != nil {
return "", "", ref, err
return "", "", err
}

remoteURL = remote.Config().URLs[0]

ref, err = repo.Head()
ref, err := repo.Head()
if err != nil {
return "", "", ref, err
return "", "", err
}

defaultBranch = ref.Name().Short()
return remoteURL, defaultBranch, ref, nil
return remoteURL, defaultBranch, nil
}

0 comments on commit c850b6d

Please sign in to comment.