mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-09-20 06:46:19 +08:00
parent
b71fd634b9
commit
9873f9f4b2
24
.github/workflows/pr_test.yml
vendored
24
.github/workflows/pr_test.yml
vendored
|
@ -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/cache@v3.3.2
|
||||
with:
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
|
13
.github/workflows/release_draft.yml
vendored
13
.github/workflows/release_draft.yml
vendored
|
@ -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
|
||||
|
@ -71,4 +59,3 @@ jobs:
|
|||
args: release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GORELEASER_CURRENT_TAG: ${{ steps.version.outputs.TAG_NAME }}
|
||||
|
|
|
@ -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 ./...
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
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() {
|
||||
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) {
|
||||
|
|
|
@ -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)
|
||||
|
@ -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",
|
||||
|
|
|
@ -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{
|
||||
|
@ -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
|
||||
|
|
13
main.go
13
main.go
|
@ -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"
|
||||
)
|
||||
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
"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
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue