Skip to content

Commit

Permalink
feat: display dyndns version in discord username
Browse files Browse the repository at this point in the history
And display release date when running dyndns --version
  • Loading branch information
mlcdf committed Apr 27, 2021
1 parent 808a9ba commit c93127a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
uses: actions/checkout@v2
- name: Build binaries
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags release -o "dyndns-$(git describe --tags)-linux-amd64" -ldflags "-X main.Version=$(git describe --tags)"
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -tags release -o "dyndns-$(git describe --tags)-linux-arm" -ldflags "-X main.Version=$(git describe --tags)"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags release -o "dyndns-$(git describe --tags)-linux-arm64" -ldflags "-X main.Version=$(git describe --tags)"
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags release -o "dyndns-$(git describe --tags)-darwin-amd64" -ldflags "-X main.Version=$(git describe --tags)"
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags release -o "dyndns-$(git describe --tags)-windows-amd64.exe" -ldflags "-X main.Version=$(git describe --tags)"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags release -o "dyndns-$(git describe --tags)-linux-amd64" -ldflags "-X 'github.com/mlcdf/dyndns/internal/build.Version=$(git describe --tags)' -X 'github.com/mlcdf/dyndns/internal/build.Time=$(date)'"
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -tags release -o "dyndns-$(git describe --tags)-linux-arm" -ldflags "-X 'github.com/mlcdf/dyndns/internal/build.Version=$(git describe --tags)' -X 'github.com/mlcdf/dyndns/internal/build.Time=$(date)'"
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -tags release -o "dyndns-$(git describe --tags)-linux-arm64" -ldflags "-X 'github.com/mlcdf/dyndns/internal/build.Version=$(git describe --tags)' -X 'github.com/mlcdf/dyndns/internal/build.Time=$(date)'"
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -tags release -o "dyndns-$(git describe --tags)-darwin-amd64" -ldflags "-X 'github.com/mlcdf/dyndns/internal/build.Version=$(git describe --tags)' -X 'github.com/mlcdf/dyndns/internal/build.Time=$(date)'"
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags release -o "dyndns-$(git describe --tags)-windows-amd64.exe" -ldflags "-X 'github.com/mlcdf/dyndns/internal/build.Version=$(git describe --tags)' -X 'github.com/mlcdf/dyndns/internal/build.Time=$(date)'"
- name: Upload release artifacts
uses: actions/github-script@v3
with:
Expand Down
19 changes: 19 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package build

// Version is set at build time using -ldflags="-X 'github.com/mlcdf/dyndns/internal/build.Version=dyndns v1.0.0'
var Version = "(devel)"

// Time is set at build time using -ldflags="-X 'github.com/mlcdf/dyndns/internal/build.Time=$(date)'
var Time string

func Short() string {
return "dyndns " + Version
}

func Long() string {
info := Short()
if Time != "" {
info = info + " (release date: " + Time + ")"
}
return info
}
3 changes: 3 additions & 0 deletions internal/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net/http"
"os"
"time"

"github.com/mlcdf/dyndns/internal/build"
)

type Client struct {
Expand Down Expand Up @@ -86,6 +88,7 @@ func (c *Client) PostSuccess(webhook *Webhook) error {
func (c *Client) Post(webhook *Webhook) error {
webhook.Embeds[0].TimeStamp = time.Now().UTC().Format(time.RFC3339)
webhook.Embeds[0].Footer.Text = hostname
webhook.Username = build.Short()

payload, err := json.Marshal(webhook)
if err != nil {
Expand Down
17 changes: 2 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io"
"log"
"os"
"runtime/debug"

"github.com/mlcdf/dyndns/internal/build"
"github.com/mlcdf/dyndns/internal/discord"
"github.com/mlcdf/dyndns/internal/dyndns"
"github.com/mlcdf/dyndns/internal/gandi"
Expand All @@ -31,11 +31,6 @@ How to create a Discord webhook: https://support.discord.com/hc/en-us/articles/2
How to generate your Gandi token: https://docs.gandi.net/en/domain_names/advanced_users/api.html
`

// Version can be set at link time to override debug.BuildInfo.Main.Version,
// which is "(devel)" when building from within the module. See
// golang.org/issue/29814 and golang.org/issue/29228.
var Version string

func main() {
log.SetFlags(0)
flag.Usage = func() { fmt.Fprint(os.Stderr, usage) }
Expand Down Expand Up @@ -65,15 +60,7 @@ func main() {
flag.Parse()

if versionFlag {
if Version != "" {
fmt.Println(Version)
return
}
if buildInfo, ok := debug.ReadBuildInfo(); ok {
fmt.Println(buildInfo.Main.Version)
return
}
fmt.Println("(unknown)")
fmt.Println(build.Long())
return
}

Expand Down

0 comments on commit c93127a

Please sign in to comment.