mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
CICD: GoReleaser version (#2737)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
committed by
GitHub
parent
8ed137aff5
commit
17da0bc69f
14
.github/workflows/pr_test.yml
vendored
14
.github/workflows/pr_test.yml
vendored
@ -38,16 +38,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
go install golang.org/x/tools/cmd/stringer@latest
|
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
|
id: build_binaries_tagged
|
||||||
name: Build binaries (if tagged)
|
name: Build binaries (if tagged)
|
||||||
@ -57,8 +47,6 @@ jobs:
|
|||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: latest
|
version: latest
|
||||||
args: build
|
args: build
|
||||||
env:
|
|
||||||
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
|
|
||||||
-
|
-
|
||||||
id: build_binaries_not_tagged
|
id: build_binaries_not_tagged
|
||||||
name: Build binaries (not tagged)
|
name: Build binaries (not tagged)
|
||||||
@ -68,8 +56,6 @@ jobs:
|
|||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: latest
|
version: latest
|
||||||
args: build --snapshot
|
args: build --snapshot
|
||||||
env:
|
|
||||||
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
|
|
||||||
integration-test-providers:
|
integration-test-providers:
|
||||||
needs: build
|
needs: build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
13
.github/workflows/release_draft.yml
vendored
13
.github/workflows/release_draft.yml
vendored
@ -49,18 +49,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
go install golang.org/x/tools/cmd/stringer@latest
|
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
|
id: release
|
||||||
name: Goreleaser release
|
name: Goreleaser release
|
||||||
@ -71,4 +59,3 @@ jobs:
|
|||||||
args: release
|
args: release
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
|
|
||||||
|
@ -18,7 +18,8 @@ builds:
|
|||||||
- goos: freebsd
|
- goos: freebsd
|
||||||
goarch: "386"
|
goarch: "386"
|
||||||
ldflags:
|
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:
|
before:
|
||||||
hooks:
|
hooks:
|
||||||
- go fmt ./...
|
- go fmt ./...
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sha = flag.String("sha", "", "SHA of current commit")
|
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
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
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"
|
pkg := "github.com/StackExchange/dnscontrol/v4"
|
||||||
|
|
||||||
build := func(out, goos string) {
|
build := func(out, goos string) {
|
||||||
|
@ -25,11 +25,6 @@ const (
|
|||||||
|
|
||||||
var commands = []*cli.Command{}
|
var commands = []*cli.Command{}
|
||||||
|
|
||||||
// These are set by/for goreleaser
|
|
||||||
var (
|
|
||||||
version = "dev"
|
|
||||||
)
|
|
||||||
|
|
||||||
func cmd(cat string, c *cli.Command) bool {
|
func cmd(cat string, c *cli.Command) bool {
|
||||||
c.Category = cat
|
c.Category = cat
|
||||||
commands = append(commands, c)
|
commands = append(commands, c)
|
||||||
@ -52,7 +47,7 @@ func Run(v string) int {
|
|||||||
app.Version = version
|
app.Version = version
|
||||||
app.Name = "dnscontrol"
|
app.Name = "dnscontrol"
|
||||||
app.HideVersion = true
|
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{
|
app.Flags = []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "v",
|
Name: "v",
|
||||||
|
@ -4,10 +4,14 @@ import (
|
|||||||
_ "embed" // Required by go:embed
|
_ "embed" // Required by go:embed
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
versionInfo "github.com/StackExchange/dnscontrol/v4/pkg/version"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GoReleaser: version
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
)
|
||||||
|
|
||||||
var _ = cmd(catUtils, func() *cli.Command {
|
var _ = cmd(catUtils, func() *cli.Command {
|
||||||
var args TypesArgs
|
var args TypesArgs
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
@ -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("// 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("// To update it, run `dnscontrol write-types`.\n\n")
|
||||||
file.WriteString("// DNSControl version: " + versionInfo.Banner() + "\n")
|
file.WriteString("// " + version + "\n")
|
||||||
file.WriteString(dtsContent)
|
file.WriteString(dtsContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
13
main.go
13
main.go
@ -2,12 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v4/commands"
|
"github.com/StackExchange/dnscontrol/v4/commands"
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
|
||||||
_ "github.com/StackExchange/dnscontrol/v4/providers/_all"
|
_ "github.com/StackExchange/dnscontrol/v4/providers/_all"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
@ -17,22 +15,17 @@ import (
|
|||||||
// Version management. Goals:
|
// Version management. Goals:
|
||||||
// 1. Someone who just does "go get" has at least some information.
|
// 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.
|
// 2. If built with build/build.go, more specific build information gets put in.
|
||||||
|
// GoReleaser: version
|
||||||
var (
|
var (
|
||||||
SHA = ""
|
version = "dev"
|
||||||
Version = ""
|
|
||||||
BuildTime = ""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
version.SHA = SHA
|
|
||||||
version.Semver = Version
|
|
||||||
version.BuildTime = BuildTime
|
|
||||||
if os.Getenv("CI") == "true" {
|
if os.Getenv("CI") == "true" {
|
||||||
color.NoColor = false
|
color.NoColor = false
|
||||||
}
|
}
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
|
||||||
if info, ok := debug.ReadBuildInfo(); !ok && info == nil {
|
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")
|
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))
|
||||||
}
|
}
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
package version
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"runtime/debug"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NOTE: main() updates these.
|
|
||||||
var (
|
|
||||||
BuildTime = ""
|
|
||||||
SHA = ""
|
|
||||||
Semver = ""
|
|
||||||
)
|
|
||||||
|
|
||||||
var versionCache string
|
|
||||||
|
|
||||||
// Banner returns the version banner.
|
|
||||||
func Banner() string {
|
|
||||||
if versionCache != "" {
|
|
||||||
return versionCache
|
|
||||||
}
|
|
||||||
|
|
||||||
var version string
|
|
||||||
if SHA != "" {
|
|
||||||
version = fmt.Sprintf("%s (%s)", Semver, SHA)
|
|
||||||
} else {
|
|
||||||
version = fmt.Sprintf("%s-dev", Semver) // no SHA. '0.x.y-dev' indicates it is run from source without build script.
|
|
||||||
}
|
|
||||||
if info, ok := debug.ReadBuildInfo(); !ok && info == nil {
|
|
||||||
version += " (non-modules)"
|
|
||||||
}
|
|
||||||
if BuildTime != "" {
|
|
||||||
i, err := strconv.ParseInt(BuildTime, 10, 64)
|
|
||||||
if err == nil {
|
|
||||||
tm := time.Unix(i, 0)
|
|
||||||
version += fmt.Sprintf(" built %s", tm.Format(time.RFC822))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
versionCache = version
|
|
||||||
return version
|
|
||||||
}
|
|
@ -5,11 +5,15 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v4/pkg/version"
|
|
||||||
"github.com/StackExchange/dnscontrol/v4/providers"
|
"github.com/StackExchange/dnscontrol/v4/providers"
|
||||||
hxcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/apiclient"
|
hxcl "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/apiclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GoReleaser: version
|
||||||
|
var (
|
||||||
|
version = "dev"
|
||||||
|
)
|
||||||
|
|
||||||
// HXClient describes a connection to the hexonet API.
|
// HXClient describes a connection to the hexonet API.
|
||||||
type HXClient struct {
|
type HXClient struct {
|
||||||
APILogin string
|
APILogin string
|
||||||
@ -36,7 +40,7 @@ func newProvider(conf map[string]string) (*HXClient, error) {
|
|||||||
api := &HXClient{
|
api := &HXClient{
|
||||||
client: hxcl.NewAPIClient(),
|
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"]
|
api.APILogin, api.APIPassword, api.APIEntity = conf["apilogin"], conf["apipassword"], conf["apientity"]
|
||||||
if conf["debugmode"] == "1" {
|
if conf["debugmode"] == "1" {
|
||||||
api.client.EnableDebugMode()
|
api.client.EnableDebugMode()
|
||||||
|
Reference in New Issue
Block a user