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. The project development went smoothly, but when it came to distribution, I found it too cumbersome to manually upload executable files one by one. Luckily, GitHub Actions 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. You can find the project address at goreleaser.
Configuring GitHub Action#
Integrating goreleaser into GitHub Actions requires almost no additional operations. Just follow the steps below.
- Add a GitHub Action workflow to your repository. The file path should be
.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 a built-in access token, so you don't need to apply for one yourself. But there is an additional operation, see below.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
In the project settings, you need to grant the GitHub Actions read and write permissions to the packages, so that the default token in the workflow can upload files to the release.
- Add a tag to the repository and push it to GitHub.
git tag v0.0.1 && git push --tag
- Now you can use it. Just wait and see the files in the release.