Closed plastikfan closed 1 year ago
First, install go releaser with go install:
go install github.com/goreleaser/goreleaser@latest
Init the project:
goreleaser init
NB: you don't really need to have a local install of goreleaser, we just need it whilst we're are setting up the process. The resultant config file (gorelease.yaml) is used by CI.
Run the release command (local-only release):
goreleaser release --snapshot --clean
The output of the first run:
• starting release...
• loading config file file=.goreleaser.yaml
• loading environment variables
• getting and validating git state
• couldn't find any tags before "v0.1.0"
• building... commit=de091d5287bc0637ff20ecd6afa3d00182ea1543 latest tag=v0.1.0
• pipe skipped reason=disabled during snapshot mode
• parsing tag
• setting defaults
• running before hooks
• running hook=go mod tidy
• running hook=go generate ./...
• snapshotting
• building snapshot... version=0.1.1-next
• checking distribution directory
• loading go mod information
• build prerequisites
• writing effective config file
• writing config=dist/config.yaml
• building binaries
• building binary=dist/extendio_darwin_arm64/extendio
• building binary=dist/extendio_windows_386/extendio.exe
• building binary=dist/extendio_windows_arm64/extendio.exe
• building binary=dist/extendio_linux_386/extendio
• building binary=dist/extendio_linux_arm64/extendio
• building binary=dist/extendio_windows_amd64_v1/extendio.exe
• building binary=dist/extendio_darwin_amd64_v1/extendio
• building binary=dist/extendio_linux_amd64_v1/extendio
⨯ release failed after 0s error=build for extendio does not contain a main function
As can be seen, there are issues because of a lack of tags. At the time of running this first attempt, there is only a single tag 0.1.0.
Then also note, goreleaser also complains about there not being a main function.
It looks like goreleaser is meant only for executables, not libraries, so we can't implement this. However, we can use Release Drafter
Also see how to customise builds
Just found a flag to disable the main check (no_main_check: true):
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
# this is a go library
no_main_check: true
with this in place, the output is now:
plastikfan@Janus ~/dev/github/go/snivilised/extendio λ chore/go-releaser ± goreleaser release --snapshot --clean
• starting release...
• loading config file file=.goreleaser.yaml
• loading environment variables
• getting and validating git state
• couldn't find any tags before "v0.1.0"
• building... commit=de091d5287bc0637ff20ecd6afa3d00182ea1543 latest tag=v0.1.0
• pipe skipped reason=disabled during snapshot mode
• parsing tag
• setting defaults
• running before hooks
• running hook=go mod tidy
• running hook=go generate ./...
• snapshotting
• building snapshot... version=0.1.1-next
• checking distribution directory
• cleaning dist
• loading go mod information
• build prerequisites
• writing effective config file
• writing config=dist/config.yaml
• building binaries
• building binary=dist/extendio_darwin_arm64/extendio
• building binary=dist/extendio_linux_386/extendio
• building binary=dist/extendio_windows_arm64/extendio.exe
• building binary=dist/extendio_windows_386/extendio.exe
• building binary=dist/extendio_linux_arm64/extendio
• building binary=dist/extendio_darwin_amd64_v1/extendio
• building binary=dist/extendio_windows_amd64_v1/extendio.exe
• building binary=dist/extendio_linux_amd64_v1/extendio
⨯ release failed after 0s error=failed to build for linux_arm64: exit status 1: no Go files in /home/plastikfan/dev/github/go/snivilised/extendio
So we now have error:
error=failed to build for linux_arm64: exit status 1: no Go files in /home/plastikfan/dev/github/go/snivilised/extendio
Need to set the input directory (ie, the entry point), turn off the main check and set skip. Note that setting skip as documented:
- skip: true
doesn't work and causes the check to fail (gorelease check):
plastikfan@Janus ~/dev/github/go/snivilised/extendio λ chore/go-releaser ± goreleaser check
• loading config file file=.goreleaser.yaml
• checking config...
⨯ config is invalid error=found 2 builds with the ID 'extendio', please fix your config
⨯ command failed error=invalid config: found 2 builds with the ID 'extendio', please fix your config
However, this can be fixed by omitting the '-'.
So now re-try the release:
✘ plastikfan@Janus ~/dev/github/go/snivilised/extendio λ chore/go-releaser ± goreleaser check
• loading config file file=.goreleaser.yaml
• checking config...
• config is valid
plastikfan@Janus ~/dev/github/go/snivilised/extendio λ chore/go-releaser ± goreleaser release --snapshot --clean
• starting release...
• loading config file file=.goreleaser.yaml
• loading environment variables
• getting and validating git state
• couldn't find any tags before "v0.1.0"
• building... commit=de091d5287bc0637ff20ecd6afa3d00182ea1543 latest tag=v0.1.0
• pipe skipped reason=disabled during snapshot mode
• parsing tag
• setting defaults
• running before hooks
• running hook=go mod tidy
• running hook=go generate ./...
• snapshotting
• building snapshot... version=0.1.1-next
• checking distribution directory
• cleaning dist
• loading go mod information
• build prerequisites
• writing effective config file
• writing config=dist/config.yaml
• building binaries
• skip is set id=extendio
• archives
• calculating checksums
• storing release metadata
• writing file=dist/artifacts.json
• writing file=dist/metadata.json
... and we now have some artifacts in the ./dist folder:
So the essential point of note is that for library projects, goreleaser does NOT do a build, it just handles generation of the changelog.
Since we don't have any prior releases, we can't generate a meaningful changelog, because there hasn't been any changes. A basic config has been defined to generate a changelog, but can't be tested yet. Verification of this will have to be done in a subsequent issue, once an initial release has been performed.
Whilst we're dealing with yaml, apply yamllint updates to the Taskfile.yml file.
(the fake version can be used to practice the auto release process without polluting this repo with mistake commits. Make sure to create the copy that includes the commit history (ie fork), so there is some commit data to work with)
Take a look at: