Skip to content

Commit ef38f59

Browse files
toppercodesampagent
andcommitted
ci: upgrade go/lint and derive provider version from tags
Amp-Thread-ID: https://ampcode.com/threads/T-019cb11d-d0b4-724b-938e-a9eb7f44c002 Co-authored-by: Amp <amp@ampcode.com>
1 parent 60598a8 commit ef38f59

7 files changed

Lines changed: 85 additions & 29 deletions

File tree

.github/workflows/pr.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ jobs:
3030
go-version-file: go.mod
3131
cache: false
3232

33-
- run: echo "GOLANGCI_LINT_VERSION=$(go list -m -f '{{.Version}}' github.com/golangci/golangci-lint)" >> $GITHUB_ENV
34-
- uses: golangci/golangci-lint-action@v4
35-
with:
36-
version: ${{ env.GOLANGCI_LINT_VERSION }}
37-
args: --timeout=5m
33+
- name: Install golangci-lint
34+
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
35+
36+
- name: Run golangci-lint
37+
run: |
38+
"$(go env GOPATH)/bin/golangci-lint" run --timeout=5m --output.text.path=stdout
3839
3940
build:
4041
name: Build
@@ -52,4 +53,4 @@ jobs:
5253
cache: false
5354

5455
- name: Run build
55-
run: make build
56+
run: make build

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
name: Set up Go
2929
uses: actions/setup-go@v5
3030
with:
31-
go-version: 1.24.x
31+
go-version-file: go.mod
3232
-
3333
name: Import GPG key
3434
id: import_gpg

.goreleaser.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ builds:
88
flags:
99
- -trimpath
1010
ldflags:
11-
- -s -w -X axiom/provider.providerVersion={{.Version}}
11+
- -s -w -X terraform-provider-axiom-provider/axiom.providerVersion={{.Version}}
1212
goos:
1313
- darwin
1414
- freebsd
@@ -43,4 +43,4 @@ release:
4343
#disable: true
4444
draft: false
4545
changelog:
46-
skip: true
46+
skip: true

Makefile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@ HOSTNAME=locally
33
NAMESPACE=debug
44
NAME=axiom
55
BINARY=terraform-provider-${NAME}
6-
VERSION=1.4.3
6+
GIT_TAG:=$(shell git describe --tags --exact-match 2>/dev/null)
7+
VERSION?=$(if $(GIT_TAG),$(patsubst v%,%,$(GIT_TAG)),dev)
8+
LDFLAGS=-X terraform-provider-axiom-provider/axiom.providerVersion=${VERSION}
79
OS_ARCH=darwin_arm64
810

911
default: install
1012

1113
build:
12-
go build -o ${BINARY}
14+
go build -ldflags "${LDFLAGS}" -o ${BINARY}
1315

1416
release:
15-
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
16-
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
17-
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
18-
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
19-
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
20-
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
21-
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
22-
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
23-
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
24-
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
25-
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
26-
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64
17+
GOOS=darwin GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_darwin_amd64
18+
GOOS=freebsd GOARCH=386 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_freebsd_386
19+
GOOS=freebsd GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
20+
GOOS=freebsd GOARCH=arm go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_freebsd_arm
21+
GOOS=linux GOARCH=386 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_linux_386
22+
GOOS=linux GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_linux_amd64
23+
GOOS=linux GOARCH=arm go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_linux_arm
24+
GOOS=openbsd GOARCH=386 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_openbsd_386
25+
GOOS=openbsd GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
26+
GOOS=solaris GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_solaris_amd64
27+
GOOS=windows GOARCH=386 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_windows_386
28+
GOOS=windows GOARCH=amd64 go build -ldflags "${LDFLAGS}" -o ./bin/${BINARY}_${VERSION}_windows_amd64
2729

2830
generate:
2931
go generate ./...
@@ -37,4 +39,3 @@ test:
3739

3840
testacc:
3941
TF_ACC=1 go test -count=1 -parallel=4 -timeout 10m -v ./...
40-

axiom/provider.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package axiom
22

33
import (
44
"context"
5+
"fmt"
56
"os"
67
"strings"
78

@@ -15,9 +16,20 @@ import (
1516
ax "github.com/axiomhq/axiom-go/axiom"
1617
)
1718

18-
const (
19-
providerUserAgent = "terraform-provider-axiom/v1.4.6"
20-
)
19+
var providerVersion = "dev"
20+
21+
func providerUserAgent() string {
22+
version := strings.TrimSpace(providerVersion)
23+
if version == "" {
24+
version = "dev"
25+
}
26+
27+
if !strings.HasPrefix(version, "v") {
28+
version = fmt.Sprintf("v%s", version)
29+
}
30+
31+
return fmt.Sprintf("terraform-provider-axiom/%s", version)
32+
}
2133

2234
// Ensure the implementation satisfies the expected interfaces
2335
var (
@@ -94,7 +106,7 @@ func (p *axiomProvider) Configure(ctx context.Context, req provider.ConfigureReq
94106

95107
ops := []ax.Option{
96108
ax.SetAPITokenConfig(apiToken),
97-
ax.SetUserAgent(providerUserAgent),
109+
ax.SetUserAgent(providerUserAgent()),
98110
}
99111

100112
if baseUrl != "" {

axiom/provider_version_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package axiom
2+
3+
import "testing"
4+
5+
func TestProviderUserAgent(t *testing.T) {
6+
original := providerVersion
7+
t.Cleanup(func() {
8+
providerVersion = original
9+
})
10+
11+
tests := []struct {
12+
name string
13+
version string
14+
expected string
15+
}{
16+
{
17+
name: "empty falls back to dev",
18+
version: "",
19+
expected: "terraform-provider-axiom/vdev",
20+
},
21+
{
22+
name: "plain semver gets v prefix",
23+
version: "1.5.0",
24+
expected: "terraform-provider-axiom/v1.5.0",
25+
},
26+
{
27+
name: "v-prefixed semver remains unchanged",
28+
version: "v1.5.0",
29+
expected: "terraform-provider-axiom/v1.5.0",
30+
},
31+
}
32+
33+
for _, tt := range tests {
34+
t.Run(tt.name, func(t *testing.T) {
35+
providerVersion = tt.version
36+
37+
if got := providerUserAgent(); got != tt.expected {
38+
t.Fatalf("providerUserAgent() = %q, expected %q", got, tt.expected)
39+
}
40+
})
41+
}
42+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module terraform-provider-axiom-provider
22

3-
go 1.24.0
3+
go 1.25.0
44

55
require (
66
github.com/axiomhq/axiom-go v0.26.2

0 commit comments

Comments
 (0)