in commands/release/create/create.go [79:205]
func NewCmdCreate(f *cmdutils.Factory) *cobra.Command {
opts := &CreateOpts{
IO: f.IO,
Config: f.Config,
}
cmd := &cobra.Command{
Use: "create <tag> [<files>...]",
Short: "Create a new GitLab release, or update an existing one.",
Long: heredoc.Docf(`Create a new release, or update an existing GitLab release, for a repository. Requires the Developer role or higher.
An existing release is updated with the new information you provide.
To create a release from an annotated Git tag, first create one locally with
Git, push the tag to GitLab, then run this command.
If the Git tag you specify doesn't exist, the release is created
from the latest state of the default branch, and tagged with the tag name you specify.
To override this behavior, use %[1]s--ref%[1]s. The %[1]sref%[1]s can be a commit SHA, another tag name, or a branch name.
To fetch the new tag locally after the release, run %[1]sgit fetch --tags origin%[1]s.
`, "`"),
Args: cmdutils.MinimumArgs(1, "no tag name provided."),
Example: heredoc.Docf(`
# Create a release interactively
$ glab release create v1.0.1
# Create a release non-interactively by specifying a note
$ glab release create v1.0.1 --notes "bugfix release"
# Use release notes from a file
$ glab release create v1.0.1 -F changelog.md
# Upload a release asset with a display name (type will default to 'other')
$ glab release create v1.0.1 '/path/to/asset.zip#My display label'
# Upload a release asset with a display name and type
$ glab release create v1.0.1 '/path/to/asset.png#My display label#image'
# Upload all assets in a specified folder (types default to 'other')
$ glab release create v1.0.1 ./dist/*
# Upload all tarballs in a specified folder (types default to 'other')
$ glab release create v1.0.1 ./dist/*.tar.gz
# Create a release with assets specified as JSON object
$ glab release create v1.0.1 --assets-links='
[
{
"name": "Asset1",
"url":"https://<domain>/some/location/1",
"link_type": "other",
"direct_asset_path": "path/to/file"
}
]'
# [EXPERIMENTAL] Create a release and publish it to the GitLab CI/CD catalog
# Requires the feature flag %[1]sci_release_cli_catalog_publish_option%[1]s to be enabled
# for this project in your GitLab instance. Do NOT run this manually. Use it as part
# of a CI/CD pipeline with the "release" keyword:
#
# - It retrieves components from the current repository by searching for
# %[1]syml%[1]s files within the "templates" directory and its subdirectories.
# - It fails if the feature flag %[1]sci_release_cli_catalog_publish_option%[1]s
# is not enabled for this project in your GitLab instance.
# Components can be defined:
# - In single files ending in %[1]s.yml%[1]s for each component, like %[1]stemplates/secret-detection.yml%[1]s.
# - In subdirectories containing %[1]stemplate.yml%[1]s files as entry points,
# for components that bundle together multiple related files. For example,
# %[1]stemplates/secret-detection/template.yml%[1]s.
$ glab release create v1.0.1 --publish-to-catalog
`, "`"),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
opts.RepoOverride, _ = cmd.Flags().GetString("repo")
opts.HTTPClient = f.HttpClient
opts.BaseRepo = f.BaseRepo
opts.TagName = args[0]
opts.AssetFiles, err = releaseutils.AssetsFromArgs(args[1:])
if err != nil {
return err
}
if opts.AssetLinksAsJson != "" {
err := json.Unmarshal([]byte(opts.AssetLinksAsJson), &opts.AssetLinks)
if err != nil {
return fmt.Errorf("failed to parse JSON string: %w", err)
}
}
opts.Notes, err = resolveNotes(cmd, opts)
if err != nil {
return err
}
opts.NoteProvided = opts.Notes != ""
return createRun(opts)
},
}
cmd.Flags().StringVarP(&opts.Name, "name", "n", "", "The release name or title.")
cmd.Flags().StringVarP(&opts.Ref, "ref", "r", "", "If the specified tag doesn't exist, the release is created from ref and tagged with the specified tag name. It can be a commit SHA, another tag name, or a branch name.")
cmd.Flags().StringVarP(&opts.TagMessage, "tag-message", "T", "", "Message to use if creating a new annotated tag.")
cmd.Flags().StringVarP(&opts.Notes, "notes", "N", "", "The release notes or description. You can use Markdown.")
cmd.Flags().StringVarP(&opts.NotesFile, "notes-file", "F", "", "Read release notes 'file'. Specify '-' as the value to read from stdin.")
cmd.Flags().StringVarP(&opts.ReleasedAt, "released-at", "D", "", "The 'date' when the release was ready. Defaults to the current datetime. Expects ISO 8601 format (2019-03-15T08:00:00Z).")
cmd.Flags().StringSliceVarP(&opts.Milestone, "milestone", "m", []string{}, "The title of each milestone the release is associated with.")
cmd.Flags().StringVarP(&opts.AssetLinksAsJson, "assets-links", "a", "", "'JSON' string representation of assets links, like `--assets-links='[{\"name\": \"Asset1\", \"url\":\"https://<domain>/some/location/1\", \"link_type\": \"other\", \"direct_asset_path\": \"path/to/file\"}]'.`")
cmd.Flags().BoolVar(&opts.PublishToCatalog, "publish-to-catalog", false, "[EXPERIMENTAL] Publish the release to the GitLab CI/CD catalog.")
cmd.Flags().BoolVar(&opts.NoUpdate, "no-update", false, "Prevent updating the existing release.")
cmd.Flags().BoolVar(&opts.NoCloseMilestone, "no-close-milestone", false, "Prevent closing milestones after creating the release.")
cmd.Flags().StringVar(&opts.ExperimentalNotesTextOrFile, "experimental-notes-text-or-file", "", "[EXPERIMENTAL] Value to use as release notes. If a file exists with this value as path, its content will be used. Otherwise, the value itself will be used as text.")
_ = cmd.Flags().MarkHidden("experimental-notes-text-or-file")
// These two need to be separately exclusive to avoid a breaking change
// because there may be existing scripts that already use both notes and notes-file.
cmd.MarkFlagsMutuallyExclusive("experimental-notes-text-or-file", "notes")
cmd.MarkFlagsMutuallyExclusive("experimental-notes-text-or-file", "notes-file")
return cmd
}