github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/www/docs/ci/actions.md (about) 1 --- 2 title: GitHub Actions 3 --- 4 5 GoReleaser can also be used within our official [GoReleaser Action][goreleaser-action] 6 through [GitHub Actions][actions]. 7 8 You can create a workflow for pushing your releases by putting YAML configuration to 9 `.github/workflows/release.yml`. 10 11 ## Usage 12 13 ### Workflow 14 15 Below is a simple snippet to use this action in your workflow: 16 17 ```yaml 18 name: goreleaser 19 20 on: 21 pull_request: 22 push: 23 24 permissions: 25 contents: write 26 27 jobs: 28 goreleaser: 29 runs-on: ubuntu-latest 30 steps: 31 - 32 name: Checkout 33 uses: actions/checkout@v2 34 with: 35 fetch-depth: 0 36 - 37 name: Set up Go 38 uses: actions/setup-go@v2 39 with: 40 go-version: 1.17 41 - 42 name: Run GoReleaser 43 uses: goreleaser/goreleaser-action@v2 44 with: 45 # either 'goreleaser' (default) or 'goreleaser-pro' 46 distribution: goreleaser 47 version: latest 48 args: release --rm-dist 49 env: 50 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution 52 # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} 53 ``` 54 55 !!! warning 56 Note the `fetch-depth: 0` option on the `Checkout` workflow step. It is required for GoReleaser to work properly. 57 Without that, GoReleaser might fail or behave incorrectly. 58 59 ### Run on new tag 60 61 If you want to run GoReleaser only on new tag, you can use this event: 62 63 ```yaml 64 on: 65 push: 66 tags: 67 - '*' 68 ``` 69 70 Or with a condition on GoReleaser step: 71 72 ```yaml 73 - 74 name: Run GoReleaser 75 uses: goreleaser/goreleaser-action@v2 76 if: startsWith(github.ref, 'refs/tags/') 77 with: 78 version: latest 79 args: release --rm-dist 80 env: 81 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 82 ``` 83 84 !!! tip 85 For detailed instructions please follow GitHub Actions [workflow syntax][syntax]. 86 87 ### Signing 88 89 If [signing is enabled][signing] in your GoReleaser configuration, you can use the [Import GPG][import-gpg] 90 GitHub Action along with this one: 91 92 ```yaml 93 - 94 name: Import GPG key 95 id: import_gpg 96 uses: crazy-max/ghaction-import-gpg@v4 97 with: 98 gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} 99 passphrase: ${{ secrets.PASSPHRASE }} 100 - 101 name: Run GoReleaser 102 uses: goreleaser/goreleaser-action@v2 103 with: 104 version: latest 105 args: release --rm-dist 106 env: 107 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 108 GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} 109 ``` 110 111 And reference the fingerprint in your signing configuration using the `GPG_FINGERPRINT` environment variable: 112 113 ```yaml 114 signs: 115 - artifacts: checksum 116 args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"] 117 ``` 118 119 ## Customizing 120 121 ### Inputs 122 123 Following inputs can be used as `step.with` keys 124 125 | Name | Type | Default | Description | 126 |------------------|---------|--------------|------------------------------------------------------------------| 127 | `distribution` | String | `goreleaser` | GoReleaser distribution, either `goreleaser` or `goreleaser-pro` | 128 | `version`**¹** | String | `latest` | GoReleaser version | 129 | `args` | String | | Arguments to pass to GoReleaser | 130 | `workdir` | String | `.` | Working directory (below repository root) | 131 | `install-only` | Bool | `false` | Just install GoReleaser | 132 133 !!! info 134 ¹: Can be a fixed version like `v0.117.0` or a max satisfying SemVer one 135 like `~> 0.132`. In this case this will return `v0.132.1`. 136 137 ### Environment Variables 138 139 Following environment variables can be used as `step.env` keys 140 141 | Name | Description | 142 |------------------|---------------------------------------| 143 | `GITHUB_TOKEN` | [GITHUB_TOKEN](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` | 144 | `GORELEASER_KEY` | Your [GoReleaser Pro](https://goreleaser.com/pro) License Key, in case you are using the `goreleaser-pro` distribution | 145 146 ## Token Permissions 147 148 The following [permissions](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token) are required by GoReleaser: 149 150 - `content: write` if you wish to 151 - [upload archives as GitHub Releases](/customization/release/), or 152 - publish to [Homebrew](/customization/homebrew/), or [Scoop](/customization/scoop/) (assuming it's part of the same repository) 153 - or just `content: read` if you don't need any of the above 154 - `packages: write` if you [push Docker images](/customization/docker/) to GitHub 155 - `issues: write` if you use [milestone closing capability](/customization/milestone/) 156 157 `GITHUB_TOKEN` permissions [are limited to the repository][about-github-token] that contains your workflow. 158 159 If you need to push the homebrew tap to another repository, you must therefore create a custom 160 [Personal Access Token][pat] with `repo` permissions and [add it as a secret in the repository][secrets]. If you 161 create a secret named `GH_PAT`, the step will look like this: 162 163 ```yaml 164 - 165 name: Run GoReleaser 166 uses: goreleaser/goreleaser-action@v2 167 with: 168 version: latest 169 args: release --rm-dist 170 env: 171 GITHUB_TOKEN: ${{ secrets.GH_PAT }} 172 ``` 173 174 You can also read the [GitHub documentation](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) about it. 175 176 ## How does it look like? 177 178 You can check [this example repository](https://github.com/goreleaser/example) for a real world example. 179 180 <a href="https://github.com/goreleaser/example/releases"> 181 <figure> 182 <img src="https://img.carlosbecker.dev/goreleaser-github.png"/> 183 <figcaption>Example release on GitHub.</figcaption> 184 </figure> 185 </a> 186 187 [goreleaser-action]: https://github.com/goreleaser/goreleaser-action 188 [actions]: https://github.com/features/actions 189 [syntax]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#About-yaml-syntax-for-workflows 190 [signing]: https://goreleaser.com/customization/sign/ 191 [import-gpg]: https://github.com/crazy-max/ghaction-import-gpg 192 [github-token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token 193 [about-github-token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about-the-github_token-secret 194 [pat]: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ 195 [secrets]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets