1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

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 <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos A Becker 2022-08-22 21:31:28 -03:00
parent 35f1d7881b
commit 797a1ccc5f
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
4 changed files with 26 additions and 8 deletions

View File

@ -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,

View File

@ -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"`

View File

@ -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.

View File

@ -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)'`