Skip to content

Commit

Permalink
fix(goreleaser): correct the name of env block and indents (#489)
Browse files Browse the repository at this point in the history
* fix(goreleaser): correct the name of env block and indents

* update test

* sanitize cmd name as block name and update test

* replace dash in cmd name, update test
  • Loading branch information
yj-yan committed Apr 24, 2024
1 parent 3757693 commit 6b7d17b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 58 deletions.
45 changes: 23 additions & 22 deletions templates/.goreleaser.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@ builds:
{{- $cmdName = (index (keys $cmdName) 0) }}
{{- $opts = (index . $cmdName | default (dict)) }}
{{- end }}
- main: ./cmd/{{ $cmdName }}
id: &name {{ $cmdName }}
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ "{{" }} .Version {{ "}}" }}"'
{{- if not $opts.delibird }}
- '-X "main.HoneycombTracingKey={{ "{{" }} .Env.HONEYCOMB_APIKEY {{ "}}" }}"'
- '-X "main.TeleforkAPIKey={{ "{{" }} .Env.TELEFORK_APIKEY {{ "}}" }}"'
{{- end }}
env:
- CGO_ENABLED={{ stencil.ApplyTemplate "cgoEnabled" | trim }}
{{- $blockName := (printf "%vAdditionalEnv" $cmdName) }}
### <<Stencil::Block({{ $blockName }})>>
{{ (file.Block $blockName) | trim | indent 2 }}
### <</Stencil::Block>>
{{- end }}
- main: ./cmd/{{ $cmdName }}
id: &name {{ $cmdName }}
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ "{{" }} .Version {{ "}}" }}"'
{{- if not $opts.delibird }}
- '-X "main.HoneycombTracingKey={{ "{{" }} .Env.HONEYCOMB_APIKEY {{ "}}" }}"'
- '-X "main.TeleforkAPIKey={{ "{{" }} .Env.TELEFORK_APIKEY {{ "}}" }}"'
{{- end }}
env:
- CGO_ENABLED={{ stencil.ApplyTemplate "cgoEnabled" | trim }}
{{- $cmd := $cmdName | split "-" }}
{{- $blockName := (printf "%vAdditionalEnv" ($cmdName | replace "-" "")) }}
## <<Stencil::Block({{ $blockName }})>>
{{ (file.Block $blockName) | trim }}
## <</Stencil::Block>>
{{- end }}

archives: []
checksum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,78 @@ before:
hooks:
- make dep
builds:
- main: ./cmd/cmd1
id: &name cmd1
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
env:
- CGO_ENABLED=0
### <<Stencil::Block(cmd1AdditionalEnv)>>

### <</Stencil::Block>>
- main: ./cmd/cmd2
id: &name cmd2
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
env:
- CGO_ENABLED=0
### <<Stencil::Block(cmd2AdditionalEnv)>>

### <</Stencil::Block>>
- main: ./cmd/cmd1
id: &name cmd1
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
env:
- CGO_ENABLED=0
## <<Stencil::Block(cmd1AdditionalEnv)>>

## <</Stencil::Block>>
- main: ./cmd/cmd2
id: &name cmd2
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
env:
- CGO_ENABLED=0
## <<Stencil::Block(cmd2AdditionalEnv)>>

## <</Stencil::Block>>
- main: ./cmd/cmd3-sub1
id: &name cmd3-sub1
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
env:
- CGO_ENABLED=0
## <<Stencil::Block(cmd3sub1AdditionalEnv)>>

## <</Stencil::Block>>
- main: ./cmd/cmd3-sub2
id: &name cmd3-sub2
binary: *name
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ldflags:
- '-w -s -X "github.com/getoutreach/gobox/pkg/app.Version=v{{ .Version }}"'
- '-X "main.HoneycombTracingKey={{ .Env.HONEYCOMB_APIKEY }}"'
- '-X "main.TeleforkAPIKey={{ .Env.TELEFORK_APIKEY }}"'
env:
- CGO_ENABLED=0
## <<Stencil::Block(cmd3sub2AdditionalEnv)>>

## <</Stencil::Block>>

archives: []
checksum:
Expand Down
2 changes: 2 additions & 0 deletions templates/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ func TestGoreleaserYml(t *testing.T) {
"commands": []interface{}{
"cmd1",
"cmd2",
"cmd3-sub1",
"cmd3-sub2",
},
})
st.Run(true)
Expand Down

0 comments on commit 6b7d17b

Please sign in to comment.