Skip to content

Commit

Permalink
feat(#43): Change var Version instead of constant
Browse files Browse the repository at this point in the history
Changes:
 - Used `Version` var to set app version instead of constant
 - Updated ci workflow
 - Removed version.go.in file, used for set app version on build step

Refs: #43
  • Loading branch information
randreev1321 committed Jun 13, 2024
1 parent ff7158a commit cd99716
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
2 changes: 1 addition & 1 deletion ctx/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ func ReadArgs() (p ArgsParams, err error) {
}

func (args) Version() string {
return "nxs-backup " + misc.VERSION
return "nxs-backup " + misc.Version
}
2 changes: 1 addition & 1 deletion ctx/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions misc/generals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions misc/version.go.in

This file was deleted.

2 changes: 1 addition & 1 deletion modules/storage/sftp/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down

0 comments on commit cd99716

Please sign in to comment.