BeTrfo

BeTrfo

love

Publishing Go projects using goreleaser in Github Action

Preface#

I have been working in front-end development for a long time, and one day I suddenly wanted to familiarize myself with a back-end development language. So I decided to give golang a try since I happened to come across it.
There was no problem with project development, but when it came to distribution, I found it too cumbersome to manually upload executable files one by one. Luckily, GitHub Actions also provides free quotas, so I decided to use it.

About goreleaser#

goreleaser provides multiple distribution methods, and GitHub Actions is just one of the many channels it supports. Of course, goreleaser is also open source, and the project can be found at goreleaser.

Configuring GitHub Action#

Integrating goreleaser into GitHub Actions requires almost no additional steps. Just follow the steps below.

  1. Add a GitHub Action workflow to the repository, with the file path as .github/workflows/release.yml.
# Define the name
name: Release
# Trigger when a tag is pushed, matching v*
on:
  create:
    tags:
      - v*

jobs:
  release:
    name: Release on GitHub
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - run: git fetch --force --tags
      - uses: actions/setup-go@v4
        with:
          go-version: stable
      - uses: goreleaser/goreleaser-action@v4
        with:
          distribution: goreleaser
          version: latest
          args: release --clean
# secrets.GITHUB_TOKEN GitHub Actions comes with its own credentials, so there is no need to apply for them separately. However, there is an additional step, as shown below.
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

In the project settings, you need to grant GitHub Actions read and write access to packages so that the default token in the workflow can upload files to the release.
image
image

  1. Add a tag to the repository and push it to GitHub.
git tag v0.0.1 && git push --tag
  1. At this point, you can already use it. Just wait and see the files in the release.
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.