Skip to content

Commit

Permalink
CICD: GoReleaser version #2 (#2761)
Browse files Browse the repository at this point in the history
  • Loading branch information
cafferata authored Jan 4, 2024
1 parent b71fd63 commit 9873f9f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 98 deletions.
24 changes: 6 additions & 18 deletions .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ env:
jobs:
build:
runs-on: ubuntu-latest
container:
image: golang:1.21
env:
TEST_RESULTS: "/tmp/test-results"
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: stable
- name: restore_cache
uses: actions/[email protected]
with:
Expand All @@ -39,16 +43,6 @@ jobs:
run: |
go install golang.org/x/tools/cmd/stringer@latest
# For some reason goreleaser isn't correctly setting the version
# string used by "dnscontrol version". Therefore, we're forcing the
# string using the GORELEASER_CURRENT_TAG feature.
# TODO(tlim): Use the native gorelease version mechanism.
- name: Retrieve version
id: version
run: |
echo "TAG_NAME=$(git config --global --add safe.directory /__w/dnscontrol/dnscontrol ; git describe)" >> $GITHUB_OUTPUT
- name: Reveal version
run: echo ${{ steps.version.outputs.TAG_NAME }}
-
id: build_binaries_tagged
name: Build binaries (if tagged)
Expand All @@ -58,19 +52,13 @@ jobs:
distribution: goreleaser
version: latest
args: build
env:
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
-
id: build_binaries_not_tagged
name: Build binaries (not tagged)
if: github.ref_type != 'tag'
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: build --snapshot
env:
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
integration-test-providers:
needs: build
runs-on: ubuntu-latest
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/release_draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ jobs:
run: |
go install golang.org/x/tools/cmd/stringer@latest
# For some reason goreleaser isn't correctly setting the version
# string used by "dnscontrol version". Therefore, we're forcing the
# string using the GORELEASER_CURRENT_TAG feature.
# TODO(tlim): Use the native gorelease version mechanism.

- name: Retrieve version
id: version
run: |
echo "TAG_NAME=$(git config --global --add safe.directory /__w/dnscontrol/dnscontrol ; git describe --tags)" >> $GITHUB_OUTPUT
- name: Reveal version
run: echo ${{ steps.version.outputs.TAG_NAME }}
-
id: release
name: Goreleaser release
Expand All @@ -71,4 +59,3 @@ jobs:
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ builds:
- goos: freebsd
goarch: "386"
ldflags:
- -linkmode=internal -s -w -X main.Version="{{ .Version }}" -X main.SHA="{{ .FullCommit }}" -X main.BuildTime={{ .Timestamp }}
- -linkmode=internal -s -w
- -X main.version={{ .Version }}
before:
hooks:
- go fmt ./...
Expand Down
3 changes: 1 addition & 2 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"strings"
"time"
)

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

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

build := func(out, goos string) {
Expand Down
7 changes: 1 addition & 6 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const (

var commands = []*cli.Command{}

// These are set by/for goreleaser
var (
version = "dev"
)

func cmd(cat string, c *cli.Command) bool {
c.Category = cat
commands = append(commands, c)
Expand All @@ -52,7 +47,7 @@ func Run(v string) int {
app.Version = version
app.Name = "dnscontrol"
app.HideVersion = true
app.Usage = "dnscontrol is a compiler and DSL for managing dns zones"
app.Usage = "DNSControl is a compiler and DSL for managing dns zones"
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "v",
Expand Down
8 changes: 6 additions & 2 deletions commands/writeTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import (
_ "embed" // Required by go:embed
"os"

versionInfo "github.com/StackExchange/dnscontrol/v4/pkg/version"
"github.com/urfave/cli/v2"
)

// GoReleaser: version
var (
version = "dev"
)

var _ = cmd(catUtils, func() *cli.Command {
var args TypesArgs
return &cli.Command{
Expand Down Expand Up @@ -50,7 +54,7 @@ func WriteTypes(args TypesArgs) error {

file.WriteString("// This file was automatically generated by DNSControl. Do not edit it directly.\n")
file.WriteString("// To update it, run `dnscontrol write-types`.\n\n")
file.WriteString("// DNSControl version: " + versionInfo.Banner() + "\n")
file.WriteString("// " + version + "\n")
file.WriteString(dtsContent)
if err != nil {
return err
Expand Down
13 changes: 3 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package main

import (
"fmt"
"log"
"os"
"runtime/debug"

"github.com/StackExchange/dnscontrol/v4/commands"
"github.com/StackExchange/dnscontrol/v4/pkg/version"
_ "github.com/StackExchange/dnscontrol/v4/providers/_all"
"github.com/fatih/color"
)
Expand All @@ -17,22 +15,17 @@ import (
// Version management. Goals:
// 1. Someone who just does "go get" has at least some information.
// 2. If built with build/build.go, more specific build information gets put in.
// GoReleaser: version
var (
SHA = ""
Version = ""
BuildTime = ""
version = "dev"
)

func main() {
version.SHA = SHA
version.Semver = Version
version.BuildTime = BuildTime
if os.Getenv("CI") == "true" {
color.NoColor = false
}
log.SetFlags(log.LstdFlags | log.Lshortfile)
if info, ok := debug.ReadBuildInfo(); !ok && info == nil {
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")
}
os.Exit(commands.Run("dnscontrol " + version.Banner()))
os.Exit(commands.Run("DNSControl " + version))
}
44 changes: 0 additions & 44 deletions pkg/version/version.go

This file was deleted.

8 changes: 6 additions & 2 deletions providers/hexonet/hexonetProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import (
"encoding/json"
"fmt"

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

// GoReleaser: version
var (
version = "dev"
)

// HXClient describes a connection to the hexonet API.
type HXClient struct {
APILogin string
Expand All @@ -36,7 +40,7 @@ func newProvider(conf map[string]string) (*HXClient, error) {
api := &HXClient{
client: hxcl.NewAPIClient(),
}
api.client.SetUserAgent("DNSControl", version.Banner())
api.client.SetUserAgent("DNSControl", version)
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
if conf["debugmode"] == "1" {
api.client.EnableDebugMode()
Expand Down

0 comments on commit 9873f9f

Please sign in to comment.