From 797a1ccc5f1da49d009ae1f41f440351e301ffa8 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Mon, 22 Aug 2022 21:31:28 -0300 Subject: [PATCH] feat: release with target_commitish in another repo We should not imply the target_commitish, as some users might want to have the code in one repo and the releases in another (e.g. private code, public releases), so the commit might not be there. We should instead allow the user to set the `target_commitish` (or not), and pass it down to the github api. refs 95bba02211a2b88426826ff36a3fd1b424a1d5a7 refs #3044 refs #3330 Signed-off-by: Carlos A Becker --- internal/client/github.go | 22 ++++++++++++++++------ pkg/config/config.go | 1 + www/docs/customization/release.md | 7 +++++++ www/docs/customization/templates.md | 4 ++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/internal/client/github.go b/internal/client/github.go index 0ee688e863b..7c1cf805abb 100644 --- a/internal/client/github.go +++ b/internal/client/github.go @@ -217,17 +217,27 @@ func (c *githubClient) CreateRelease(ctx *context.Context, body string) (string, body = truncateReleaseBody(body) data := &github.RepositoryRelease{ - Name: github.String(title), - TagName: github.String(ctx.Git.CurrentTag), - TargetCommitish: github.String(ctx.Git.Commit), - Body: github.String(body), - Draft: github.Bool(ctx.Config.Release.Draft), - Prerelease: github.Bool(ctx.PreRelease), + Name: github.String(title), + TagName: github.String(ctx.Git.CurrentTag), + Body: github.String(body), + Draft: github.Bool(ctx.Config.Release.Draft), + Prerelease: github.Bool(ctx.PreRelease), } + if ctx.Config.Release.DiscussionCategoryName != "" { data.DiscussionCategoryName = github.String(ctx.Config.Release.DiscussionCategoryName) } + if target := ctx.Config.Release.TargetCommitish; target != "" { + target, err := tmpl.New(ctx).Apply(target) + if err != nil { + return "", err + } + if target != "" { + data.TargetCommitish = github.String(target) + } + } + release, _, err = c.client.Repositories.GetReleaseByTag( ctx, ctx.Config.Release.GitHub.Owner, diff --git a/pkg/config/config.go b/pkg/config/config.go index acf1c8dc9e2..7df34ef6341 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -500,6 +500,7 @@ type Release struct { Gitea Repo `yaml:"gitea,omitempty" json:"gitea,omitempty"` Draft bool `yaml:"draft,omitempty" json:"draft,omitempty"` ReplaceExistingDraft bool `yaml:"replace_existing_draft,omitempty" json:"replace_existing_draft,omitempty"` + TargetCommitish string `yaml:"target_commitish,omitempty" json:"target_commitish,omitempty"` Disable bool `yaml:"disable,omitempty" json:"disable,omitempty"` SkipUpload bool `yaml:"skip_upload,omitempty" json:"skip_upload,omitempty"` Prerelease string `yaml:"prerelease,omitempty" json:"prerelease,omitempty"` diff --git a/www/docs/customization/release.md b/www/docs/customization/release.md index b0a17f847c4..5a5b815a9fb 100644 --- a/www/docs/customization/release.md +++ b/www/docs/customization/release.md @@ -34,6 +34,13 @@ release: # Default is false. replace_existing_draft: true + # Useful if you want to delay the creation of the tag in the remote. + # You can create the tag locally, but not push it, and run GoReleaser. + # It'll then set the `target_commitish` portion of the GitHub release to the value of this field. + # Only works on GitHub. + # Default is empty. + target_commitish: '{{ .Commit }}' + # If set, will create a release discussion in the category specified. # # Warning: do not use categories in the 'Announcement' format. diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index 8b2fb42787f..e7f9898c9ed 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -49,10 +49,10 @@ On fields that support templating, these fields are always available: | `.Runtime.Goos` | equivalent to `runtime.GOOS` | | `.Runtime.Goarch` | equivalent to `runtime.GOARCH` | -[^1]: The `v` prefix is stripped and it might be changed in `snapshot` and `nightly` builds. +[^1]: The `v` prefix is stripped, and it might be changed in `snapshot` and `nightly` builds. [^2]: Assuming `Tag` is a valid a SemVer, otherwise empty/zeroed. [^3]: Will panic if not a semantic version. -[^4]: Composed from the current SCM's download URL and current tag. For instance, on GitHub, it'll be `https://github.com/{owner}/{repo}/releases/tag/{tag}`. +[^4]: Composed of the current SCM's download URL and current tag. For instance, on GitHub, it'll be `https://github.com/{owner}/{repo}/releases/tag/{tag}`. [^5]: It is generated by `git describe --dirty --always --tags`, the format will be `{Tag}-$N-{CommitSHA}` [^6]: As reported by `git tag -l --format='%(contents:subject)'` [^7]: As reported by `git tag -l --format='%(contents)'`