Skip to content

Commit

Permalink
feat: release with target_commitish in another repo
Browse files Browse the repository at this point in the history
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 95bba02
refs #3044
refs #3330

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Aug 23, 2022
1 parent 35f1d78 commit 797a1cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
22 changes: 16 additions & 6 deletions internal/client/github.go
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Expand Up @@ -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"`
Expand Down
7 changes: 7 additions & 0 deletions www/docs/customization/release.md
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions www/docs/customization/templates.md
Expand Up @@ -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)'`
Expand Down

0 comments on commit 797a1cc

Please sign in to comment.