If you've ever faced the challenge of releasing a project written on Go for different platforms/OS, you already know what kind of problems you may come across. If not, I will bring some of them:
You need to constantly monitor the features of each OS (for example, specific slashes in the paths).
You need to create archives manually and upload them to the release page on GitHub.
You need to look at all the commits to make CHANGELOG for a new version.
...and many more!
So, what if I told you that there is a tool that will allow you to do all this (and more) automatically after creating a tag in your repository?
I'm not kidding, it allows you to do all this with GoReleaser GitHub action π
GoReleaser Action runs goreleaser, please follow its docs for
more information about how to customize what GoReleaser do.
Workflow
name: goreleaseron:
pull_request:
push:
permissions:
contents: writejobs:
goreleaser:
runs-on: ubuntu-lateststeps:
-
name: Checkoutuses: actions/checkout@v4with:
fetch-depth: 0
-
name: Set up Gouses: actions/setup-go@v5
-
name: Run GoReleaseruses: goreleaser/goreleaser-action@v6with:
# either 'goreleaser' (default) or 'goreleaser-pro'distribution: goreleaser# 'latest', 'nightly', or a semverversion: '~> v2'args: release --cleanenv:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
Let's move on to the main character of our story. Look at the listing of the file release_build.yml, which already has a lot of familiar elements (if you did read my previous articles about GitHub Action π):
name:Release Go projecton:push:tags:-"*"# triggers only if push new tag version, like `0.8.4` or elsejobs:build:name:GoReleaser buildruns-on:ubuntu-lateststeps:-name:Check out code into the Go module directoryuses:actions/checkout@v2with:fetch-depth:0# See: https://goreleaser.com/ci/actions/-name:Set up Go 1.14uses:actions/setup-go@v2with:go-version:1.14id:go-name:Run GoReleaseruses:goreleaser/goreleaser-action@masterwith:version:latestargs:release --rm-distenv:GITHUB_TOKEN:${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
Yes, GitHub automatically creates a GITHUB_TOKEN secret to use in your workflow, but I recommend to create your own token with repo scopes here:
And now, create new GitHub secret (GO_RELEASER_GITHUB_TOKEN in my case):
If your file with main() function is not in the root directory of your repository, GoReleaser will generate an error. Therefore, you will need to specify the correct directory in the step settings, for example like this:
# ...steps:# ...-name:Run GoReleaseruses:goreleaser/goreleaser-action@masterwith:version:latestargs:release --rm-distworkdir:./cmd/myapp# <-- path to directory with main() funcenv:GITHUB_TOKEN:${{ secrets.GO_RELEASER_GITHUB_TOKEN }}
Create new release with tag (in my case, it's 0.8.4) and go to Actions page in order to follow up on the job:
After successfully completing the job, go to release page to see awesome result: CHANGELOG with all of your commits (between two versions), checksums.txt file and uploaded archives with compiled apps for all platforms!
β¨ A complete and self-contained solution for developers of any qualification to create a production-ready project with backend (Go), frontend (JavaScript, TypeScript) and deploy automation (Ansible, Docker) by running only one CLI command.
Create Go App CLI
Create a new production-ready project with backend (Golang)
frontend (JavaScript, TypeScript) and deploy automation (Ansible
Docker) by running only one CLI command.
Focus on writing your code and thinking of the business-logic! The CLI
will take care of the rest.
β‘οΈ Quick start
First, download and install Go. Version 1.20 or
higher is required.
βοΈ Note: If you're looking for the Create Go App CLI for other Go
versions: 1.16, 1.17.
Installation is done by using the go install command:
go install github.com/create-go-app/cli/v4/cmd/cgapp@latest
Or see the repository's Release page, if you want to
download a ready-made deb, rpm, apk or Arch Linux package.
Also, GNU/Linux and macOS users available way to install via
Homebrew:
# Tap a new formula:
brew tap create-go-app/tap
# Installation:
brew install create-go-app/tap/cgapp
Let's create a new project via interactive console UI (or CUIβ¦
Repeat everything you have seen in the article, but with your own Golang project. Please, write about your result & link to your shorter website in the comments below!
Change the triggering value so that it only works for major versions. Please, read more about software versioning here.
If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! π»
βοΈ You can support me on Boosty, both on a permanent and on a one-time basis. All proceeds from this way will go to support my OSS projects and will energize me to create new products and articles for the community.
And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!
My main projects that need your help (and stars) π
π₯ gowebly: A next-generation CLI tool that makes it easy to create amazing web applications with Go on the backend, using htmx, hyperscript or Alpine.js and the most popular CSS frameworks on the frontend.
β¨ create-go-app: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.