Skip to content

Commit 9873f9f

Browse files
authored
CICD: GoReleaser version #2 (#2761)
1 parent b71fd63 commit 9873f9f

File tree

9 files changed

+25
-98
lines changed

9 files changed

+25
-98
lines changed

.github/workflows/pr_test.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ env:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14-
container:
15-
image: golang:1.21
1614
env:
1715
TEST_RESULTS: "/tmp/test-results"
1816
steps:
1917
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: stable
2024
- name: restore_cache
2125
uses: actions/[email protected]
2226
with:
@@ -39,16 +43,6 @@ jobs:
3943
run: |
4044
go install golang.org/x/tools/cmd/stringer@latest
4145
42-
# For some reason goreleaser isn't correctly setting the version
43-
# string used by "dnscontrol version". Therefore, we're forcing the
44-
# string using the GORELEASER_CURRENT_TAG feature.
45-
# TODO(tlim): Use the native gorelease version mechanism.
46-
- name: Retrieve version
47-
id: version
48-
run: |
49-
echo "TAG_NAME=$(git config --global --add safe.directory /__w/dnscontrol/dnscontrol ; git describe)" >> $GITHUB_OUTPUT
50-
- name: Reveal version
51-
run: echo ${{ steps.version.outputs.TAG_NAME }}
5246
-
5347
id: build_binaries_tagged
5448
name: Build binaries (if tagged)
@@ -58,19 +52,13 @@ jobs:
5852
distribution: goreleaser
5953
version: latest
6054
args: build
61-
env:
62-
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
6355
-
6456
id: build_binaries_not_tagged
6557
name: Build binaries (not tagged)
6658
if: github.ref_type != 'tag'
6759
uses: goreleaser/goreleaser-action@v5
6860
with:
69-
distribution: goreleaser
70-
version: latest
7161
args: build --snapshot
72-
env:
73-
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
7462
integration-test-providers:
7563
needs: build
7664
runs-on: ubuntu-latest

.github/workflows/release_draft.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ jobs:
4949
run: |
5050
go install golang.org/x/tools/cmd/stringer@latest
5151
52-
# For some reason goreleaser isn't correctly setting the version
53-
# string used by "dnscontrol version". Therefore, we're forcing the
54-
# string using the GORELEASER_CURRENT_TAG feature.
55-
# TODO(tlim): Use the native gorelease version mechanism.
56-
57-
- name: Retrieve version
58-
id: version
59-
run: |
60-
echo "TAG_NAME=$(git config --global --add safe.directory /__w/dnscontrol/dnscontrol ; git describe --tags)" >> $GITHUB_OUTPUT
61-
62-
- name: Reveal version
63-
run: echo ${{ steps.version.outputs.TAG_NAME }}
6452
-
6553
id: release
6654
name: Goreleaser release
@@ -71,4 +59,3 @@ jobs:
7159
args: release
7260
env:
7361
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74-
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}

.goreleaser.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ builds:
1818
- goos: freebsd
1919
goarch: "386"
2020
ldflags:
21-
- -linkmode=internal -s -w -X main.Version="{{ .Version }}" -X main.SHA="{{ .FullCommit }}" -X main.BuildTime={{ .Timestamp }}
21+
- -linkmode=internal -s -w
22+
- -X main.version={{ .Version }}
2223
before:
2324
hooks:
2425
- go fmt ./...

build/build.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"os"
88
"os/exec"
99
"strings"
10-
"time"
1110
)
1211

