goreleaser / goreleaser-action

GitHub Action for GoReleaser
https://github.com/marketplace/actions/goreleaser-action
MIT License
865 stars 78 forks source link

GoReleaser Action not working with `ldflag` #396

Closed jay-kinder closed 1 year ago

jay-kinder commented 1 year ago

https://goreleaser.com/cookbooks/using-main.version/

Please let me know if i have misunderstood this, but I was expecting to have a main.version ldflag available to me in my main.go.

I have set it up as above, but always receive a dev response when using the -v flag.

If I have misunderstood, is there a way to get hold of this through the action? Thanks

caarlos0 commented 1 year ago

you are likely not running it against a tag.

jay-kinder commented 1 year ago

This is still causing a problem:

github action:

name: Release Pipeline
on:
  push:
    tags:
      - "*"

jobs:
  release:
    name: Release New Version
    runs-on: ubuntu-latest

    steps:
      - name: Check Out Code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version-file: "./go.mod"

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v4
        with:
          distribution: goreleaser
          version: latest
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser yaml (I was under the impression the ldflag i want was default, but just to be sure i tried this)

project_name: grole
builds:
  - env:
      - CGO_ENABLED=0
    goos:
      - linux
      - windows
      - darwin
    goarch:
      - amd64
      - arm64
    ldflags:
      - -s -w -X main.version={{.Version}}

main.go

var version = "dev"

func main(){
fmt.Printf("version: %s 👍\n", version)
}

I've taken lots of functionality out of my main.go, but this is the jist of the issue. This always causes version: dev 👍 to be printed

Thanks

caarlos0 commented 1 year ago

can you make a minimal reproducible example repository?

dwertent commented 8 months ago

@jay-kinder try setting it up like this: - -s -w -X "main.version={{.Version}}"

e.g.

project_name: grole
builds:
  - env:
      - CGO_ENABLED=0
    goos:
      - linux
      - windows
      - darwin
    goarch:
      - amd64
      - arm64
    ldflags:
      - -s -w -X "main.version={{.Version}}"