Skip to content

Support retrieving git metadata from export-subst file (.git_archival.txt pattern) #5212

Closed
@nickstenning

Description

@nickstenning

Is your feature request related to a problem? Please describe.

The problem this is trying to solve is that I'd like goreleaser to be the only way my project is built. That's tricky when packaging for Homebrew, for example, as we need to be able to build from a source tarball without the .git directory. The problem is that goreleaser build doesn't allow me to provide the necessary git metadata any other way. (It seems like GORELEASER_CURRENT_TAG doesn't work for build?)

$ GOTOOLCHAIN=go1.23.2 GORELEASER_CURRENT_TAG=v0.11.3 go run github.com/goreleaser/goreleaser/v2@latest build --skip=validate --clean --single-target --id cog --output cog
  • skipping validate...
  • cleaning distribution directory
  • loading environment variables
  • getting and validating git state
  ⨯ build failed after 0s                    error=current folder is not a git repository
exit status 1

Describe the solution you'd like

What I'd like is for goreleaser to adopt the same convention as Python's setuptools_scm, namely allowing Git users to specify an export-subst file which captures Git metadata in an archive tarball.

The idea is that if users create a .gitattributes file containing

.git_archival.txt  export-subst

and then a .git_archival.txt containing

node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$

then in the resulting archive tarball, the .git_archival.txt will contain a file that looks like this:

node: 72b293363490f32b754943f25ac82ee9976b0dc4
node-date: 2024-10-19T01:22:47+02:00
describe-name: v0.11.3

Python's setuptools_scm can automatically detect this file and use it to establish the relevant Git metadata for the build.

Describe alternatives you've considered

Another option would be to allow GORELEASER_CURRENT_TAG and possibly other information like commit, commit date, etc., to be provided from environment variable overrides for goreleaser build invocations. This would work fine for us.

The advantage of the .git_archival.txt solution is that it's already supported by at least one other build tool, and it would be great to further establish it as a standard.

Search

  • I did search for other open and closed issues before opening this

Supporter

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

Thank you for making goreleaser!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions