diff --git a/internal/client/gitlab.go b/internal/client/gitlab.go index d3d518b17..582744d55 100644 --- a/internal/client/gitlab.go +++ b/internal/client/gitlab.go @@ -377,19 +377,41 @@ func (c *gitlabClient) Upload( projectID = ctx.Config.Release.GitLab.Owner + "/" + projectID } - log.WithField("file", file.Name()).Debug("uploading file") - projectFile, _, err := c.client.Projects.UploadFile( - projectID, - file.Name(), - nil, - ) - if err != nil { - return err + var baseLinkURL string + if ctx.Config.GitLabURLs.UsePackageRegistry { + log.WithField("file", file.Name()).Debug("uploading file as generic package") + _, _, err := c.client.GenericPackages.PublishPackageFile( + projectID, + ctx.Config.ProjectName, + ctx.Version, + artifact.Name, + file, + nil, + ) + if err != nil { + return err + } + baseLinkURL, err = c.client.GenericPackages.FormatPackageURL( + projectID, ctx.Config.ProjectName, ctx.Version, artifact.Name) + if err != nil { + return err + } + } else { + log.WithField("file", file.Name()).Debug("uploading file as attachment") + projectFile, _, err := c.client.Projects.UploadFile( + projectID, + file.Name(), + nil, + ) + if err != nil { + return err + } + baseLinkURL = projectFile.URL } log.WithFields(log.Fields{ "file": file.Name(), - "url": projectFile.URL, + "url": baseLinkURL, }).Debug("uploaded file") // search for project details based on projectID @@ -398,14 +420,18 @@ func (c *gitlabClient) Upload( return err } - gitlabBaseURL, err := tmpl.New(ctx).Apply(ctx.Config.GitLabURLs.Download) - if err != nil { - return fmt.Errorf("templating GitLab Download URL: %w", err) - } - - linkURL := gitlabBaseURL + "/" + projectDetails.PathWithNamespace + projectFile.URL name := artifact.Name filename := "/" + name + var linkURL string + if ctx.Config.GitLabURLs.UsePackageRegistry { + linkURL = c.client.BaseURL().String() + baseLinkURL + } else { + gitlabBaseURL, err := tmpl.New(ctx).Apply(ctx.Config.GitLabURLs.Download) + if err != nil { + return fmt.Errorf("templating GitLab Download URL: %w", err) + } + linkURL = gitlabBaseURL + "/" + projectDetails.PathWithNamespace + baseLinkURL + } releaseLink, _, err := c.client.ReleaseLinks.CreateReleaseLink( projectID, releaseID, diff --git a/pkg/config/config.go b/pkg/config/config.go index 52c18f26a..1b35b7f43 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -25,9 +25,10 @@ type GitHubURLs struct { // GitLabURLs holds the URLs to be used when using gitlab ce/enterprise. type GitLabURLs struct { - API string `yaml:"api,omitempty"` - Download string `yaml:"download,omitempty"` - SkipTLSVerify bool `yaml:"skip_tls_verify,omitempty"` + API string `yaml:"api,omitempty"` + Download string `yaml:"download,omitempty"` + SkipTLSVerify bool `yaml:"skip_tls_verify,omitempty"` + UsePackageRegistry bool `yaml:"use_package_registry,omitempty"` } // GiteaURLs holds the URLs to be used when using gitea. diff --git a/www/docs/scm/gitlab.md b/www/docs/scm/gitlab.md index 20c6f716c..6ff1d6f79 100644 --- a/www/docs/scm/gitlab.md +++ b/www/docs/scm/gitlab.md @@ -28,6 +28,9 @@ gitlab_urls: download: https://gitlab.company.com # set to true if you use a self-signed certificate skip_tls_verify: false + # set to true if you want to upload to the Package Registry rather than attachments + # Only works with GitLab 13.5+ + use_package_registry: false ``` If none are set, they default to GitLab's public URLs. @@ -37,6 +40,19 @@ If none are set, they default to GitLab's public URLs. on [release](https://docs.gitlab.com/ee/user/project/releases/index.html) functionality and [direct asset linking](https://docs.gitlab.com/ee/user/project/releases/index.html#permanent-links-to-release-assets). +## Generic Package Registry + +GitLab introduced the [Generic Package Registry](https://docs.gitlab.com/ee/user/packages/package_registry/index.html) in Gitlab 13.5. + +Normally, `goreleaser` uploads release files as "attachments", which may have [administrative limits](https://docs.gitlab.com/ee/user/admin_area/settings/account_and_limit_settings.html). Notably, hosted gitlab.com instances have a 10MB attachment limit which cannot be changed. + +Uploading to the Generic Package Registry does not have this restriction. To use it instead, set `use_package_registry` to `true`. + +```yaml +# .goreleaser.yml +gitlab_urls: + use_package_registry: true +``` ## Example release