iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤔

Some GoReleaser Settings Have Been Deprecated

に公開

I have been using GoReleaser to build and deploy repositories on [GitHub][1]. Regarding the build configuration file .goreleaser.yml, I had been reusing the one I first created (with almost no changes). However, triggered by the release of Go 1.20, I felt ambitious and decided to "add binaries for RISC-V." When I actually tried running it locally, I noticed that several settings have become DEPRECATED.

In this article, I will leave a note of some of the settings that are becoming (or have become) deprecated. Note that I won't go into how to write the .goreleaser.yml file here. I think you can find that by searching around. Just don't be fooled by the poems spat out by ChatGPT (lol).

The --rm-dist Option is Deprecated

When I start it in my local environment, for example, with:

$ goreleaser release --snapshot --skip-publish --rm-dist

I get scolded immediately:

DEPRECATED: --rm-dist was deprecated in favor of --clean, check https://goreleaser.com/deprecations#-rm-dist for more details

Ouch... orz

Checking the indicated web page:

--rm-dist has been deprecated in favor of --clean.
(via “Deprecation notices - GoReleaser”)

Following the instructions, if I change the command line to:

$ goreleaser release --snapshot --skip-publish --clean

it's all good. Don't forget that you also need to change the GitHub Action settings.

Enable rlcp

The warnings continue.

DEPRECATED: `archives.rlcp` will be the default soon, check https://goreleaser.com/deprecations#archivesrlcp for more info

Checking the indicated web page for this too, it said the following:

This is not so much a deprecation property (yet), as it is a default behavior change.

The usage of relative longest common path (rlcp) on the destination side of archive files will be enabled by default by June 2023. Then, this option will be deprecated, and you will have another 6 months (until December 2023) to remove it.
(via “Deprecation notices - GoReleaser”)

For now, if I set it in the .goreleaser.yml file as:

.goreleaser.yml
archives:
-
  rlcp: true

the behavior will remain the same as before, the warning will disappear, and I seem to be safe for the time being. You could also call it kicking the can down the road (lol).

Use Templates for Name Replacements

Let's move on to the next one.

DEPRECATED: `archives.replacements` should not be used anymore, check https://goreleaser.com/deprecations#archivesreplacements for more info

For example, suppose you had defined a template for output archive filenames like this:

.goreleaser.yml
archives:
  - rlcp: true
    format: tar.gz
    format_overrides:
      - goos: windows
        format: zip
    name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
    replacements:
      darwin: Darwin
      linux: Linux
      windows: Windows
      freebsd: FreeBSD
      386: 32bit
      amd64: 64bit
      arm64: ARM64
      riscv64: RISCV

It seems it's saying that the replacements item among these is DEPRECATED[2]. It looks like we're supposed to use Go's template functionality[3] to replace strings instead.

Rewriting the above description using Go's template functionality would look something like this:

.goreleaser.yml
archives:
  - rlcp: true
    format: tar.gz
    format_overrides:
      - goos: windows
        format: zip
    name_template: >-
      {{ .ProjectName }}_
      {{- .Version }}_
      {{- if eq .Os "freebsd" }}FreeBSD
      {{- else }}{{ title .Os }}{{ end }}_
      {{- if eq .Arch "amd64" }}64bit
      {{- else if eq .Arch "386" }}32bit
      {{- else if eq .Arch "arm64" }}ARM64
      {{- else if eq .Arch "riscv64" }}RISCV
      {{- else }}{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ end }}

It will look like this. When processed with GoReleaser under this setting:

  • archives
    • creating      archive=dist/product_1.0.0_Windows_armv6.zip
    • creating      archive=dist/product_1.0.0_Linux_64bit.tar.gz
    • creating      archive=dist/product_1.0.0_FreeBSD_armv6.tar.gz
    • creating      archive=dist/product_1.0.0_Darwin_ARM64.tar.gz
    • creating      archive=dist/product_1.0.0_Darwin_64bit.tar.gz
    • creating      archive=dist/product_1.0.0_Windows_ARM64.zip
    • creating      archive=dist/product_1.0.0_Linux_32bit.tar.gz
    • creating      archive=dist/product_1.0.0_Linux_armv6.tar.gz
    • creating      archive=dist/product_1.0.0_Linux_ARM64.tar.gz
    • creating      archive=dist/product_1.0.0_Windows_32bit.zip
    • creating      archive=dist/product_1.0.0_Windows_64bit.zip
    • creating      archive=dist/product_1.0.0_Linux_RISCV.tar.gz
    • creating      archive=dist/product_1.0.0_FreeBSD_64bit.tar.gz
    • creating      archive=dist/product_1.0.0_FreeBSD_ARM64.tar.gz
    • creating      archive=dist/product_1.0.0_FreeBSD_32bit.tar.gz

The files were generated like this. All right, looking good, all right.

脚注
  1. For details, please refer to my article "Performing a Full Suite of CI Tasks for Go Packages with GitHub Actions". ↩︎

  2. I heard that the deprecation of the replacements item applies not only to archives but also to nfpms and snapcrafts. ↩︎

  3. Refer to the official documentation for Go's template functionality. It has quite a few quirks, so it might be a bit of a struggle until you get used to it. ↩︎

GitHubで編集を提案

Discussion