From 09d0ea7e98829ccbeb18da68b57c5cbc3580a5b3 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Tue, 11 Feb 2020 16:30:59 +1100 Subject: [PATCH 01/29] Add create command and integrate with internal/gitlab client --- .gitlab-ci.yml | 11 +++ internal/commands/create.go | 130 +++++++++++++++++++++++++++++++ internal/commands/create_test.go | 14 ++++ 3 files changed, 155 insertions(+) create mode 100644 internal/commands/create.go create mode 100644 internal/commands/create_test.go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 308ad0b..55c781f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,3 +35,14 @@ cover: artifacts: paths: - coverage.html + +release-branch: + stage: release-branch + when: manual + except: + - master + dependencies: + - build + script: + - ./bin/gitlab-releaser create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA + diff --git a/internal/commands/create.go b/internal/commands/create.go new file mode 100644 index 0000000..b63e7f3 --- /dev/null +++ b/internal/commands/create.go @@ -0,0 +1,130 @@ +package commands + +import ( + "fmt" + "io" + "net/http" + "os" + "time" + + log "github.com/sirupsen/logrus" + "github.com/urfave/cli/v2" + + "gitlab.com/gitlab-org/gitlab-releaser/internal/gitlab" +) + +var defaultClientTimeout = 10 * time.Second + +// Create defines the create command to be used by the CLI +func Create() *cli.Command { + httpClient := &http.Client{ + Timeout: defaultClientTimeout, + } + + return &cli.Command{ + Name: "create", + Aliases: []string{"c"}, + Usage: "Create a Release using GitLab's Releases API", + UsageText: "gitlab-release create [OPTIONS]", + Action: createRelease(httpClient), + Subcommands: nil, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "name", + Aliases: []string{"n"}, + Usage: "Name for this Release", + Required: true, + Destination: nil, + }, + &cli.StringFlag{ + Name: "description", + Aliases: []string{"d"}, + Usage: "Description for this Release", + Required: true, + Destination: nil, + }, + &cli.StringFlag{ + Name: "tag-name", + Aliases: []string{"tag"}, + Usage: "Tag name to use for this Release, ref will be used if not present", + Required: true, + EnvVars: []string{"CI_COMMIT_TAG"}, + Destination: nil, + }, + &cli.StringFlag{ + Name: "ref", + Aliases: []string{"r"}, + Usage: "Reference name to use for this Release, only used if tag-name is not present", + Required: false, + EnvVars: []string{"CI_COMMIT_SHA"}, + Destination: nil, + }, + }, + } +} + +func createRelease(httpClient *http.Client) cli.ActionFunc { + return func(ctx *cli.Context) error { + id := ctx.String("id") + name := ctx.String("name") + description := ctx.String("description") + baseURL := ctx.String("gitlab-server-api-url") + token := ctx.String("token") + tagName := ctx.String("tag-name") + ref := ctx.String("ref") + + l := log.WithFields(log.Fields{ + "command": ctx.Command.Name, + "id": id, + "name": name, + "description": description, + "tag-name": tagName, + "ref": ref, + }) + + l.Info("Creating Release...") + + gitlabClient := gitlab.New(baseURL, token, id, httpClient) + + release, err := gitlabClient.CreateRelease(ctx.Context, &gitlab.CreateReleaseRequest{ + ID: id, + Name: name, + Description: description, + TagName: tagName, + Ref: ref, + }) + if err != nil { + return fmt.Errorf("failed to create release: %w", err) + } + + printReleaseOutput(ctx.App.Writer, release) + + l.Info("release created successfully!") + + return nil + } +} + +func printReleaseOutput(w io.Writer, release *gitlab.CreateReleaseResponse) { + fmt.Fprintf(w, ` + +Tag: %s +Name: %s +Description: %s +Created At: %s +Released At: %s + +`, + release.TagName, + release.Name, + release.Description, + release.CreatedAt, + release.ReleasedAt, + ) + + for _, source := range release.Assets.Sources { + fmt.Fprintf(w, "%s - %s\n", source.Format, source.URL) + } + + fmt.Fprintf(w, "See all releases here: %s/-/releases\n", os.Getenv("CI_PROJECT_URL")) +} diff --git a/internal/commands/create_test.go b/internal/commands/create_test.go new file mode 100644 index 0000000..2f8a4bc --- /dev/null +++ b/internal/commands/create_test.go @@ -0,0 +1,14 @@ +package commands + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCreate(t *testing.T) { + got := Create() + require.NotNil(t, got) + require.Equal(t, "create", got.Name) + require.Len(t, got.Flags, 4) +} -- GitLab From 2e8f81b03a52f787c5cb4cff328274b03d8dbc9a Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Tue, 11 Feb 2020 16:28:32 +1100 Subject: [PATCH 02/29] Add release-branch manual step for testing --- .gitlab-ci.yml | 5 ++--- internal/app/app.go | 32 +++++++++++++++++++++++++++++--- internal/app/app_test.go | 1 + 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 55c781f..f04ef48 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ image: golang:1.13.7 stages: - test - build - - self-release # for testing only + - release-branch # for testing only build: stage: build @@ -22,7 +22,7 @@ test: script: - make test -lint: +lint: stage: test image: golangci/golangci-lint:v1.23.2 script: @@ -45,4 +45,3 @@ release-branch: - build script: - ./bin/gitlab-releaser create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA - diff --git a/internal/app/app.go b/internal/app/app.go index 30cb794..e54de10 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -5,6 +5,8 @@ import ( "time" "github.com/urfave/cli/v2" + + "gitlab.com/gitlab-org/gitlab-releaser/internal/commands" ) // New creates cli.App for the releaser CLI @@ -17,9 +19,7 @@ func New(version, revision string) *cli.App { Version: fmt.Sprintf("%s-rev:%s", version, revision), Description: "gitlab-releaser is a CLI tool that can be used to interact with GitLab's Releases API", Commands: []*cli.Command{ - { - Name: "create", - }, + commands.Create(), }, CommandNotFound: nil, OnUsageError: nil, @@ -30,5 +30,31 @@ func New(version, revision string) *cli.App { Email: "support@gitlab.com", }, }, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "gitlab-server-api-url", + Aliases: []string{"gs"}, + Usage: "GitLab server API V4 URL", + Required: true, + EnvVars: []string{"CI_API_V4_URL"}, + Destination: nil, + }, + &cli.StringFlag{ + Name: "token", + Aliases: []string{"t"}, + Usage: "Token used for authentication to the GitLab Releases API", + Required: true, + EnvVars: []string{"CI_JOB_TOKEN"}, + Destination: nil, + }, + &cli.StringFlag{ + Name: "project-id", + Aliases: []string{"id"}, + Usage: "Project ID in which to create the Release", + Required: true, + EnvVars: []string{"CI_PROJECT_ID"}, + Destination: nil, + }, + }, } } diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 018142a..2ba4de5 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -11,4 +11,5 @@ func TestNew(t *testing.T) { require.NotNil(t, got) require.Equal(t, "gitlab-releaser", got.Name) require.Len(t, got.Commands, 1) + require.Len(t, got.Flags, 3) } -- GitLab From cd02d043800c34d73d68fa1fa4a395156ce5754c Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 20 Feb 2020 10:16:22 +1100 Subject: [PATCH 03/29] Rename -token to -job-token to make it easier to implement #11 --- internal/app/app.go | 4 ++-- internal/gitlab/client.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/app/app.go b/internal/app/app.go index e54de10..3785b08 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -40,8 +40,8 @@ func New(version, revision string) *cli.App { Destination: nil, }, &cli.StringFlag{ - Name: "token", - Aliases: []string{"t"}, + Name: "job-token", + Aliases: []string{"jt"}, Usage: "Token used for authentication to the GitLab Releases API", Required: true, EnvVars: []string{"CI_JOB_TOKEN"}, diff --git a/internal/gitlab/client.go b/internal/gitlab/client.go index 4adf5f5..bfafd66 100644 --- a/internal/gitlab/client.go +++ b/internal/gitlab/client.go @@ -56,7 +56,7 @@ func (gc *Client) request(ctx context.Context, method, url string, body io.Reade req = req.WithContext(ctx) - // TODO support `PRIVATE-TOKEN` when the cli is not used in CI + // TODO support `PRIVATE-TOKEN` when the cli is not used in CI https://gitlab.com/gitlab-org/gitlab-releaser/issues/11 req.Header.Set("JOB-TOKEN", gc.token) req.Header.Set("Content-Type", "application/json") -- GitLab From 1fe3c993cb8546edd693bff1e31328df7e5174fb Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 5 Mar 2020 15:40:34 +1100 Subject: [PATCH 04/29] Update usage documentation in the help menu Add flags package with flag names defined as constants Add docs/README.md to document usage of this tool --- .gitlab-ci.yml | 122 ++++++++++++++++----------------- docs/README.md | 98 ++++++++++++++++++++++++++ internal/app/app.go | 35 +++++----- internal/commands/create.go | 76 +++++++++----------- internal/flags/const.go | 18 +++++ internal/gitlab/client.go | 9 ++- internal/gitlab/client_test.go | 5 +- 7 files changed, 237 insertions(+), 126 deletions(-) create mode 100644 docs/README.md create mode 100644 internal/flags/const.go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 628ea71..8a68c8f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,29 +6,29 @@ cache: paths: - .go/pkg/mod/ - -include: - - template: Security/License-Management.gitlab-ci.yml - - template: Security/SAST.gitlab-ci.yml - +# +##include: +## - template: Security/License-Management.gitlab-ci.yml +## - template: Security/SAST.gitlab-ci.yml +# variables: GO: "1.13.8" - +# image: golang:${GO} - +# stages: - build - - test - - security +## - test +## - security - release-branch # for testing only - -license_management: - stage: security - -sast: - stage: security - - +# +##license_management: +## stage: security +## +##sast: +## stage: security +# +# build: extends: .go-cache stage: build @@ -40,50 +40,50 @@ build: paths: - ./bin/gitlab-releaser expire_in: 7 days - -test: - extends: .go-cache - stage: test - script: - - make test - -test-race: - extends: .go-cache - stage: test - image: golang:${GO} - variables: - CGO_ENABLED: 1 - script: - - make test-race - -lint: - extends: .go-cache - image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine - stage: test - script: - # Use default .golangci.yml file from the image if one is not present in the project root. - - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' - # Write the code coverage report to gl-code-quality-report.json - # and print linting issues to stdout in the format: path/to/file:line description - - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' - artifacts: - reports: - codequality: gl-code-quality-report.json - paths: - - gl-code-quality-report.json - expire_in: 7 days - allow_failure: true - -cover: - extends: .go-cache - stage: test - script: - - make cover - artifacts: - paths: - - cover/coverage.html - expire_in: 7 days - +# +#test: +# extends: .go-cache +# stage: test +# script: +# - make test +# +#test-race: +# extends: .go-cache +# stage: test +# image: golang:${GO} +# variables: +# CGO_ENABLED: 1 +# script: +# - make test-race +# +#lint: +# extends: .go-cache +# image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine +# stage: test +# script: +# # Use default .golangci.yml file from the image if one is not present in the project root. +# - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' +# # Write the code coverage report to gl-code-quality-report.json +# # and print linting issues to stdout in the format: path/to/file:line description +# - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' +# artifacts: +# reports: +# codequality: gl-code-quality-report.json +# paths: +# - gl-code-quality-report.json +# expire_in: 7 days +# allow_failure: true +# +#cover: +# extends: .go-cache +# stage: test +# script: +# - make cover +# artifacts: +# paths: +# - cover/coverage.html +# expire_in: 7 days +# release-branch: stage: release-branch when: manual diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..cf6b51d --- /dev/null +++ b/docs/README.md @@ -0,0 +1,98 @@ +# GitLab Releaser CLI documentation + +gitlab-releaser is a CLI tool that can be used to interact with GitLab's Releases API. + +## Usage + +```shell script +$ gitlab-releaser help +NAME: + gitlab-releaser - A CLI tool that interacts with GitLab's Releases API + +USAGE: + gitlab-releaser [global options] command [command options] [arguments...] + +VERSION: + 0.0.1~beta.17.g14e5c2a + +DESCRIPTION: + +CLI tool that can be used to interact with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/. + +All configuration flags will default to GitLab's CI predefined environment variables. +For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html +If you would like to override these values please use the [GLOBAL OPTIONS]. + +For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser + +AUTHOR: + GitLab Inc. + +COMMANDS: + create, c Create a Release using GitLab's Releases API + help, h Shows a list of commands or help for one command + +GLOBAL OPTIONS: + --server-url value The base URL of the GitLab instance, including protocol and port e.g. https://gitlab.example.com:8080. [$CI_SERVER_URL] + --job-token value Token used for authenticating with the GitLab Releases API. [$CI_JOB_TOKEN] + --project-id value The unique id of the current project that GitLab CI uses internally. [$CI_PROJECT_ID] + --help, -h show help (default: false) + --version, -v print the version (default: false) +``` + + +## Configuration + +All configuration flags will default to GitLab's CI predefined environment variables. +For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html +If you would like to override these values please use the [GLOBAL OPTIONS]. + +e.g. to create a release with a custom GitLab server URL + +```shell script +gitlab-releaser -server-url https://gitlab.mydomain.com create -name "My Release" -description "THis is a new release for my amazing tool" +``` + + +## Create a new release + +See [Create a Release](https://docs.gitlab.com/ee/api/releases/) API + +```shell script +$ gitlab-releaser --server-url https://gitlab.com --job-token=SOME_JOB_TOKEN --project-id 12345 create help +NAME: + gitlab-releaser create - Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release. + +USAGE: + gitlab-releaser create [command options] [arguments...] + +OPTIONS: + --name value The release name. + --description value The description of the release. You can use Markdown. + --tag-name value The tag where the release will be created from. [$CI_COMMIT_TAG] + --ref value If tag_name doesn’t exist, the release will be created from ref. It can be a commit SHA, another tag name, or a branch name. [$CI_COMMIT_SHA] + --help, -h show help (default: false) +``` + +## Using this tool in GitLab CI + +This tool will be available to use when the new `release` section becomes available in `.gitlab-ci.yml` +https://gitlab.com/groups/gitlab-org/-/epics/2510 + +If you would like to try this on your project please add the following step to your `.gitlab-ci.yml` +*NOTE* this is still under development. Please report any new issues in https://gitlab.com/gitlab-org/gitlab-releaser/issues +*NOTE* https://gitlab.com/gitlab-org/gitlab/issues/16290 when a tag is created, a new pipeline will run. +To avoid some steps running in an infinite loop please add the `execpt: tags` rule to the jobs you don't want to run. + +```yaml +release-branch: + stage: release-branch + when: manual + except: + - master + dependencies: + - build + script: + - ./bin/gitlab-releaser create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA + +``` diff --git a/internal/app/app.go b/internal/app/app.go index 0211552..b55c6c3 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -6,17 +6,23 @@ import ( "github.com/urfave/cli/v2" "gitlab.com/gitlab-org/gitlab-releaser/internal/commands" + "gitlab.com/gitlab-org/gitlab-releaser/internal/flags" ) // New creates cli.App for the releaser CLI func New(version string) *cli.App { return &cli.App{ - Name: "gitlab-releaser", - Usage: "gitlab-releaser CLI", - UsageText: "gitlab-releaser COMMAND [OPTIONS...]", - ArgsUsage: "command [OPTIONS]", - Version: version, - Description: "gitlab-releaser is a CLI tool that can be used to interact with GitLab's Releases API", + Name: "gitlab-releaser", + Usage: "A CLI tool that interacts with GitLab's Releases API", + Version: version, + Description: ` +CLI tool that can be used to interact with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/. + +All configuration flags will default to GitLab's CI predefined environment variables. +For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html +If you would like to override these values please use the [GLOBAL OPTIONS]. + +For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser`, Commands: []*cli.Command{ commands.Create(), }, @@ -31,25 +37,22 @@ func New(version string) *cli.App { }, Flags: []cli.Flag{ &cli.StringFlag{ - Name: "gitlab-server-api-url", - Aliases: []string{"gs"}, - Usage: "GitLab server API V4 URL", + Name: flags.ServerURL, + Usage: "The base URL of the GitLab instance, including protocol and port e.g. https://gitlab.example.com:8080.", Required: true, - EnvVars: []string{"CI_API_V4_URL"}, + EnvVars: []string{"CI_SERVER_URL"}, Destination: nil, }, &cli.StringFlag{ - Name: "job-token", - Aliases: []string{"jt"}, - Usage: "Token used for authentication to the GitLab Releases API", + Name: flags.JobToken, + Usage: "Job token used for authenticating with the GitLab Releases API.", Required: true, EnvVars: []string{"CI_JOB_TOKEN"}, Destination: nil, }, &cli.StringFlag{ - Name: "project-id", - Aliases: []string{"id"}, - Usage: "Project ID in which to create the Release", + Name: flags.ProjectID, + Usage: "The unique id of the current project that GitLab CI uses internally.", Required: true, EnvVars: []string{"CI_PROJECT_ID"}, Destination: nil, diff --git a/internal/commands/create.go b/internal/commands/create.go index b63e7f3..592641b 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -10,6 +10,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" + "gitlab.com/gitlab-org/gitlab-releaser/internal/flags" "gitlab.com/gitlab-org/gitlab-releaser/internal/gitlab" ) @@ -23,41 +24,31 @@ func Create() *cli.Command { return &cli.Command{ Name: "create", - Aliases: []string{"c"}, - Usage: "Create a Release using GitLab's Releases API", - UsageText: "gitlab-release create [OPTIONS]", + Usage: "Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release.", Action: createRelease(httpClient), Subcommands: nil, Flags: []cli.Flag{ &cli.StringFlag{ - Name: "name", - Aliases: []string{"n"}, - Usage: "Name for this Release", - Required: true, - Destination: nil, + Name: flags.Name, + Usage: "The release name.", + Required: true, }, &cli.StringFlag{ - Name: "description", - Aliases: []string{"d"}, - Usage: "Description for this Release", - Required: true, - Destination: nil, + Name: flags.Description, + Usage: "The description of the release. You can use Markdown.", + Required: true, }, &cli.StringFlag{ - Name: "tag-name", - Aliases: []string{"tag"}, - Usage: "Tag name to use for this Release, ref will be used if not present", - Required: true, - EnvVars: []string{"CI_COMMIT_TAG"}, - Destination: nil, + Name: flags.TagName, + Usage: "The tag where the release will be created from.", + Required: true, + EnvVars: []string{"CI_COMMIT_TAG"}, }, &cli.StringFlag{ - Name: "ref", - Aliases: []string{"r"}, - Usage: "Reference name to use for this Release, only used if tag-name is not present", - Required: false, - EnvVars: []string{"CI_COMMIT_SHA"}, - Destination: nil, + Name: flags.Ref, + Usage: "If tag_name doesn’t exist, the release will be created from ref. It can be a commit SHA, another tag name, or a branch name.", + Required: false, + EnvVars: []string{"CI_COMMIT_SHA"}, }, }, } @@ -65,26 +56,27 @@ func Create() *cli.Command { func createRelease(httpClient *http.Client) cli.ActionFunc { return func(ctx *cli.Context) error { - id := ctx.String("id") - name := ctx.String("name") - description := ctx.String("description") - baseURL := ctx.String("gitlab-server-api-url") - token := ctx.String("token") - tagName := ctx.String("tag-name") - ref := ctx.String("ref") + id := ctx.String(flags.ProjectID) + name := ctx.String(flags.Name) + description := ctx.String(flags.Description) + serverURL := ctx.String(flags.ServerURL) + jobToken := ctx.String(flags.JobToken) + tagName := ctx.String(flags.TagName) + ref := ctx.String(flags.Ref) l := log.WithFields(log.Fields{ - "command": ctx.Command.Name, - "id": id, - "name": name, - "description": description, - "tag-name": tagName, - "ref": ref, + "command": ctx.Command.Name, + flags.ServerURL: serverURL, + flags.ProjectID: id, + flags.Name: name, + flags.Description: description, + flags.TagName: tagName, + flags.Ref: ref, }) l.Info("Creating Release...") - gitlabClient := gitlab.New(baseURL, token, id, httpClient) + gitlabClient := gitlab.New(serverURL, jobToken, id, httpClient) release, err := gitlabClient.CreateRelease(ctx.Context, &gitlab.CreateReleaseRequest{ ID: id, @@ -122,9 +114,5 @@ Released At: %s release.ReleasedAt, ) - for _, source := range release.Assets.Sources { - fmt.Fprintf(w, "%s - %s\n", source.Format, source.URL) - } - - fmt.Fprintf(w, "See all releases here: %s/-/releases\n", os.Getenv("CI_PROJECT_URL")) + fmt.Fprintf(w, "See all available releases here: %s/-/releases\n", os.Getenv("CI_PROJECT_URL")) } diff --git a/internal/flags/const.go b/internal/flags/const.go new file mode 100644 index 0000000..7f8f20e --- /dev/null +++ b/internal/flags/const.go @@ -0,0 +1,18 @@ +package flags + +const ( + // ServerURL available in the CLI context + ServerURL = "server-url" + // JobToken available in the CLI context + JobToken = "job-token" + // ProjectID available in the CLI context + ProjectID = "project-id" + // Name available in the CLI context + Name = "name" + // Description available in the CLI context + Description = "description" + // TagName available in the CLI context + TagName = "tag-name" + // Ref available in the CLI context + Ref = "ref" +) diff --git a/internal/gitlab/client.go b/internal/gitlab/client.go index 33c8eda..228bcc1 100644 --- a/internal/gitlab/client.go +++ b/internal/gitlab/client.go @@ -5,10 +5,13 @@ import ( "fmt" "io" "net/http" + "path" log "github.com/sirupsen/logrus" ) +const apiBaseURL = "api/v4/" + // ErrorResponse expected from the API type ErrorResponse struct { statusCode int @@ -40,9 +43,9 @@ type Client struct { } // New creates a new GitLab Client -func New(baseURL, token, projectID string, httpClient httpClient) *Client { +func New(serverURL, token, projectID string, httpClient httpClient) *Client { return &Client{ - baseURL: baseURL, + baseURL: path.Join(serverURL, apiBaseURL), token: token, projectID: projectID, httpClient: httpClient, @@ -51,7 +54,7 @@ func New(baseURL, token, projectID string, httpClient httpClient) *Client { // request creates a new request and attaches func (gc *Client) request(ctx context.Context, method, url string, body io.Reader) (*http.Request, error) { - req, err := http.NewRequest(method, gc.baseURL+url, body) + req, err := http.NewRequest(method, path.Join(gc.baseURL, url), body) if err != nil { return nil, err } diff --git a/internal/gitlab/client_test.go b/internal/gitlab/client_test.go index 0a031ac..18b238e 100644 --- a/internal/gitlab/client_test.go +++ b/internal/gitlab/client_test.go @@ -25,7 +25,7 @@ func TestClient_request(t *testing.T) { { name: "invalid_url", baseURL: "%", - wantErrMsg: "parse %%: invalid URL escape \"%%\"", + wantErrMsg: "invalid URL escape \"%/a\"", }, } for _, tt := range tests { @@ -33,7 +33,8 @@ func TestClient_request(t *testing.T) { gc := New(tt.baseURL, tt.token, tt.projectID, &mockHttpClient{}) got, err := gc.request(context.Background(), tt.method, tt.baseURL, nil) if tt.wantErrMsg != "" { - require.EqualError(t, err, tt.wantErrMsg) + require.NotNil(t, err) + require.Contains(t, err.Error(), tt.wantErrMsg) return } -- GitLab From 2706964fa171da7016eccd3e3100ca83c03619be Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 5 Mar 2020 16:19:30 +1100 Subject: [PATCH 05/29] Validate --server-url is a proper URL --- .gitlab-ci.yml | 119 ++++++++++++++++---------------- docs/README.md | 7 +- internal/commands/create.go | 5 +- internal/gitlab/client.go | 18 +++-- internal/gitlab/client_test.go | 7 +- internal/gitlab/release_test.go | 8 +-- 6 files changed, 88 insertions(+), 76 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8a68c8f..a835e6d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,11 +6,11 @@ cache: paths: - .go/pkg/mod/ -# -##include: -## - template: Security/License-Management.gitlab-ci.yml -## - template: Security/SAST.gitlab-ci.yml -# + +include: + - template: Security/License-Management.gitlab-ci.yml + - template: Security/SAST.gitlab-ci.yml + variables: GO: "1.13.8" # @@ -18,17 +18,17 @@ image: golang:${GO} # stages: - build -## - test -## - security + - test + - security - release-branch # for testing only -# -##license_management: -## stage: security -## -##sast: -## stage: security -# -# + +license_management: + stage: security + +sast: + stage: security + + build: extends: .go-cache stage: build @@ -40,55 +40,56 @@ build: paths: - ./bin/gitlab-releaser expire_in: 7 days -# -#test: -# extends: .go-cache -# stage: test -# script: -# - make test -# -#test-race: -# extends: .go-cache -# stage: test -# image: golang:${GO} -# variables: -# CGO_ENABLED: 1 -# script: -# - make test-race -# -#lint: -# extends: .go-cache -# image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine -# stage: test -# script: -# # Use default .golangci.yml file from the image if one is not present in the project root. -# - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' -# # Write the code coverage report to gl-code-quality-report.json -# # and print linting issues to stdout in the format: path/to/file:line description -# - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' -# artifacts: -# reports: -# codequality: gl-code-quality-report.json -# paths: -# - gl-code-quality-report.json -# expire_in: 7 days -# allow_failure: true -# -#cover: -# extends: .go-cache -# stage: test -# script: -# - make cover -# artifacts: -# paths: -# - cover/coverage.html -# expire_in: 7 days -# + +test: + extends: .go-cache + stage: test + script: + - make test + +test-race: + extends: .go-cache + stage: test + image: golang:${GO} + variables: + CGO_ENABLED: 1 + script: + - make test-race + +lint: + extends: .go-cache + image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine + stage: test + script: + # Use default .golangci.yml file from the image if one is not present in the project root. + - '[ -e .golangci.yml ] || cp /golangci/.golangci.yml .' + # Write the code coverage report to gl-code-quality-report.json + # and print linting issues to stdout in the format: path/to/file:line description + - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' + artifacts: + reports: + codequality: gl-code-quality-report.json + paths: + - gl-code-quality-report.json + expire_in: 7 days + allow_failure: true + +cover: + extends: .go-cache + stage: test + script: + - make cover + artifacts: + paths: + - cover/coverage.html + expire_in: 7 days + release-branch: stage: release-branch when: manual except: - master + - tags dependencies: - build script: diff --git a/docs/README.md b/docs/README.md index cf6b51d..0cc73dc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -80,9 +80,11 @@ This tool will be available to use when the new `release` section becomes availa https://gitlab.com/groups/gitlab-org/-/epics/2510 If you would like to try this on your project please add the following step to your `.gitlab-ci.yml` + *NOTE* this is still under development. Please report any new issues in https://gitlab.com/gitlab-org/gitlab-releaser/issues -*NOTE* https://gitlab.com/gitlab-org/gitlab/issues/16290 when a tag is created, a new pipeline will run. -To avoid some steps running in an infinite loop please add the `execpt: tags` rule to the jobs you don't want to run. + +*NOTE* this issue https://gitlab.com/gitlab-org/gitlab/issues/16290 when a tag is created, a new pipeline will run. +To avoid some steps running in an infinite loop please add the `except: tags` rule to the jobs you don't want to run. ```yaml release-branch: @@ -90,6 +92,7 @@ release-branch: when: manual except: - master + - tags dependencies: - build script: diff --git a/internal/commands/create.go b/internal/commands/create.go index 592641b..d3cb63c 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -76,7 +76,10 @@ func createRelease(httpClient *http.Client) cli.ActionFunc { l.Info("Creating Release...") - gitlabClient := gitlab.New(serverURL, jobToken, id, httpClient) + gitlabClient, err := gitlab.New(serverURL, jobToken, id, httpClient) + if err != nil { + return fmt.Errorf("failed to create GitLab client: %w", err) + } release, err := gitlabClient.CreateRelease(ctx.Context, &gitlab.CreateReleaseRequest{ ID: id, diff --git a/internal/gitlab/client.go b/internal/gitlab/client.go index 228bcc1..eb57a8f 100644 --- a/internal/gitlab/client.go +++ b/internal/gitlab/client.go @@ -5,12 +5,13 @@ import ( "fmt" "io" "net/http" + "net/url" "path" log "github.com/sirupsen/logrus" ) -const apiBaseURL = "api/v4/" +const apiBaseURL = "/api/v4/" // ErrorResponse expected from the API type ErrorResponse struct { @@ -43,18 +44,25 @@ type Client struct { } // New creates a new GitLab Client -func New(serverURL, token, projectID string, httpClient httpClient) *Client { +func New(serverURL, token, projectID string, httpClient httpClient) (*Client, error) { + u, err := url.Parse(serverURL) + if err != nil { + return nil, fmt.Errorf("failed to parse url: %w", err) + } + + u.Path = path.Join(u.Path, apiBaseURL) + return &Client{ - baseURL: path.Join(serverURL, apiBaseURL), + baseURL: u.String(), token: token, projectID: projectID, httpClient: httpClient, - } + }, nil } // request creates a new request and attaches func (gc *Client) request(ctx context.Context, method, url string, body io.Reader) (*http.Request, error) { - req, err := http.NewRequest(method, path.Join(gc.baseURL, url), body) + req, err := http.NewRequest(method, gc.baseURL+url, body) if err != nil { return nil, err } diff --git a/internal/gitlab/client_test.go b/internal/gitlab/client_test.go index 18b238e..d4b9783 100644 --- a/internal/gitlab/client_test.go +++ b/internal/gitlab/client_test.go @@ -25,18 +25,19 @@ func TestClient_request(t *testing.T) { { name: "invalid_url", baseURL: "%", - wantErrMsg: "invalid URL escape \"%/a\"", + wantErrMsg: "invalid URL escape \"%\"", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - gc := New(tt.baseURL, tt.token, tt.projectID, &mockHttpClient{}) - got, err := gc.request(context.Background(), tt.method, tt.baseURL, nil) + gc, err := New(tt.baseURL, tt.token, tt.projectID, &mockHttpClient{}) if tt.wantErrMsg != "" { require.NotNil(t, err) require.Contains(t, err.Error(), tt.wantErrMsg) return } + got, err := gc.request(context.Background(), tt.method, tt.baseURL, nil) + require.NoError(t, err) require.NoError(t, err) require.NotNil(t, got) diff --git a/internal/gitlab/release_test.go b/internal/gitlab/release_test.go index 3fa840c..22fa1f5 100644 --- a/internal/gitlab/release_test.go +++ b/internal/gitlab/release_test.go @@ -111,11 +111,6 @@ func TestClient_CreateRelease_NonAPIErrors(t *testing.T) { resBody string wantErrMsg string }{ - { - name: "invalid_url", - baseURL: "%", - wantErrMsg: "failed to create request:", - }, { name: "failed_to_call_api", err: fmt.Errorf("something went wrong"), @@ -143,7 +138,8 @@ func TestClient_CreateRelease_NonAPIErrors(t *testing.T) { t.Run(tt.name, func(t *testing.T) { mhc := &mockHttpClient{} mhc.On("Do", mock.Anything).Return(tt.res, tt.err).Once() - client := New(tt.baseURL, "token", "projectID", mhc) + client, err := New(tt.baseURL, "token", "projectID", mhc) + require.NoError(t, err) res, err := client.CreateRelease(context.Background(), &CreateReleaseRequest{}) require.Nil(t, res) -- GitLab From e08678c8bdb550faadc7e964a837ec86eab7b999 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 5 Mar 2020 16:53:36 +1100 Subject: [PATCH 06/29] Formatting and docs reference --- .gitlab-ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a835e6d..2b66043 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,14 +13,14 @@ include: variables: GO: "1.13.8" -# + image: golang:${GO} -# + stages: - build - test - security - - release-branch # for testing only + - release-branch # for testing only see docs/README.md license_management: stage: security @@ -28,7 +28,6 @@ license_management: sast: stage: security - build: extends: .go-cache stage: build -- GitLab From fcb37c7102c99d89e93a11fc32598529e28b603c Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Tue, 10 Mar 2020 12:05:06 +1100 Subject: [PATCH 07/29] Use correct interface in create command --- internal/commands/create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/commands/create.go b/internal/commands/create.go index d3cb63c..318fb5a 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -54,7 +54,7 @@ func Create() *cli.Command { } } -func createRelease(httpClient *http.Client) cli.ActionFunc { +func createRelease(httpClient gitlab.HTTPClient) cli.ActionFunc { return func(ctx *cli.Context) error { id := ctx.String(flags.ProjectID) name := ctx.String(flags.Name) -- GitLab From e5dd42465c1c53e276e463bd09411298ebce91d4 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 12 Mar 2020 14:19:56 +1100 Subject: [PATCH 08/29] Improve documentation with better URLs Applied feedback from !6. Added references in CLI usage. Added better resources and improved some Markdown formatting, especifically with adding **notes**. --- .gitlab-ci.yml | 12 ------------ docs/README.md | 20 ++++++++++---------- internal/app/app.go | 2 +- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b66043..2749298 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,7 +20,6 @@ stages: - build - test - security - - release-branch # for testing only see docs/README.md license_management: stage: security @@ -82,14 +81,3 @@ cover: paths: - cover/coverage.html expire_in: 7 days - -release-branch: - stage: release-branch - when: manual - except: - - master - - tags - dependencies: - - build - script: - - ./bin/gitlab-releaser create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA diff --git a/docs/README.md b/docs/README.md index 0cc73dc..d9e6b7d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # GitLab Releaser CLI documentation -gitlab-releaser is a CLI tool that can be used to interact with GitLab's Releases API. +`gitlab-releaser` is a CLI tool that can be used to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) ## Usage @@ -43,10 +43,9 @@ GLOBAL OPTIONS: ## Configuration -All configuration flags will default to GitLab's CI predefined environment variables. -For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html -If you would like to override these values please use the [GLOBAL OPTIONS]. +All configuration flags will default to [GitLab's CI predefined environment variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). +If you would like to override these values please use the flags available under the `GLOBAL OPTIONS`. e.g. to create a release with a custom GitLab server URL ```shell script @@ -81,21 +80,22 @@ https://gitlab.com/groups/gitlab-org/-/epics/2510 If you would like to try this on your project please add the following step to your `.gitlab-ci.yml` -*NOTE* this is still under development. Please report any new issues in https://gitlab.com/gitlab-org/gitlab-releaser/issues +NOTE: **Note:** +`gitlab-releaser` is still under development. Please report any new issues [here](https://gitlab.com/gitlab-org/gitlab-releaser/issues) -*NOTE* this issue https://gitlab.com/gitlab-org/gitlab/issues/16290 when a tag is created, a new pipeline will run. -To avoid some steps running in an infinite loop please add the `except: tags` rule to the jobs you don't want to run. +NOTE: **Note** +A new pipeline will run when a new tag is created. +We recommend adding the `except: tags` to avoid certain pipelines running when this happens. +See this [issue](https://gitlab.com/gitlab-org/gitlab/issues/16290) for more details. ```yaml release-branch: - stage: release-branch + stage: release when: manual except: - - master - tags dependencies: - build script: - ./bin/gitlab-releaser create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA - ``` diff --git a/internal/app/app.go b/internal/app/app.go index b55c6c3..f70501a 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -22,7 +22,7 @@ All configuration flags will default to GitLab's CI predefined environment varia For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html If you would like to override these values please use the [GLOBAL OPTIONS]. -For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser`, +For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser/-/blob/master/docs/README.md`, Commands: []*cli.Command{ commands.Create(), }, -- GitLab From 1a38cd5eb1b64b2e5b233bcd81323a62a53e2295 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 12 Mar 2020 14:20:29 +1100 Subject: [PATCH 09/29] Improve readability of code and tests Make the `createRelease` function independent of `cli.ActionFunc`. Move assertions in the client test to a more accurate place. --- internal/commands/create.go | 92 +++++++++++++++++----------------- internal/gitlab/client_test.go | 4 +- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/internal/commands/create.go b/internal/commands/create.go index 318fb5a..e37696e 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -23,9 +23,11 @@ func Create() *cli.Command { } return &cli.Command{ - Name: "create", - Usage: "Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release.", - Action: createRelease(httpClient), + Name: "create", + Usage: "Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release.", + Action: func(ctx *cli.Context) error { + return createRelease(ctx, httpClient) + }, Subcommands: nil, Flags: []cli.Flag{ &cli.StringFlag{ @@ -54,50 +56,48 @@ func Create() *cli.Command { } } -func createRelease(httpClient gitlab.HTTPClient) cli.ActionFunc { - return func(ctx *cli.Context) error { - id := ctx.String(flags.ProjectID) - name := ctx.String(flags.Name) - description := ctx.String(flags.Description) - serverURL := ctx.String(flags.ServerURL) - jobToken := ctx.String(flags.JobToken) - tagName := ctx.String(flags.TagName) - ref := ctx.String(flags.Ref) - - l := log.WithFields(log.Fields{ - "command": ctx.Command.Name, - flags.ServerURL: serverURL, - flags.ProjectID: id, - flags.Name: name, - flags.Description: description, - flags.TagName: tagName, - flags.Ref: ref, - }) - - l.Info("Creating Release...") - - gitlabClient, err := gitlab.New(serverURL, jobToken, id, httpClient) - if err != nil { - return fmt.Errorf("failed to create GitLab client: %w", err) - } - - release, err := gitlabClient.CreateRelease(ctx.Context, &gitlab.CreateReleaseRequest{ - ID: id, - Name: name, - Description: description, - TagName: tagName, - Ref: ref, - }) - if err != nil { - return fmt.Errorf("failed to create release: %w", err) - } - - printReleaseOutput(ctx.App.Writer, release) - - l.Info("release created successfully!") - - return nil +func createRelease(ctx *cli.Context, httpClient gitlab.HTTPClient) error { + projectID := ctx.String(flags.ProjectID) + name := ctx.String(flags.Name) + description := ctx.String(flags.Description) + serverURL := ctx.String(flags.ServerURL) + jobToken := ctx.String(flags.JobToken) + tagName := ctx.String(flags.TagName) + ref := ctx.String(flags.Ref) + + l := log.WithFields(log.Fields{ + "command": ctx.Command.Name, + flags.ServerURL: serverURL, + flags.ProjectID: projectID, + flags.Name: name, + flags.Description: description, + flags.TagName: tagName, + flags.Ref: ref, + }) + + l.Info("Creating Release...") + + gitlabClient, err := gitlab.New(serverURL, jobToken, projectID, httpClient) + if err != nil { + return fmt.Errorf("failed to create GitLab client: %w", err) + } + + release, err := gitlabClient.CreateRelease(ctx.Context, &gitlab.CreateReleaseRequest{ + ID: projectID, + Name: name, + Description: description, + TagName: tagName, + Ref: ref, + }) + if err != nil { + return fmt.Errorf("failed to create release: %w", err) } + + printReleaseOutput(ctx.App.Writer, release) + + l.Info("release created successfully!") + + return nil } func printReleaseOutput(w io.Writer, release *gitlab.CreateReleaseResponse) { diff --git a/internal/gitlab/client_test.go b/internal/gitlab/client_test.go index e82b43f..3ecefbe 100644 --- a/internal/gitlab/client_test.go +++ b/internal/gitlab/client_test.go @@ -31,16 +31,16 @@ func TestClient_request(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { gc, err := New(tt.baseURL, tt.token, tt.projectID, &MockHTTPClient{}) - if tt.wantErrMsg != "" { require.NotNil(t, err) require.Contains(t, err.Error(), tt.wantErrMsg) return } - got, err := gc.request(context.Background(), tt.method, tt.baseURL, nil) require.NoError(t, err) + got, err := gc.request(context.Background(), tt.method, tt.baseURL, nil) require.NoError(t, err) + require.NotNil(t, got) require.Equal(t, got.Header.Get("JOB-TOKEN"), tt.token) require.Equal(t, got.Header.Get("Content-Type"), "application/json") -- GitLab From 5216a908d1f48f4a4f6926e9937ded0928483b55 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Mon, 16 Mar 2020 12:59:17 +1100 Subject: [PATCH 10/29] Improve documentation output for help command --- docs/README.md | 67 ++++++++++++++++++------------------- internal/app/app.go | 32 ++++++++++++------ internal/commands/create.go | 10 +++--- 3 files changed, 59 insertions(+), 50 deletions(-) diff --git a/docs/README.md b/docs/README.md index d9e6b7d..1f89ecf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,43 +1,43 @@ -# GitLab Releaser CLI documentation +# gitlab-releaser command-line tool -`gitlab-releaser` is a CLI tool that can be used to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) +`gitlab-releaser` is a command-line tool that you can use to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) ## Usage -```shell script +```shell $ gitlab-releaser help + NAME: gitlab-releaser - A CLI tool that interacts with GitLab's Releases API USAGE: - gitlab-releaser [global options] command [command options] [arguments...] + help [global options] command [command options] [arguments...] VERSION: - 0.0.1~beta.17.g14e5c2a + 0.0.1~beta.6.g1a38cd5 DESCRIPTION: -CLI tool that can be used to interact with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/. +CLI tool that interacts with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/. -All configuration flags will default to GitLab's CI predefined environment variables. -For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html -If you would like to override these values please use the [GLOBAL OPTIONS]. +All configuration flags will default to GitLab's CI predefined environment variables (https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). +To override these values, use the [GLOBAL OPTIONS]. -For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser +Get started with gitlab-releaser https://gitlab.com/gitlab-org/gitlab-releaser. AUTHOR: GitLab Inc. COMMANDS: - create, c Create a Release using GitLab's Releases API - help, h Shows a list of commands or help for one command + create Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release + help, h Shows a list of commands or help for one command GLOBAL OPTIONS: - --server-url value The base URL of the GitLab instance, including protocol and port e.g. https://gitlab.example.com:8080. [$CI_SERVER_URL] - --job-token value Token used for authenticating with the GitLab Releases API. [$CI_JOB_TOKEN] - --project-id value The unique id of the current project that GitLab CI uses internally. [$CI_PROJECT_ID] - --help, -h show help (default: false) - --version, -v print the version (default: false) + --server-url value The base URL of the GitLab instance, including protocol and port, for example https://gitlab.example.com:8080 [$CI_SERVER_URL] + --job-token value Job token used for authenticating with the GitLab Releases API [$CI_JOB_TOKEN] + --project-id value The current project's unique ID; used by GitLab CI internally [$CI_PROJECT_ID] + --help, -h Show help (default: false) + --version, -v Print the version (default: false) ``` @@ -45,43 +45,42 @@ GLOBAL OPTIONS: All configuration flags will default to [GitLab's CI predefined environment variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). -If you would like to override these values please use the flags available under the `GLOBAL OPTIONS`. -e.g. to create a release with a custom GitLab server URL +To override these values, use the flags available under the `GLOBAL OPTIONS`. +For example, use the flags to create a release with a custom GitLab server URL. -```shell script -gitlab-releaser -server-url https://gitlab.mydomain.com create -name "My Release" -description "THis is a new release for my amazing tool" +```shell +gitlab-releaser -server-url https://gitlab.mydomain.com create -name "My Release" -description "This is a new release for my amazing tool" ``` ## Create a new release -See [Create a Release](https://docs.gitlab.com/ee/api/releases/) API +This command uses the [Create a Release](https://docs.gitlab.com/ee/api/releases/) API. -```shell script +```shell $ gitlab-releaser --server-url https://gitlab.com --job-token=SOME_JOB_TOKEN --project-id 12345 create help NAME: - gitlab-releaser create - Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release. + help create - Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release USAGE: - gitlab-releaser create [command options] [arguments...] + help create [command options] [arguments...] OPTIONS: - --name value The release name. - --description value The description of the release. You can use Markdown. - --tag-name value The tag where the release will be created from. [$CI_COMMIT_TAG] - --ref value If tag_name doesn’t exist, the release will be created from ref. It can be a commit SHA, another tag name, or a branch name. [$CI_COMMIT_SHA] - --help, -h show help (default: false) + --name value The release name + --description value The description of the release, you can use Markdown + --tag-name value The tag the release will be created from [$CI_COMMIT_TAG] + --ref value If tag_name doesn’t exist, the release will be created from ref; it can be a commit SHA, another tag name, or a branch name [$CI_COMMIT_SHA] + --help, -h Show help (default: false) ``` ## Using this tool in GitLab CI -This tool will be available to use when the new `release` section becomes available in `.gitlab-ci.yml` -https://gitlab.com/groups/gitlab-org/-/epics/2510 +The `gitlab-releaser` tool will be available when [the new `release` section becomes available in `.gitlab-ci.yml`](https://gitlab.com/groups/gitlab-org/-/epics/2510). -If you would like to try this on your project please add the following step to your `.gitlab-ci.yml` +If you would like to try `gitlab-releaser` on your project, add the following step to your `.gitlab-ci.yml`. NOTE: **Note:** -`gitlab-releaser` is still under development. Please report any new issues [here](https://gitlab.com/gitlab-org/gitlab-releaser/issues) +`gitlab-releaser` is still under development. Please report any new issues [here](https://gitlab.com/gitlab-org/gitlab-releaser/issues). NOTE: **Note** A new pipeline will run when a new tag is created. diff --git a/internal/app/app.go b/internal/app/app.go index f70501a..4d12186 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -11,18 +11,28 @@ import ( // New creates cli.App for the releaser CLI func New(version string) *cli.App { + cli.HelpFlag = &cli.BoolFlag{ + Name: "help", Aliases: []string{"h"}, + Usage: "Show help", + } + cli.VersionFlag = &cli.BoolFlag{ + Name: "version", Aliases: []string{"v"}, + Usage: "Print the version", + } + return &cli.App{ - Name: "gitlab-releaser", - Usage: "A CLI tool that interacts with GitLab's Releases API", - Version: version, + Name: "gitlab-releaser", + Usage: "A CLI tool that interacts with GitLab's Releases API", + Version: version, + HelpName: "help", Description: ` -CLI tool that can be used to interact with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/. +CLI tool that interacts with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/. + +All configuration flags will default to GitLab's CI predefined environment variables (https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). +To override these values, use the [GLOBAL OPTIONS]. -All configuration flags will default to GitLab's CI predefined environment variables. -For more information please visit https://docs.gitlab.com/ee/ci/variables/predefined_variables.html -If you would like to override these values please use the [GLOBAL OPTIONS]. +Get started with gitlab-releaser https://gitlab.com/gitlab-org/gitlab-releaser.`, -For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser/-/blob/master/docs/README.md`, Commands: []*cli.Command{ commands.Create(), }, @@ -38,21 +48,21 @@ For more information please visit https://gitlab.com/gitlab-org/gitlab-releaser/ Flags: []cli.Flag{ &cli.StringFlag{ Name: flags.ServerURL, - Usage: "The base URL of the GitLab instance, including protocol and port e.g. https://gitlab.example.com:8080.", + Usage: "The base URL of the GitLab instance, including protocol and port, for example https://gitlab.example.com:8080", Required: true, EnvVars: []string{"CI_SERVER_URL"}, Destination: nil, }, &cli.StringFlag{ Name: flags.JobToken, - Usage: "Job token used for authenticating with the GitLab Releases API.", + Usage: "Job token used for authenticating with the GitLab Releases API", Required: true, EnvVars: []string{"CI_JOB_TOKEN"}, Destination: nil, }, &cli.StringFlag{ Name: flags.ProjectID, - Usage: "The unique id of the current project that GitLab CI uses internally.", + Usage: "The current project's unique ID; used by GitLab CI internally", Required: true, EnvVars: []string{"CI_PROJECT_ID"}, Destination: nil, diff --git a/internal/commands/create.go b/internal/commands/create.go index e37696e..2a56dc5 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -24,7 +24,7 @@ func Create() *cli.Command { return &cli.Command{ Name: "create", - Usage: "Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release.", + Usage: "Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release", Action: func(ctx *cli.Context) error { return createRelease(ctx, httpClient) }, @@ -32,23 +32,23 @@ func Create() *cli.Command { Flags: []cli.Flag{ &cli.StringFlag{ Name: flags.Name, - Usage: "The release name.", + Usage: "The release name", Required: true, }, &cli.StringFlag{ Name: flags.Description, - Usage: "The description of the release. You can use Markdown.", + Usage: "The description of the release, you can use Markdown", Required: true, }, &cli.StringFlag{ Name: flags.TagName, - Usage: "The tag where the release will be created from.", + Usage: "The tag the release will be created from", Required: true, EnvVars: []string{"CI_COMMIT_TAG"}, }, &cli.StringFlag{ Name: flags.Ref, - Usage: "If tag_name doesn’t exist, the release will be created from ref. It can be a commit SHA, another tag name, or a branch name.", + Usage: "If tag_name doesn’t exist, the release will be created from ref; it can be a commit SHA, another tag name, or a branch name", Required: false, EnvVars: []string{"CI_COMMIT_SHA"}, }, -- GitLab From abe355106330e36777ff04694b0450b30889534e Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Wed, 18 Mar 2020 11:01:12 +1100 Subject: [PATCH 11/29] Update notes section in documentation --- docs/README.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1f89ecf..0fbc51e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -78,14 +78,6 @@ OPTIONS: The `gitlab-releaser` tool will be available when [the new `release` section becomes available in `.gitlab-ci.yml`](https://gitlab.com/groups/gitlab-org/-/epics/2510). If you would like to try `gitlab-releaser` on your project, add the following step to your `.gitlab-ci.yml`. - -NOTE: **Note:** -`gitlab-releaser` is still under development. Please report any new issues [here](https://gitlab.com/gitlab-org/gitlab-releaser/issues). - -NOTE: **Note** -A new pipeline will run when a new tag is created. -We recommend adding the `except: tags` to avoid certain pipelines running when this happens. -See this [issue](https://gitlab.com/gitlab-org/gitlab/issues/16290) for more details. ```yaml release-branch: @@ -98,3 +90,9 @@ release-branch: script: - ./bin/gitlab-releaser create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA ``` + +### Notes + +* `gitlab-releaser` is still under development. Please report any new issues [here](https://gitlab.com/gitlab-org/gitlab-releaser/issues). + +* A new pipeline will run when [a new tag is created](https://gitlab.com/gitlab-org/gitlab/issues/16290). We recommend adding `except: tags` to your job to avoid certain pipelines running when this happens. -- GitLab From 305f2fd442578398acc36053b279c10e0659c71d Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 19 Mar 2020 11:27:45 +1100 Subject: [PATCH 12/29] Update documuentation from review notes --- docs/{README.md => index.md} | 89 +++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 21 deletions(-) rename docs/{README.md => index.md} (56%) diff --git a/docs/README.md b/docs/index.md similarity index 56% rename from docs/README.md rename to docs/index.md index 0fbc51e..762ebfd 100644 --- a/docs/README.md +++ b/docs/index.md @@ -1,12 +1,57 @@ -# gitlab-releaser command-line tool +# GitLab Releaser command-line tool -`gitlab-releaser` is a command-line tool that you can use to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) +GitLab Releaser is a command-line tool that you can use to interact with +[GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html). + +It consumes instructions in the `:release` node of the `.gitlab-ci.yml` to create a Release object in GitLab Rails. +GitLab Releaser is a CLI application written in [Golang](https://golang.org/). + +The GitLab Releaser is a decoupled utility that may be called by the GitLab Runner, +by a third-party CI or directly from the command-line. +It uses the CI `Job-Token` to authorize against the GitLab Rails API, which is passed to it by the GitLab Runner. + +The CLI can also be called independently, and can still create the Release via Rails API +if the `Job-Token` and correct command line params are provided. + + +```mermaid +sequenceDiagram + participant Rails + participant ReleaseCLI + participant Runner + Runner->>Rails: 1. Runner calls API for job info + Rails->>Rails : 2. Yaml exposed as Steps + Runner->>ReleaseCLI : 3. Runner calls CLI on Job success + ReleaseCLI->>Rails : 4. CLI retrieves Release Steps + ReleaseCLI->>Rails : 5. CLI creates Release +``` + +###### 1. Runner calls API for job info + +The Runner polls Rails for new Jobs. + +###### 2. Yaml exposed as Steps + +The `release` node of the `.gitlab-ci.yaml` configuration is converted into **Steps** and made available via API endpoint. + +###### 3. Runner calls GitLab Releaser on Job success + +The Runner executes the Job, and upon success calls the **GitLab Releaser**. + +###### 4. GitLab Releaser retrieves Release Steps + +The GitLab Releaser calls the Rails API to retrieve the `release` configuration (as Steps). + +###### 5. GitLab Releaser creates Release + +The GitLab Releaser makes an API call to Rails to create the Release. ## Usage -```shell -$ gitlab-releaser help +To get started, open your project in a terminal and run `gitlab-releaser help` +for usage options. The output will be: +```shell NAME: gitlab-releaser - A CLI tool that interacts with GitLab's Releases API @@ -40,20 +85,7 @@ GLOBAL OPTIONS: --version, -v Print the version (default: false) ``` - -## Configuration - -All configuration flags will default to [GitLab's CI predefined environment variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). - -To override these values, use the flags available under the `GLOBAL OPTIONS`. -For example, use the flags to create a release with a custom GitLab server URL. - -```shell -gitlab-releaser -server-url https://gitlab.mydomain.com create -name "My Release" -description "This is a new release for my amazing tool" -``` - - -## Create a new release +### Create a new release This command uses the [Create a Release](https://docs.gitlab.com/ee/api/releases/) API. @@ -73,16 +105,29 @@ OPTIONS: --help, -h Show help (default: false) ``` +## Configuration + +All configuration flags will default to [GitLab's CI predefined environment variables](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). + +To override these values, use the flags available under the `GLOBAL OPTIONS`. +For example, use the flags to create a release with a custom GitLab server URL. + +```shell +gitlab-releaser -server-url https://gitlab.mydomain.com create -name "My Release" -description "This is a new release for my amazing tool" +``` + ## Using this tool in GitLab CI The `gitlab-releaser` tool will be available when [the new `release` section becomes available in `.gitlab-ci.yml`](https://gitlab.com/groups/gitlab-org/-/epics/2510). -If you would like to try `gitlab-releaser` on your project, add the following step to your `.gitlab-ci.yml`. +If you would like to try GitLab Releaser on your project, add the following `script` to your `.gitlab-ci.yml` file: ```yaml release-branch: stage: release when: manual + # We recommend the use of `except: tags` to prevent these pipelines + # from running. See the notes section below for details. except: - tags dependencies: @@ -93,6 +138,8 @@ release-branch: ### Notes -* `gitlab-releaser` is still under development. Please report any new issues [here](https://gitlab.com/gitlab-org/gitlab-releaser/issues). +* GitLab Releaser is still under development. Please report any issues in its project [issue tracker](https://gitlab.com/gitlab-org/gitlab-releaser/issues). -* A new pipeline will run when [a new tag is created](https://gitlab.com/gitlab-org/gitlab/issues/16290). We recommend adding `except: tags` to your job to avoid certain pipelines running when this happens. +* A new pipeline will run when [a new tag is created](https://gitlab.com/gitlab-org/gitlab/issues/16290). +We recommend adding `except: tags` to your job to prevent these pipelines from +running concurrently with `gitlab-releaser`. -- GitLab From d10bdfec550235e591fabb6d646fcb2bb50ca139 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:24:14 +0000 Subject: [PATCH 13/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 762ebfd..0a64581 100644 --- a/docs/index.md +++ b/docs/index.md @@ -140,6 +140,6 @@ release-branch: * GitLab Releaser is still under development. Please report any issues in its project [issue tracker](https://gitlab.com/gitlab-org/gitlab-releaser/issues). -* A new pipeline will run when [a new tag is created](https://gitlab.com/gitlab-org/gitlab/issues/16290). +- A new pipeline will run when [a new tag is created](https://gitlab.com/gitlab-org/gitlab/issues/16290). We recommend adding `except: tags` to your job to prevent these pipelines from running concurrently with `gitlab-releaser`. -- GitLab From 3a525eaa7ddd7e1c44ee0a876d0c2b73c8f31752 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:24:32 +0000 Subject: [PATCH 14/29] Apply suggestion to docs/index.md --- docs/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 0a64581..419dcff 100644 --- a/docs/index.md +++ b/docs/index.md @@ -138,7 +138,8 @@ release-branch: ### Notes -* GitLab Releaser is still under development. Please report any issues in its project [issue tracker](https://gitlab.com/gitlab-org/gitlab-releaser/issues). +- GitLab Releaser is still under development. Please report any issues in +its project [issue tracker](https://gitlab.com/gitlab-org/gitlab-releaser/issues). - A new pipeline will run when [a new tag is created](https://gitlab.com/gitlab-org/gitlab/issues/16290). We recommend adding `except: tags` to your job to prevent these pipelines from -- GitLab From 5b9955140be2f223573f6d44b1dbfd6dcdf2cf49 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:25:31 +0000 Subject: [PATCH 15/29] Apply suggestion to docs/index.md --- docs/index.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 419dcff..ae8a70e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -90,7 +90,12 @@ GLOBAL OPTIONS: This command uses the [Create a Release](https://docs.gitlab.com/ee/api/releases/) API. ```shell -$ gitlab-releaser --server-url https://gitlab.com --job-token=SOME_JOB_TOKEN --project-id 12345 create help +gitlab-releaser --server-url https://gitlab.com --job-token=SOME_JOB_TOKEN --project-id 12345 create help +``` + +The output is: + +```shell NAME: help create - Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release -- GitLab From 296542ecdd77518976ccd4be26d7dcf6d3b4b1e7 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:25:55 +0000 Subject: [PATCH 16/29] Apply suggestion to docs/index.md --- docs/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index ae8a70e..3f90484 100644 --- a/docs/index.md +++ b/docs/index.md @@ -44,8 +44,6 @@ The GitLab Releaser calls the Rails API to retrieve the `release` configuration ###### 5. GitLab Releaser creates Release -The GitLab Releaser makes an API call to Rails to create the Release. - ## Usage To get started, open your project in a terminal and run `gitlab-releaser help` -- GitLab From 99a4744da14276ab3fb6dd356859b54a7f5dffaf Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:26:04 +0000 Subject: [PATCH 17/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 3f90484..df7ca8b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -42,7 +42,7 @@ The Runner executes the Job, and upon success calls the **GitLab Releaser**. The GitLab Releaser calls the Rails API to retrieve the `release` configuration (as Steps). -###### 5. GitLab Releaser creates Release +1. GitLab Releaser creates a Release: the GitLab Releaser makes an API call to Rails to create the new Release. ## Usage -- GitLab From 6bf0d7af18b6d51dd739bb3d1188676798723e7f Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:26:18 +0000 Subject: [PATCH 18/29] Apply suggestion to docs/index.md --- docs/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index df7ca8b..8173842 100644 --- a/docs/index.md +++ b/docs/index.md @@ -40,8 +40,6 @@ The Runner executes the Job, and upon success calls the **GitLab Releaser**. ###### 4. GitLab Releaser retrieves Release Steps -The GitLab Releaser calls the Rails API to retrieve the `release` configuration (as Steps). - 1. GitLab Releaser creates a Release: the GitLab Releaser makes an API call to Rails to create the new Release. ## Usage -- GitLab From 94262cdccbc08fff0df7c8b0db9fac74d80a3332 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:26:32 +0000 Subject: [PATCH 19/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 8173842..b2abf7e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -38,7 +38,7 @@ The `release` node of the `.gitlab-ci.yaml` configuration is converted into **St The Runner executes the Job, and upon success calls the **GitLab Releaser**. -###### 4. GitLab Releaser retrieves Release Steps +1. GitLab Releaser retrieves Release **Steps**: the GitLab Releaser calls the Rails API to retrieve the `release` configuration (as **Steps**). 1. GitLab Releaser creates a Release: the GitLab Releaser makes an API call to Rails to create the new Release. -- GitLab From 7844e8e074251cadd0a9b54c2149671a490359e5 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:26:40 +0000 Subject: [PATCH 20/29] Apply suggestion to docs/index.md --- docs/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index b2abf7e..905803d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -36,8 +36,6 @@ The `release` node of the `.gitlab-ci.yaml` configuration is converted into **St ###### 3. Runner calls GitLab Releaser on Job success -The Runner executes the Job, and upon success calls the **GitLab Releaser**. - 1. GitLab Releaser retrieves Release **Steps**: the GitLab Releaser calls the Rails API to retrieve the `release` configuration (as **Steps**). 1. GitLab Releaser creates a Release: the GitLab Releaser makes an API call to Rails to create the new Release. -- GitLab From 78af6442a4476e0c513e73d0acb7cafd6673c540 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:26:56 +0000 Subject: [PATCH 21/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 905803d..e534799 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,7 @@ The Runner polls Rails for new Jobs. The `release` node of the `.gitlab-ci.yaml` configuration is converted into **Steps** and made available via API endpoint. -###### 3. Runner calls GitLab Releaser on Job success +1. The Runner calls GitLab Releaser: the Runner executes the job, and upon success calls the **GitLab Releaser**. 1. GitLab Releaser retrieves Release **Steps**: the GitLab Releaser calls the Rails API to retrieve the `release` configuration (as **Steps**). -- GitLab From d973152af7b95616be2ebcb4372411888fdaa91f Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:27:09 +0000 Subject: [PATCH 22/29] Apply suggestion to docs/index.md --- docs/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index e534799..01c3225 100644 --- a/docs/index.md +++ b/docs/index.md @@ -32,8 +32,6 @@ The Runner polls Rails for new Jobs. ###### 2. Yaml exposed as Steps -The `release` node of the `.gitlab-ci.yaml` configuration is converted into **Steps** and made available via API endpoint. - 1. The Runner calls GitLab Releaser: the Runner executes the job, and upon success calls the **GitLab Releaser**. 1. GitLab Releaser retrieves Release **Steps**: the GitLab Releaser calls the Rails API to retrieve the `release` configuration (as **Steps**). -- GitLab From 1b09426c792b6e82cbf311e0806306683028bbd9 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:27:17 +0000 Subject: [PATCH 23/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 01c3225..7be3b1d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -30,7 +30,7 @@ sequenceDiagram The Runner polls Rails for new Jobs. -###### 2. Yaml exposed as Steps +1. Yaml exposed as **Steps**: The `release` node of the `.gitlab-ci.yml` configuration is converted into **Steps** and made available via API endpoint. 1. The Runner calls GitLab Releaser: the Runner executes the job, and upon success calls the **GitLab Releaser**. -- GitLab From dcfe43a82e5f9caa6ec506ce43de53f073dc8777 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:28:05 +0000 Subject: [PATCH 24/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 7be3b1d..733be18 100644 --- a/docs/index.md +++ b/docs/index.md @@ -26,7 +26,7 @@ sequenceDiagram ReleaseCLI->>Rails : 5. CLI creates Release ``` -###### 1. Runner calls API for job info +1. Runner calls API for job info: the Runner polls Rails for new Jobs. The Runner polls Rails for new Jobs. -- GitLab From 77474d2111e8db0d7cc147e1b8b69a6a114cb0c8 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:28:08 +0000 Subject: [PATCH 25/29] Apply suggestion to docs/index.md --- docs/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 733be18..7edab40 100644 --- a/docs/index.md +++ b/docs/index.md @@ -28,8 +28,6 @@ sequenceDiagram 1. Runner calls API for job info: the Runner polls Rails for new Jobs. -The Runner polls Rails for new Jobs. - 1. Yaml exposed as **Steps**: The `release` node of the `.gitlab-ci.yml` configuration is converted into **Steps** and made available via API endpoint. 1. The Runner calls GitLab Releaser: the Runner executes the job, and upon success calls the **GitLab Releaser**. -- GitLab From 4743f7fec163ba1d0e623217bbac43b4c044838f Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:28:20 +0000 Subject: [PATCH 26/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 7edab40..6624d17 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,7 +7,7 @@ It consumes instructions in the `:release` node of the `.gitlab-ci.yml` to creat GitLab Releaser is a CLI application written in [Golang](https://golang.org/). The GitLab Releaser is a decoupled utility that may be called by the GitLab Runner, -by a third-party CI or directly from the command-line. +by a third-party CI or directly from the command line. It uses the CI `Job-Token` to authorize against the GitLab Rails API, which is passed to it by the GitLab Runner. The CLI can also be called independently, and can still create the Release via Rails API -- GitLab From 795a6285cb2964ff15fb929b68c37aab0605b987 Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 09:29:00 +0000 Subject: [PATCH 27/29] Apply suggestion to docs/index.md --- docs/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/index.md b/docs/index.md index 6624d17..74571d9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,10 +1,9 @@ # GitLab Releaser command-line tool -GitLab Releaser is a command-line tool that you can use to interact with -[GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html). +GitLab Releaser is a CLI application written in [Golang](https://golang.org/) +to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) through the command line. It consumes instructions in the `:release` node of the `.gitlab-ci.yml` to create a Release object in GitLab Rails. -GitLab Releaser is a CLI application written in [Golang](https://golang.org/). The GitLab Releaser is a decoupled utility that may be called by the GitLab Runner, by a third-party CI or directly from the command line. -- GitLab From ad01f65b74888ee5321b9020267561075550ebbd Mon Sep 17 00:00:00 2001 From: Sean Carroll Date: Fri, 20 Mar 2020 18:06:57 +0000 Subject: [PATCH 28/29] Apply suggestion to docs/index.md --- docs/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 74571d9..f4bdf4e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,5 +1,7 @@ # GitLab Releaser command-line tool +> [Introduced](https://gitlab.com/gitlab-org/gitlab-releaser/-/merge_requests/6) in GitLab 12.10. + GitLab Releaser is a CLI application written in [Golang](https://golang.org/) to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) through the command line. -- GitLab From 8ffcfe597f357022c7b34093a6c5059511261c7e Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Sun, 22 Mar 2020 23:43:24 +0000 Subject: [PATCH 29/29] Apply suggestion to docs/index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index f4bdf4e..46433d6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,7 +3,7 @@ > [Introduced](https://gitlab.com/gitlab-org/gitlab-releaser/-/merge_requests/6) in GitLab 12.10. GitLab Releaser is a CLI application written in [Golang](https://golang.org/) -to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) through the command line. +to interact with [GitLab's Releases API](https://docs.gitlab.com/ee/api/releases/index.html) through the command line and through GitLab CI/CD's configuration file, `.gitlab-ci.yml`. It consumes instructions in the `:release` node of the `.gitlab-ci.yml` to create a Release object in GitLab Rails. -- GitLab