Skip to content

Commit

Permalink
Gitlab-token-env-var (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
corang authored Oct 16, 2024
1 parent efb7e61 commit 151c93d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ uds-releaser update-yaml <flavor>
uds-releaser release <flavor>
```

### Gitlab

When running `uds-releaser release gitlab <flavor>` you are expected to have an environment variable set to a GitLab token that has write permissions for your current project. This defaults to `GITLAB_RELEASE_TOKEN` but can be changed with the `--token-var-name` flag.

## Configuration

UDS-Releaser can be configured using a YAML file named uds-releaser.yaml in your project's root directory.
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/spf13/cobra"
)

var tokenVarName string

// gitlabCmd represents the gitlab command
var gitlabCmd = &cobra.Command{
Use: "gitlab flavor",
Expand All @@ -39,7 +41,7 @@ var gitlabCmd = &cobra.Command{

rootCmd.SilenceUsage = true

return gitlab.TagAndRelease(currentFlavor)
return gitlab.TagAndRelease(currentFlavor, tokenVarName)
},
}

Expand All @@ -52,4 +54,5 @@ var releaseCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(releaseCmd)
releaseCmd.AddCommand(gitlabCmd)
gitlabCmd.Flags().StringVarP(&tokenVarName, "token-var-name", "t", "GITLAB_RELEASE_TOKEN", "Environment variable name for GitLab token")
}
4 changes: 2 additions & 2 deletions src/gitlab/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var openRepo = utils.OpenRepo

var getPackageName = utils.GetPackageName

func TagAndRelease(flavor types.Flavor) error {
func TagAndRelease(flavor types.Flavor, tokenVarName string) error {
repo, err := openRepo()
if err != nil {
return err
Expand Down Expand Up @@ -47,7 +47,7 @@ func TagAndRelease(flavor types.Flavor) error {
fmt.Printf("Default branch: %s\n", defaultBranch)

// Create a new GitLab client
gitlabClient, err := newGitlabClient(os.Getenv("GITLAB_RELEASE_TOKEN"), gitlab.WithBaseURL(gitlabBaseURL))
gitlabClient, err := newGitlabClient(os.Getenv(tokenVarName), gitlab.WithBaseURL(gitlabBaseURL))
if err != nil {
return err
}
Expand Down

0 comments on commit 151c93d

Please sign in to comment.