mgechev/revive

Missing version output in `revive -version` in goreleaser released files

Open

#787 opened on Feb 12, 2023

View on GitHub
 (5 comments) (0 reactions) (0 assignees)Go (316 forks)github user discovery
buggood first issue

Repository metrics

Stars
 (5,517 stars)
PR merge metrics
 (PR metrics pending)

Description

Describe the bug A clear and concise description of what the bug is. The released binaries do not contain a version when calling revive -version

To Reproduce Steps to reproduce the behavior:

  1. Get revive by the following three methods, and run revive -version
  2. See that the versions are different

From the downloaded latest release (linux amd64)

$ chmod +x revive
$ ./revive -version
version (devel)

If using the released docker image, (also built by goreleaser): (Note: I used this dockerfile to have an image where I could call with an entry point)

FROM ghcr.io/mgechev/revive:1.2.5 as revive
FROM alpine:latest
COPY --from=revive /usr/bin/revive /usr/bin/revive
$ docker run --rm   revive:test-echoix sh -c 'revive -version' 
version (devel)

If building from go install (inside a container)

$ docker run --rm -it golang:1.19-alpine sh -c 'go install github.com/mgechev/revive@master && revive -version'
Unable to find image 'golang:1.19-alpine' locally

1.19-alpine: Pulling from library/golang
63b65145d645: Already exists 
a2d21d5440eb: Pull complete 
46eea44c656f: Pull complete 
f44e73cf898e: Pull complete 
Digest: sha256:a00a03c72ecc1a01e4ca7b7cfb62459063912ff45ccb13011f9fb061e25916eb
Status: Downloaded newer image for golang:1.19-alpine

go: downloading github.com/mgechev/revive v1.2.5
go: downloading github.com/mitchellh/go-homedir v1.1.0
go: downloading github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517
go: downloading github.com/fatih/color v1.14.1
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/BurntSushi/toml v1.2.1
go: downloading github.com/chavacava/garif v0.0.0-20221024190013-b3ef35877348
go: downloading github.com/olekukonko/tablewriter v0.0.5
go: downloading github.com/fatih/structtag v1.2.0
go: downloading golang.org/x/tools v0.5.0
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading github.com/mattn/go-isatty v0.0.17
go: downloading github.com/mattn/go-runewidth v0.0.9
go: downloading golang.org/x/sys v0.4.0
version 1.2.5

Expected behavior A clear and concise description of what you expected to happen. The released binaries are the same as the ones that we can build locally with the latest available release source code. This means that version returned by -version would be the same.

Logs If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: VERSION="20.04.5 LTS (Focal Fossa)" on Gitpod
  • Version of Go : 1.19?

Additional context Add any other context about the problem here. The goreleaser/goreleaser-action@v2 seems outdated, there is a goreleaser/goreleaser-action@v4

By default, (at the latest releases, I don't know about older versions of goreleaser), Goreleaser adds the following ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser See also the note on their docs to get reproducible builds https://goreleaser.com/customization/builds/#reproducible-builds

In my try to get editorconfig-checker using goreleaser, the build section looked like this to have reproducible builds:

builds:
  - # ID of the build.
    # Defaults to the binary name.
    id: "editorconfig-checker"

    # Path to main.go file or main package.
    # Notice: when used with `gomod.proxy`, this must be a package.
    #
    # Default is `.`.
    main: ./cmd/editorconfig-checker
    env:
      - CGO_ENABLED=0
    goos:
      - linux
      - windows
      - darwin

    goarch:
      - amd64
      - arm64
      - arm
      - 386
    # Set the modified timestamp on the output binary, typically
    # you would do this to ensure a build was reproducible. Pass
    # empty string to skip modifying the output.
    # Default is empty string, which will be the compile time.
    mod_timestamp: "{{ .CommitTimestamp }}"
    flags:
      - -trimpath
    # Custom ldflags templates.
    # Default is `-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
    # The goal of the changes to the default flags is to make reproducible builds.
    ldflags:
      - -s -w -X main.version={{.Version}}
      - -X main.commit={{.Commit}} -X main.date={{.CommitDate}}
      - -X main.builtBy=goreleaser

However, in the Makefile at the root of the project, the ldflags seems to not apply the version to main, but to cli. https://github.com/mgechev/revive/blob/a4f4632a3f934868012008d36eecafb912282d45/Makefile#L3-L9

Thus, the solution is either to have the project use a main something to be like other default go projects, or to configure the .goreleaser.yml to have the same flags if it is what it takes to have a working build: https://github.com/mgechev/revive/blob/a4f4632a3f934868012008d36eecafb912282d45/.goreleaser.yml#L16-L24

Contributor guide