Skip to content

Commit

Permalink
Add build info and build script
Browse files Browse the repository at this point in the history
  • Loading branch information
LDLDL committed Aug 27, 2023
1 parent 4e4869d commit 0d0f84a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ config.json
# log file
cfddns.log

# linux binary name
cfddns-go
# build path
release/*
25 changes: 19 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@ import (
flag "github.com/spf13/pflag"
)

var conf = flag.StringP("conf", "c", "./config.json", "Config file path")
var pLogPath = flag.StringP("log", "l", "", "Log file path")
var onetime = flag.BoolP("onetime", "o", false, "Run just once")
var usedns = flag.BoolP("usedns", "u", false, "Use dns to check your domain record")
var nolog = flag.BoolP("nolog", "n", false, "Do not log to any file")
var help = flag.BoolP("help", "h", false, "Print help")
var (
buildCommit string
buildDate string
)

var (
conf = flag.StringP("conf", "c", "./config.json", "Config file path")
pLogPath = flag.StringP("log", "l", "", "Log file path")
onetime = flag.BoolP("onetime", "o", false, "Run just once")
usedns = flag.BoolP("usedns", "u", false, "Use dns to check your domain record")
nolog = flag.BoolP("nolog", "n", false, "Do not log to any file")
help = flag.BoolP("help", "h", false, "Print help")
version = flag.BoolP("version", "v", false, "Print version")
)

var config Config

Expand Down Expand Up @@ -49,6 +57,11 @@ func init() {
os.Exit(0)
}

if *version {
fmt.Printf("CloudFlare DDns go %s, built at %s\n", buildCommit, buildDate)
os.Exit(0)
}

if *usedns {
getIPFunc = GetIPByDns
}
Expand Down
37 changes: 37 additions & 0 deletions release/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import glob
import subprocess
import datetime

subprocess.run("rm ./cfddns-go*", shell=True)

commitId = subprocess.run("git rev-parse --short HEAD", shell=True, capture_output=True)
commitId = commitId.stdout.decode().strip()

time = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M')

t = [['linux', 'amd64'],
['linux', 'arm'],
['linux', 'arm64'],
['linux', 'mips'],
['linux', 'mipsle'],
['windows', 'amd64'],
]

for o, a in t:
subprocess.run(
f'''env GOOS="{o}" GOARCH="{a}" '''
f'''go build -ldflags="-s -w '''
f'''-X main.buildCommit={commitId} -X \'main.buildDate={time}\'" '''
f'''-o cfddns-go_{o}_{a}{".exe" if o == "windows" else ""} '''
f'''../''', shell=True
)

bins = glob.glob("cfddns-go*")
for bin in bins:
if bin.endswith(".exe"):
subprocess.run(f"zip {bin}.zip {bin}", shell=True)
os.remove(bin)
else:
subprocess.run(f"gzip {bin}", shell=True)

0 comments on commit 0d0f84a

Please sign in to comment.