github.com/joselitofilho/goreleaser@v0.155.1-0.20210123221854-e4891856c593/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  jobs:
    25    goreleaser:
    26      runs-on: ubuntu-latest
    27      steps:
    28        -
    29          name: Checkout
    30          uses: actions/checkout@v2
    31          with:
    32            fetch-depth: 0
    33        -
    34          name: Set up Go
    35          uses: actions/setup-go@v2
    36          with:
    37            go-version: 1.15
    38        -
    39          name: Run GoReleaser
    40          uses: goreleaser/goreleaser-action@v2
    41          with:
    42            version: latest
    43            args: release --rm-dist
    44          env:
    45            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    46  ```
    47  
    48  !!! info
    49      Note the `fetch-depth: 0` option on the `Checkout` workflow step. It is required for the change log to work correctly.
    50  
    51  ### Run on new tag
    52  
    53  If you want to run GoReleaser only on new tag, you can use this event:
    54  
    55  ```yaml
    56  on:
    57    push:
    58      tags:
    59        - '*'
    60  ```
    61  
    62  Or with a condition on GoReleaser step:
    63  
    64  ```yaml
    65        -
    66          name: Run GoReleaser
    67          uses: goreleaser/goreleaser-action@v2
    68          if: startsWith(github.ref, 'refs/tags/')
    69          with:
    70            version: latest
    71            args: release --rm-dist
    72          env:
    73            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    74  ```
    75  
    76  !!! tip
    77      For detailed instructions please follow GitHub Actions [workflow syntax][syntax].
    78  
    79  ### Signing
    80  
    81  If [signing is enabled][signing] in your GoReleaser configuration, you can use the [Import GPG][import-gpg]
    82  GitHub Action along with this one:
    83  
    84  ```yaml
    85        -
    86          name: Import GPG key
    87          id: import_gpg
    88          uses: crazy-max/ghaction-import-gpg@v3
    89          with:
    90            gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
    91            passphrase: ${{ secrets.PASSPHRASE }}
    92        -
    93          name: Run GoReleaser
    94          uses: goreleaser/goreleaser-action@v2
    95          with:
    96            version: latest
    97            args: release --rm-dist
    98          env:
    99            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
   100            GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
   101  ```
   102  
   103  And reference the fingerprint in your signing configuration using the `GPG_FINGERPRINT` environment variable:
   104  
   105  ```yaml
   106  signs:
   107    - artifacts: checksum
   108      args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"]
   109  ```
   110  
   111  ## Customizing
   112  
   113  ### Inputs
   114  
   115  Following inputs can be used as `step.with` keys
   116  
   117  | Name      | Type   | Default  | Description                               |
   118  |-----------|--------|----------|-------------------------------------------|
   119  | `version`¹| String | `latest` | GoReleaser version. Example: `v0.117.0`   |
   120  | `args`    | String |          | Arguments to pass to GoReleaser           |
   121  | `workdir` | String | `.`      | Working directory (below repository root) |
   122  
   123  !!! info
   124      ¹: Can be a fixed version like `v0.117.0` or a max satisfying SemVer one
   125      like `~> 0.132`. In this case this will return `v0.132.1`.
   126  
   127  ### Environment Variables
   128  
   129  Following environment variables can be used as `step.env` keys
   130  
   131  | Name           | Description                                           |
   132  |----------------|-------------------------------------------------------|
   133  | `GITHUB_TOKEN` | [GITHUB_TOKEN][github-token] as provided by `secrets` |
   134  
   135  ## Limitations
   136  
   137  `GITHUB_TOKEN` permissions [are limited to the repository][about-github-token] that contains your workflow.
   138  
   139  If you need to push the homebrew tap to another repository, you must therefore create a custom
   140  [Personal Access Token][pat] with `repo` permissions and [add it as a secret in the repository][secrets]. If you
   141  create a secret named `GH_PAT`, the step will look like this:
   142  
   143  ```yaml
   144        -
   145          name: Run GoReleaser
   146          uses: goreleaser/goreleaser-action@v2
   147          with:
   148            version: latest
   149            args: release --rm-dist
   150          env:
   151            GITHUB_TOKEN: ${{ secrets.GH_PAT }}
   152  ```
   153  
   154  ## How does it look like?
   155  
   156  You can check [this example repository](https://github.com/goreleaser/example) for a real world example.
   157  
   158  <a href="https://github.com/goreleaser/example/releases">
   159    <figure>
   160      <img src="https://img.carlosbecker.dev/goreleaser-github.png"/>
   161      <figcaption>Example release on GitHub.</figcaption>
   162    </figure>
   163  </a>
   164  
   165  [goreleaser-action]: https://github.com/goreleaser/goreleaser-action
   166  [actions]: https://github.com/features/actions
   167  [syntax]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#About-yaml-syntax-for-workflows
   168  [signing]: https://goreleaser.com/customization/sign/
   169  [import-gpg]: https://github.com/crazy-max/ghaction-import-gpg
   170  [github-token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
   171  [about-github-token]: https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about-the-github_token-secret
   172  [pat]: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
   173  [secrets]: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets