diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fa42a81..30389fa 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,11 +32,12 @@ jobs: with: go-version: '1.20' - - name: Set version - run: V=${{ github.ref_name }} && VT="${V#v}" && sed "s@APP_VERSION@$VT@" misc/version.go.in > misc/version.go + - name: Get version + id: get_version + uses: battila7/get-version-action@v2 - name: Build - run: GOOS=linux GOARCH=${{ matrix.TARGET }} CGO_ENABLED=0 go build -ldflags="-s -w" -v -o nxs-backup + run: GOOS=linux GOARCH=${{ matrix.TARGET }} CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/nixys/nxs-backup/misc.Version=${{ steps.get_version.outputs.version-without-v }}" -v -o nxs-backup - name: Run UPX uses: crazy-max/ghaction-upx@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90276c7..55ae2c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,11 +18,8 @@ jobs: with: go-version: '1.20' - - name: Set version - run: V=${{ github.ref_name }} && VT="${V#v}" && sed "s@APP_VERSION@$VT@" misc/version.go.in > misc/version.go - - name: Build - run: CGO_ENABLED=0 go build -v + run: CGO_ENABLED=0 go build -ldflags="-s -w -X github.com/nixys/nxs-backup/misc.Version=3-test-build" -v - name: Test run: go test -v ./... diff --git a/ctx/args.go b/ctx/args.go index 6d3a3fa..7dfca3f 100755 --- a/ctx/args.go +++ b/ctx/args.go @@ -71,5 +71,5 @@ func ReadArgs() (p ArgsParams, err error) { } func (args) Version() string { - return "nxs-backup " + misc.VERSION + return "nxs-backup " + misc.Version } diff --git a/ctx/context.go b/ctx/context.go index 403a0c1..61fae35 100755 --- a/ctx/context.go +++ b/ctx/context.go @@ -165,7 +165,7 @@ func appInit(c *Ctx, cfgPath string) (app, error) { if conf.Server.Metrics.Enabled { nva := 0.0 - ver, _ := semver.NewVersion(misc.VERSION) + ver, _ := semver.NewVersion(misc.Version) newVer, _, _ := misc.CheckNewVersionAvailable(strconv.FormatUint(ver.Major(), 10)) if newVer != "" { nva = 1 diff --git a/misc/generals.go b/misc/generals.go index 1ae9aa1..7b4fce7 100755 --- a/misc/generals.go +++ b/misc/generals.go @@ -37,7 +37,10 @@ const ( External BackupType = "external" ) -var DecadesBackupDays = []string{"1", "11", "21"} +var ( + DecadesBackupDays = []string{"1", "11", "21"} + Version string +) func AllowedBackupTypesList() []string { return []string{ @@ -190,7 +193,7 @@ func CheckNewVersionAvailable(ver string) (string, string, error) { if err != nil { return "", "", err } - curVer, err := semver.NewVersion(VERSION) + curVer, err := semver.NewVersion(Version) if err != nil { return "", "", err } diff --git a/misc/version.go.in b/misc/version.go.in deleted file mode 100755 index cbb2cc9..0000000 --- a/misc/version.go.in +++ /dev/null @@ -1,4 +0,0 @@ -package misc - -// VERSION is a program version generated using nxs-build-tools -const VERSION = "APP_VERSION" diff --git a/modules/storage/sftp/sftp.go b/modules/storage/sftp/sftp.go index bef76ab..d91a409 100755 --- a/modules/storage/sftp/sftp.go +++ b/modules/storage/sftp/sftp.go @@ -48,7 +48,7 @@ func Init(name string, params Params) (*SFTP, error) { Auth: []ssh.AuthMethod{}, HostKeyCallback: ssh.InsecureIgnoreHostKey(), Timeout: params.ConnectTimeout * time.Second, - ClientVersion: "SSH-2.0-" + "nxs-backup/" + misc.VERSION, + ClientVersion: "SSH-2.0-" + "nxs-backup/" + misc.Version, } if params.Password != "" {