1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/www/content/environment.md
Andy Grunwald ac206f8442 docs: Add main.commit and main.date to environment section
In the default golang builders ldflags three flags are set:
main.version, main.commit and main.date.
See https://github.com/goreleaser/goreleaser/blob/master/internal/builders/golang/build.go#L48

In the environment docs, only the main.version is mentioned.
goreleaser itself uses main.date and main.commit also.
2018-05-06 09:17:08 -03:00

2.2 KiB

title weight menu
Environment 20 true

GitHub Token

GoReleaser requires a GitHub API token with the repo scope selected to deploy the artifacts to GitHub. You can create one here.

This token should be added to the environment variables as GITHUB_TOKEN. Here is how to do it with Travis CI: Defining Variables in Repository Settings.

Alternatively, you can provide the GitHub token in a file. GoReleaser will check ~/.config/goreleaser/github_token by default, you can change that in the .goreleaser.yml file:

# .goreleaser.yml
env_files:
  github_token: ~/.path/to/my/token

GitHub Enterprise

You can use GoReleaser with GitHub Enterprise by providing its URLs in the .goreleaser.yml configuration file:

# .goreleaser.yml
github_urls:
    api: api.github.foo.bar
    upload: uploads.github.foo.bar
    download: github.foo.bar

If none are set, they default to GitHub's public URLs.

The dist folder

By default, GoReleaser will create its artifacts in the ./dist folder. If you must, you can change it by setting it in the .goreleaser.yml file:

# .goreleaser.yml
dist: another-folder-that-is-not-dist

Using the main.version

Default wise GoReleaser sets three ldflags:

  • main.version: Current Git tag (the v prefix is stripped) or the name of the snapshot, if you're using the --snapshot flag
  • main.commit: Current git commit SHA
  • main.date: Date according RFC3339

You can use it in your main.go file:

package main

import "fmt"

var (
	version = "dev"
	commit  = "none"
	date    = "unknown"
)

func main() {
  fmt.Printf("%v, commit %v, built at %v", version, commit, date)
}

You can override this by changing the ldflags option in the build section.

Customizing Git

By default, GoReleaser uses full length commit hashes when setting a main.commit ldflag or creating filenames in --snapshot mode.

You can use short, 7 character long commit hashes by setting it in the .goreleaser.yml:

# .goreleaser.yml
git:
  short_hash: true