2020-05-10 21:57:11 +02:00
|
|
|
# Quick Start
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2019-03-25 01:10:30 +02:00
|
|
|
In this example we will build, archive and release a sample Go project.
|
2017-10-01 18:57:52 +02:00
|
|
|
|
2017-09-10 22:07:28 +02:00
|
|
|
Create a GitHub repository and add a single main package:
|
|
|
|
|
|
|
|
```go
|
|
|
|
// main.go
|
|
|
|
package main
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
println("Ba dum, tss!")
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2022-06-11 04:04:16 +02:00
|
|
|
Initialize modules with
|
2024-07-09 04:30:10 +02:00
|
|
|
|
2022-06-11 04:04:16 +02:00
|
|
|
```sh
|
|
|
|
go mod init main
|
|
|
|
```
|
|
|
|
|
2024-07-09 04:30:10 +02:00
|
|
|
Run the [init](cmd/goreleaser_init.md) command to create an example `.goreleaser.yaml` file:
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
|
|
|
goreleaser init
|
2018-07-21 15:33:59 +02:00
|
|
|
```
|
2017-10-01 18:57:52 +02:00
|
|
|
|
2024-07-09 04:30:10 +02:00
|
|
|
Now, lets run a "local-only" release to see if it works using the [release](cmd/goreleaser_release.md) command:
|
2019-02-06 19:14:38 +02:00
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
2023-01-31 04:06:46 +02:00
|
|
|
goreleaser release --snapshot --clean
|
2019-02-06 19:14:38 +02:00
|
|
|
```
|
|
|
|
|
2024-07-09 04:30:10 +02:00
|
|
|
At this point, you can [customize](customization/index.md) the generated `.goreleaser.yaml` or leave it as-is, it's up to you.
|
2021-12-23 02:52:01 +02:00
|
|
|
It is best practice to check `.goreleaser.yaml` into the source control.
|
2019-02-06 19:14:38 +02:00
|
|
|
|
2024-07-09 04:30:10 +02:00
|
|
|
You can verify your `.goreleaser.yaml` is valid by running the [check](cmd/goreleaser_check.md) command:
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2021-07-10 19:11:37 +02:00
|
|
|
```sh
|
|
|
|
goreleaser check
|
|
|
|
```
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2024-07-09 04:30:10 +02:00
|
|
|
You can also use GoReleaser to [build](cmd/goreleaser_build.md) the binary only for a given GOOS/GOARCH, which is useful for local development:
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
2021-07-10 19:11:37 +02:00
|
|
|
goreleaser build --single-target
|
2020-08-14 23:13:02 +02:00
|
|
|
```
|
|
|
|
|
2022-08-28 21:15:24 +02:00
|
|
|
To release to GitHub, you'll need to export a `GITHUB_TOKEN` environment variable, which should contain a valid GitHub token with the `repo` scope.
|
2021-07-10 19:11:37 +02:00
|
|
|
It will be used to deploy releases to your GitHub repository.
|
2023-05-15 14:26:08 +02:00
|
|
|
You can create a new GitHub token [here](https://github.com/settings/tokens/new?scopes=repo,write:packages).
|
2020-08-14 23:13:02 +02:00
|
|
|
|
2021-12-04 19:03:36 +02:00
|
|
|
!!! info
|
2024-07-09 04:30:10 +02:00
|
|
|
|
2021-12-04 19:03:36 +02:00
|
|
|
The minimum permissions the `GITHUB_TOKEN` should have to run this are `write:packages`
|
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
2021-07-10 19:11:37 +02:00
|
|
|
export GITHUB_TOKEN="YOUR_GH_TOKEN"
|
2017-09-10 22:07:28 +02:00
|
|
|
```
|
|
|
|
|
2021-07-10 19:11:37 +02:00
|
|
|
GoReleaser will use the latest [Git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) of your repository.
|
|
|
|
|
|
|
|
Now, create a tag and push it to GitHub:
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
|
|
|
git tag -a v0.1.0 -m "First release"
|
|
|
|
git push origin v0.1.0
|
2017-09-10 22:07:28 +02:00
|
|
|
```
|
|
|
|
|
2020-05-10 21:57:11 +02:00
|
|
|
!!! info
|
2024-07-09 04:30:10 +02:00
|
|
|
|
|
|
|
Check if your tag adheres to [semantic versioning](limitations/semver.md).
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2021-07-10 19:11:37 +02:00
|
|
|
!!! info
|
2024-07-09 04:30:10 +02:00
|
|
|
|
|
|
|
If you don't want to create a tag yet, you can also run GoReleaser without
|
|
|
|
publishing based on the latest commit by using the `--snapshot` flag:
|
2020-02-20 20:39:42 +02:00
|
|
|
|
2021-07-10 19:11:37 +02:00
|
|
|
```sh
|
|
|
|
goreleaser release --snapshot
|
|
|
|
```
|
2017-09-10 22:07:28 +02:00
|
|
|
|
|
|
|
Now you can run GoReleaser at the root of your repository:
|
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
2021-01-21 06:04:16 +02:00
|
|
|
goreleaser release
|
2017-09-10 22:07:28 +02:00
|
|
|
```
|
|
|
|
|
2021-07-10 19:11:37 +02:00
|
|
|
That's all it takes!
|
|
|
|
|
|
|
|
GoReleaser will build the binaries for your app for Windows, Linux and macOS, both amd64 and i386 architectures.
|
2024-07-09 04:30:10 +02:00
|
|
|
You can customize that by changing the `builds` section. Check the [documentation](customization/builds.md) for more information.
|
2021-07-10 19:11:37 +02:00
|
|
|
|
|
|
|
After building the binaries, GoReleaser will create an archive for each OS/Arch pair into a separate file.
|
|
|
|
You can customize several things by changing the `archive` section, including releasing only the binaries and not creating archives at all.
|
2024-07-09 04:30:10 +02:00
|
|
|
Check the [documentation](customization/archive.md) for more information.
|
2021-07-10 19:11:37 +02:00
|
|
|
|
|
|
|
Finally, it will create a release on GitHub with all the artifacts.
|
2017-09-10 22:07:28 +02:00
|
|
|
|
2021-01-21 05:54:12 +02:00
|
|
|
Check your GitHub project's releases page!
|
|
|
|
|
|
|
|
<a href="https://github.com/goreleaser/example/releases">
|
|
|
|
<figure>
|
|
|
|
<img src="https://img.carlosbecker.dev/goreleaser-github.png"/>
|
|
|
|
<figcaption>Example release on GitHub.</figcaption>
|
|
|
|
</figure>
|
2017-09-10 22:07:28 +02:00
|
|
|
</a>
|
2018-10-17 05:41:40 +02:00
|
|
|
|
|
|
|
## Dry run
|
|
|
|
|
|
|
|
If you want to test everything before doing a release "for real", you can
|
2020-05-15 16:19:20 +02:00
|
|
|
use the following techniques.
|
|
|
|
|
|
|
|
### Build-only Mode
|
|
|
|
|
|
|
|
Build command will build the project
|
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
|
|
|
goreleaser build
|
2020-05-15 16:19:20 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
This can be useful as part of CI pipelines to verify the project builds
|
|
|
|
without errors for all build targets.
|
|
|
|
|
|
|
|
You can check the other options by running:
|
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
|
|
|
goreleaser build --help
|
2020-05-15 16:19:20 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
### Release Flags
|
|
|
|
|
2023-11-29 14:31:53 +02:00
|
|
|
Use the `--skip=publish` flag to skip publishing:
|
2018-10-17 05:41:40 +02:00
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
2023-11-29 14:31:53 +02:00
|
|
|
goreleaser release --skip=publish
|
2018-10-17 05:41:40 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
You can check the other options by running:
|
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
|
|
|
goreleaser --help
|
2018-10-17 05:41:40 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
and
|
|
|
|
|
2020-08-14 23:13:02 +02:00
|
|
|
```sh
|
|
|
|
goreleaser release --help
|
2018-10-17 05:41:40 +02:00
|
|
|
```
|