svu v3
Back in 2017, I got tired of manually checking and creating git tags.
GoReleaser Pro v1.11+ added support to keeping a nightly release.
That means that, whenever you want, you can run:
goreleaser releaser --clean --nightly
And it’ll delete previous nightly
releases and create a new one with the
current commit artifacts.
To enable it, you’ll need to change a few things in your .goreleaser.yml
.
The first one, is actually enabling the nightly release publishing, and setting up the version name template, as well as instructing GoReleaser to keep a single nightly release:
# .goreleaser.yml
# ...
nightly:
publish_release: true
keep_single_release: true
name_template: '{{ incminor .Version }}-nightly'
tag_name: nightly
# ...
This will do a couple of things when you do a nightly release:
nightly
tag and release;{{.Version}}
template variable will now be the result of the
name_template
field aboveAnother change you might want to do is related to the Docker images.
Nightly releases do build and publish Docker images and manifests.
If you have a :latest
tag, you might not want it to be published on nightly
releases.
To do that, we can change those to evaluate to an empty string when it’s a nightly release:
# .goreleaser.yml
# ...
dockers:
- image_templates:
- 'user/repo:v{{ .Version }}'
- '{{ if not .IsNightly }}user/repo:latest{{ end }}'
# ...
You could also do something like:
# .goreleaser.yml
# ...
dockers:
- image_templates:
- 'user/repo:v{{ .Version }}'
- 'user/repo:latest{{ if .IsNightly }}-nightly{{ end }}'
# ...
So it’ll create a :latest-nightly
tag along with the :v{{ .Version }}
one.
The same thing applies to Docker Manifests:
# .goreleaser.yml
# ...
docker_manifests:
- name_template: '{{ if not .IsNightly }}user/repo:latest{{ end }}'
image_templates:
- 'user/repo:v{{ .Version }}-amd64'
- 'user/repo:v{{ .Version }}-arm64'
# ...
Basically any empty Docker image_template
or Docker Manifest name_template
is ignored.
I don’t particularly want to run GoReleaser in my machine to build and release anything, so I also created a GitHub Actions workflow for it:
# .github/workflows/nightly.yml
name: goreleaser-nightly
on:
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-go@v2
with:
go-version: 1.19
- uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser-pro
version: latest
args: release --clean --nightly
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
This way, when I want to release a new nightly, I can just run the workflow in the “Actions” tab of the repository.
And it works:
GitHub actions Run workflow
You can see the latest nightly release here.
Of course, you can also automate it to run, say, daily, or on each commit to
the main
branch:
# .github/workflows/nightly.yml
name: goreleaser-nightly
on:
# release every commit to main:
push:
branches:
- 'main'
# release daily:
schedule:
- cron: '0 * * * *'
# ...
You can read more about it in the GitHub Documentation.
This is only available on GoReleaser Pro. If you want to give it a try, you have an one-week free trial, and since your read all this post here, you can also use this $20 discount, limited to the first 20 people.
I hope you like it!
Well, that’s what I had to show you today! I hope it’s helpful somehow, and I’ll see you in the next one!