2021-10-30 09:50:23 -03:00
# GitHub Actions
2019-01-24 16:10:14 -02:00
2022-09-17 00:13:09 -03:00
GoReleaser can also be used within our official [GoReleaser
Action][goreleaser-action] through [GitHub Actions][actions].
2019-01-24 16:10:14 -02:00
2022-09-17 00:13:09 -03:00
You can create a workflow for pushing your releases by putting YAML
configuration to `.github/workflows/release.yml` .
2019-08-30 14:18:25 +01:00
2020-05-10 17:40:51 +02:00
## Usage
### Workflow
2019-09-29 16:32:25 +02:00
Below is a simple snippet to use this action in your workflow:
2019-12-24 14:52:45 +01:00
2019-08-30 14:18:25 +01:00
```yaml
2023-09-15 09:23:19 -03:00
# .github/workflows/release.yml
2019-09-29 16:32:25 +02:00
name: goreleaser
2019-08-30 14:18:25 +01:00
on:
2024-01-04 13:21:15 +01:00
pull_request:
2019-08-30 14:18:25 +01:00
push:
2022-04-11 09:35:03 -03:00
# run only against tags
tags:
2023-09-15 09:23:19 -03:00
- "*"
2019-09-29 16:32:25 +02:00
2021-04-21 20:45:14 +01:00
permissions:
contents: write
2022-04-11 09:35:03 -03:00
# packages: write
# issues: write
2024-09-14 00:21:23 +08:00
# id-token: write
2021-04-21 20:45:14 +01:00
2019-08-30 14:18:25 +01:00
jobs:
2019-09-29 16:32:25 +02:00
goreleaser:
2019-08-30 14:18:25 +01:00
runs-on: ubuntu-latest
steps:
2024-01-04 13:21:15 +01:00
- name: Checkout
uses: actions/checkout@v4
2020-06-16 09:37:11 -03:00
with:
fetch-depth: 0
2024-01-04 13:21:15 +01:00
- name: Set up Go
2024-02-19 06:43:37 -05:00
uses: actions/setup-go@v5
2019-12-24 14:52:45 +01:00
with:
2023-03-17 16:04:47 -03:00
go-version: stable
2023-09-15 09:23:19 -03:00
# More assembly might be required: Docker logins, GPG, etc.
# It all depends on your needs.
2024-01-04 13:21:15 +01:00
- name: Run GoReleaser
2024-06-05 08:44:00 -03:00
uses: goreleaser/goreleaser-action@v6
2019-09-29 16:32:25 +02:00
with:
2024-01-04 13:21:15 +01:00
# either 'goreleaser' (default) or 'goreleaser-pro'
2021-05-26 19:08:46 -03:00
distribution: goreleaser
2024-03-25 09:58:18 -03:00
# 'latest', 'nightly', or a semver
2024-08-11 18:39:44 +02:00
version: "~> v2"
2023-01-30 23:06:46 -03:00
args: release --clean
2019-10-21 19:33:19 +08:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2024-01-04 13:21:15 +01:00
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
2021-05-26 19:08:46 -03:00
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
2019-01-24 16:10:14 -02:00
```
2022-02-25 22:41:00 -03:00
!!! warning "Some things to look closely..."
2023-09-15 09:23:19 -03:00
2022-09-25 10:46:40 -03:00
#### The action does not install, configure or authenticate into dependencies
GoReleaser Action will not install nor setup any other software needed to
release. It's the user's responsibility to install and configure Go, Docker,
Syft, Cosign and any other tools the release might need. It's also the
user's responsibility to log in into tools that need it, such as docker.
2022-06-14 15:26:20 -03:00
2024-11-23 16:22:14 -03:00
#### Fetch all history
Notice the `fetch-depth: 0` option in the `Checkout` workflow step.
This is required for GoReleaser to work properly, as it will need the full
history to work properly.
2022-02-25 22:41:00 -03:00
2020-05-10 19:47:55 -03:00
!!! tip
2023-09-15 09:23:19 -03:00
2020-05-10 19:47:55 -03:00
For detailed instructions please follow GitHub Actions [workflow syntax][syntax].
2019-09-29 16:32:25 +02:00
2020-05-10 17:40:51 +02:00
### Signing
2022-09-17 00:13:09 -03:00
If [signing is enabled][signing] in your GoReleaser configuration, you can use
the [Import GPG][import-gpg] GitHub Action along with this one:
2020-05-10 17:40:51 +02:00
```yaml
2023-09-15 09:23:19 -03:00
# .github/workflows/release.yml
jobs:
# ...
goreleaser:
# ...
steps:
# ...
- name: Import GPG key
2020-05-10 18:16:17 +02:00
id: import_gpg
2023-09-15 09:23:19 -03:00
uses: crazy-max/ghaction-import-gpg@v6
2020-09-07 15:22:45 +02:00
with:
2021-09-06 22:46:23 +02:00
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
2020-09-07 15:22:45 +02:00
passphrase: ${{ secrets.PASSPHRASE }}
2023-09-15 09:23:19 -03:00
- name: Run GoReleaser
2024-06-05 08:44:00 -03:00
uses: goreleaser/goreleaser-action@v6
2020-05-10 17:40:51 +02:00
with:
2024-08-11 18:39:44 +02:00
version: "~> v2"
2023-01-30 23:06:46 -03:00
args: release --clean
2020-05-10 17:40:51 +02:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2020-05-10 18:16:17 +02:00
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
2023-09-15 09:23:19 -03:00
# ...
2020-05-10 17:40:51 +02:00
```
2022-09-17 00:13:09 -03:00
And reference the fingerprint in your signing configuration using the
`GPG_FINGERPRINT` environment variable:
2020-05-10 17:40:51 +02:00
2024-11-29 11:17:45 -03:00
```yaml title=".goreleaser.yaml"
2020-05-10 17:40:51 +02:00
signs:
- artifacts: checksum
2023-11-28 19:38:53 +05:30
cmd: gpg2
2023-09-15 09:23:19 -03:00
args:
- "--batch"
- "-u"
- "{{ .Env.GPG_FINGERPRINT }}"
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
2020-05-10 17:40:51 +02:00
```
2019-09-29 16:32:25 +02:00
## Customizing
2020-06-16 09:37:11 -03:00
### Inputs
2019-01-25 21:47:17 -02:00
2019-09-29 16:32:25 +02:00
Following inputs can be used as `step.with` keys
2019-03-14 11:06:26 -03:00
2023-09-15 09:23:19 -03:00
| Name | Type | Default | Description |
2024-03-25 09:58:18 -03:00
| -------------- | ------ | ------------ | ---------------------------------------------------------------- |
2023-09-15 09:23:19 -03:00
| `distribution` | String | `goreleaser` | GoReleaser distribution, either `goreleaser` or `goreleaser-pro` |
2024-08-11 18:39:44 +02:00
| `version` [^1] | String | `~> v2` | GoReleaser version |
2023-09-15 09:23:19 -03:00
| `args` | String | | Arguments to pass to GoReleaser |
| `workdir` | String | `.` | Working directory (below repository root) |
| `install-only` | Bool | `false` | Just install GoReleaser |
2019-01-25 21:47:17 -02:00
2023-09-15 09:23:19 -03:00
[^1]:
Can be a fixed version like `v0.117.0` or a max satisfying SemVer one like
`~> 0.132` . In this case this will return `v0.132.1` .
2020-06-16 09:52:41 -03:00
2022-04-11 09:35:03 -03:00
### Outputs
Following outputs are available
2023-09-15 09:23:19 -03:00
| Name | Type | Description |
2024-03-25 09:58:18 -03:00
| ----------- | ---- | ---------------------- |
2023-09-15 09:23:19 -03:00
| `artifacts` | JSON | Build result artifacts |
| `metadata` | JSON | Build result metadata |
2022-04-11 09:35:03 -03:00
2020-06-16 09:37:11 -03:00
### Environment Variables
2020-05-07 14:13:46 +02:00
Following environment variables can be used as `step.env` keys
2023-09-15 09:23:19 -03:00
| Name | Description |
2024-03-25 09:58:18 -03:00
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
2023-09-15 09:23:19 -03:00
| `GITHUB_TOKEN` | [GITHUB_TOKEN ](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token ) as provided by `secrets` |
| `GORELEASER_KEY` | Your [GoReleaser Pro ](https://goreleaser.com/pro ) License Key, in case you are using the `goreleaser-pro` distribution |
2020-05-07 14:13:46 +02:00
2021-04-21 20:45:14 +01:00
## Token Permissions
2022-09-17 00:13:09 -03:00
The following
[permissions ](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token )
are required by GoReleaser:
2021-04-21 20:45:14 +01:00
2023-09-15 09:23:19 -03:00
- `contents: write` if you wish to
2024-07-08 23:30:10 -03:00
- [upload archives as GitHub Releases ](../customization/release.md ), or
- publish to [Homebrew ](../customization/homebrew.md ), or
[Scoop ](../customization/scoop.md ) (assuming it's part of the same repository)
2023-09-15 09:23:19 -03:00
- or just `contents: read` if you don't need any of the above
2024-07-08 23:30:10 -03:00
- `packages: write` if you [push Docker images ](../customization/docker.md ) to
2023-09-15 09:23:19 -03:00
GitHub
- `issues: write` if you use [milestone closing
2024-07-08 23:30:10 -03:00
capability](../customization/milestone.md)
2024-09-14 00:21:23 +08:00
- `id-token: write` if you wish use [Cosign][cosign] with [GitHub OIDC][oidc]
2022-09-17 00:13:09 -03:00
`GITHUB_TOKEN` permissions [are limited to the repository][about-github-token]
that contains your workflow.
If you need to push the homebrew tap to another repository, you must create a
custom [Personal Access Token][pat] with `repo` permissions and [add it as a
secret in the repository][secrets]. If you create a secret named `GH_PAT` , the
step will look like this:
2020-05-07 14:13:46 +02:00
```yaml
2023-09-15 09:23:19 -03:00
# .github/workflows/release.yml
jobs:
# ...
goreleaser:
# ...
steps:
# ...
- name: Run GoReleaser
2024-06-05 08:44:00 -03:00
uses: goreleaser/goreleaser-action@v6
2020-05-07 14:13:46 +02:00
with:
2024-08-11 18:39:44 +02:00
version: "~> v2"
2023-01-30 23:06:46 -03:00
args: release --clean
2020-05-07 14:13:46 +02:00
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
2023-09-15 09:23:19 -03:00
# ...
2020-05-07 14:13:46 +02:00
```
2021-03-22 08:52:26 -03:00
You can also read the [GitHub documentation ](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token ) about it.
2022-06-10 20:04:16 -06:00
## What does it look like?
2021-01-21 00:54:12 -03:00
You can check [this example repository ](https://github.com/goreleaser/example ) for a real world example.
< 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 >
< / a >
2019-09-29 16:32:25 +02:00
[goreleaser-action]: https://github.com/goreleaser/goreleaser-action
2019-01-24 16:10:14 -02:00
[actions]: https://github.com/features/actions
2019-08-30 14:18:25 +01:00
[syntax]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#About -yaml-syntax-for-workflows
2024-07-08 23:30:10 -03:00
[signing]: ../customization/sign.md
2020-05-10 17:40:51 +02:00
[import-gpg]: https://github.com/crazy-max/ghaction-import-gpg
2020-05-07 14:13:46 +02:00
[github-token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
[about-github-token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about -the-github_token-secret
[pat]: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
[secrets]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets
2024-09-14 00:21:23 +08:00
[oidc]: https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding -permissions-settings
[cosign]: https://github.com/sigstore/cosign