You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	Merge branch 'master' into readme
This commit is contained in:
		
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
								
							| @@ -20,7 +20,8 @@ So, the all-new goreleaser was born. | ||||
|  | ||||
| ## Usage | ||||
|  | ||||
| Create a `goreleaser.yml` file in the root of your repository. A minimal config would look like this: | ||||
| Create a `goreleaser.yml` file in the root of your repository. A minimal config | ||||
| would look like this: | ||||
|  | ||||
| ```yaml | ||||
| repo: user/repo | ||||
| @@ -33,6 +34,10 @@ You may then run releaser at the root of your repository: | ||||
| curl -s https://raw.githubusercontent.com/goreleaser/get/master/latest | bash | ||||
| ``` | ||||
|  | ||||
| For that to work, you need to export a `GITHUB_TOKEN` environment variable with | ||||
| the `repo` scope selected. You can create one | ||||
| [here](https://github.com/settings/tokens/new). | ||||
|  | ||||
| This will build `main.go` as `my-binary`, for `Darwin` and `Linux` | ||||
| (`amd64` and `i386`), archive the binary and common files as `.tar.gz`, | ||||
| and finally, publish a new github release in the `user/repo` repository with | ||||
| @@ -59,6 +64,7 @@ repo: user/repo | ||||
| binary_name: my-binary | ||||
| build: | ||||
|   main: ./cmd/main.go | ||||
|   ldflags: -s -w | ||||
|   oses: | ||||
|     - darwin | ||||
|     - freebsd | ||||
| @@ -66,7 +72,8 @@ build: | ||||
|     - amd64 | ||||
| ``` | ||||
|  | ||||
| > `oses` and `arches` should be in `GOOS`/`GOARCH`-compatible format. | ||||
| > - `oses` and `arches` should be in `GOOS`/`GOARCH`-compatible format. | ||||
| > - `-s -w` is the default value for `ldflags`. | ||||
|  | ||||
| ### Archive customization | ||||
|  | ||||
| @@ -109,7 +116,7 @@ files: | ||||
| > By default GoReleaser adds the binary itself, `LICENCE*`, `LICENSE*`, | ||||
| `README*` and `CHANGELOG*`. | ||||
|  | ||||
| ### ldflags | ||||
| ### ldflags (main.version) | ||||
|  | ||||
| GoReleaser already sets a `main.version` ldflag, so, in you `main.go` program, | ||||
| you can: | ||||
|   | ||||
| @@ -22,9 +22,10 @@ type Homebrew struct { | ||||
|  | ||||
| // BuildConfig contains the build configuration section | ||||
| type BuildConfig struct { | ||||
| 	Oses   []string | ||||
| 	Arches []string | ||||
| 	Main   string | ||||
| 	Oses    []string | ||||
| 	Arches  []string | ||||
| 	Main    string | ||||
| 	Ldflags string | ||||
| } | ||||
|  | ||||
| // GitInfo includes tags and diffs used in some point | ||||
| @@ -107,6 +108,9 @@ func (config *ProjectConfig) fillBasicData() { | ||||
| 	if len(config.Build.Arches) == 0 { | ||||
| 		config.Build.Arches = []string{"amd64", "386"} | ||||
| 	} | ||||
| 	if config.Build.Ldflags == "" { | ||||
| 		config.Build.Ldflags = "-s -w" | ||||
| 	} | ||||
| 	if config.Archive.NameTemplate == "" { | ||||
| 		config.Archive.NameTemplate = "{{.BinaryName}}_{{.Os}}_{{.Arch}}" | ||||
| 	} | ||||
|   | ||||
| @@ -35,16 +35,18 @@ func (Pipe) Run(config config.ProjectConfig) error { | ||||
| } | ||||
|  | ||||
| func build(system, arch string, config config.ProjectConfig) error { | ||||
| 	log.Println("Building", system+"/"+arch, "...") | ||||
| 	name, err := config.ArchiveName(system, arch) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	ldflags := config.Build.Ldflags + " -X main.version=" + config.Git.CurrentTag | ||||
| 	output := "dist/" + name + "/" + config.BinaryName | ||||
| 	log.Println("Building", output, "...") | ||||
| 	cmd := exec.Command( | ||||
| 		"go", | ||||
| 		"build", | ||||
| 		"-ldflags=-s -w -X main.version="+config.Git.CurrentTag, | ||||
| 		"-o", "dist/"+name+"/"+config.BinaryName, | ||||
| 		"-ldflags="+ldflags, | ||||
| 		"-o", output, | ||||
| 		config.Build.Main, | ||||
| 	) | ||||
| 	cmd.Env = append( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user