1312
var sha = flag.String("sha", "", "SHA of current commit")
@@ -16,7 +15,7 @@ var goos = flag.String("os", "", "OS to build (linux, windows, or darwin) Defaul
1615

1716
func main() {
1817
flag.Parse()
19-
flags := fmt.Sprintf(`-s -w -X "main.SHA=%s" -X main.BuildTime=%d`, getVersion(), time.Now().Unix())
18+
flags := fmt.Sprintf(`-s -w -X "main.version=%s"`, getVersion())
2019
pkg := "github.com/StackExchange/dnscontrol/v4"
2120

2221
build := func(out, goos string) {

commands/commands.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ const (
2525

2626
var commands = []*cli.Command{}
2727

28-
// These are set by/for goreleaser
29-
var (
30-
version = "dev"
31-
)
32-
3328
func cmd(cat string, c *cli.Command) bool {
3429
c.Category = cat
3530
commands = append(commands, c)
@@ -52,7 +47,7 @@ func Run(v string) int {
5247
app.Version = version
5348
app.Name = "dnscontrol"
5449
app.HideVersion = true
55-
app.Usage = "dnscontrol is a compiler and DSL for managing dns zones"
50+
app.Usage = "DNSControl is a compiler and DSL for managing dns zones"
5651
app.Flags = []cli.Flag{
5752
&cli.BoolFlag{
5853
Name: "v",

commands/writeTypes.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import (
44
_ "embed" // Required by go:embed
55
"os"
66

7-
versionInfo "github.com/StackExchange/dnscontrol/v4/pkg/version"
87
"github.com/urfave/cli/v2"
98
)
109

10+
// GoReleaser: version
11+
var (
12+
version = "dev"
13+
)
14+
1115
var _ = cmd(catUtils, func() *cli.Command {
1216
var args TypesArgs
1317
return &cli.Command{
@@ -50,7 +54,7 @@ func WriteTypes(args TypesArgs) error {
5054

5155
file.WriteString("// This file was automatically generated by DNSControl. Do not edit it directly.\n")
5256
file.WriteString("// To update it, run `dnscontrol write-types`.\n\n")
53-
file.WriteString("// DNSControl version: " + versionInfo.Banner() + "\n")
57+
file.WriteString("// " + version + "\n")
5458
file.WriteString(dtsContent)
5559
if err != nil {
5660
return err

main.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ package main
22

33
import (
44
"fmt"
5-
"log"
65
"os"
76
"runtime/debug"
87

98
"github.com/StackExchange/dnscontrol/v4/commands"
10-
"github.com/StackExchange/dnscontrol/v4/pkg/version"
119
_ "github.com/StackExchange/dnscontrol/v4/providers/_all"
1210
"github.com/fatih/color"
1311
)
@@ -17,22 +15,17 @@ import (
1715
// Version management. Goals:
1816
// 1. Someone who just does "go get" has at least some information.
1917
// 2. If built with build/build.go, more specific build information gets put in.
18+
// GoReleaser: version
2019
var (
21-
SHA = ""
22-
Version = ""
23-
BuildTime = ""
20+
version = "dev"
2421
)
2522

2623
func main() {
27-
version.SHA = SHA
28-
version.Semver = Version
29-
version.BuildTime = BuildTime
3024
if os.Getenv("CI") == "true" {
3125
color.NoColor = false
3226
}
33-
log.SetFlags(log.LstdFlags | log.Lshortfile)
3427
if info, ok := debug.ReadBuildInfo(); !ok && info == nil {
3528
fmt.Fprint(os.Stderr, "Warning: dnscontrol was built without Go modules. See https://docs.dnscontrol.org/getting-started/getting-started#source for more information on how to build dnscontrol correctly.\n\n")
3629
}
37-
os.Exit(commands.Run("dnscontrol " + version.Banner()))
30+
os.Exit(commands.Run("DNSControl " + version))
3831
}

pkg/version/version.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

providers/hexonet/hexonetProvider.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ import (
55
"encoding/json"
66
"fmt"
77

8-
"github.com/StackExchange/dnscontrol/v4/pkg/version"
98
"github.com/StackExchange/dnscontrol/v4/providers"
109
hxcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/apiclient"
1110
)
1211

12+
// GoReleaser: version
13+
var (
14+
version = "dev"
15+
)
16+
1317
// HXClient describes a connection to the hexonet API.
1418
type HXClient struct {
1519
APILogin string
@@ -36,7 +40,7 @@ func newProvider(conf map[string]string) (*HXClient, error) {
3640
api := &HXClient{
3741
client: hxcl.NewAPIClient(),
3842
}
39-
api.client.SetUserAgent("DNSControl", version.Banner())
43+
api.client.SetUserAgent("DNSControl", version)
4044
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
4145
if conf["debugmode"] == "1" {
4246
api.client.EnableDebugMode()

0 commit comments

Comments
 (0)