diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 394200d..32c89c0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -44,7 +44,7 @@ jobs: run: | $env:DEV_VERSION = ((Get-Content .\Makefile -TotalCount 1) -split '=')[1].Trim() $env:CGO_CXXFLAGS="-I${{github.workspace}}\libs\webview2\build\native\include" - go build -ldflags "-H=windowsgui -X github.com/pydio/cells-sync/common.Version=$env:DEV_VERSION -X github.com/pydio/cells-sync/common.BuildStamp=20230526 -X github.com/pydio/cells-sync/common.BuildRevision=rev" -o cells-sync.exe + go build -a -trimpath -ldflags "-H=windowsgui -X github.com/pydio/cells-sync/common.Version=$env:DEV_VERSION" -o cells-sync.exe - name: Upload uses: actions/upload-artifact@v3 @@ -52,6 +52,18 @@ jobs: name: cells-sync-windows path: cells-sync.exe + - name: Build No-UI Version + run: | + $env:DEV_VERSION = ((Get-Content .\Makefile -TotalCount 1) -split '=')[1].Trim() + $env:CGO_ENABLED=0 + go build -a -trimpath --tags pure -ldflags "-H=windowsgui -X github.com/pydio/cells-sync/common.Version=$env:DEV_VERSION" -o cells-sync-noui.exe + + - name: Upload No-UI Version + uses: actions/upload-artifact@v3 + with: + name: cells-sync-noui-windows + path: cells-sync-noui.exe + - name: Checkout Artifacts uses: actions/checkout@v4 with: diff --git a/Makefile b/Makefile index 68de947..ed370e9 100644 --- a/Makefile +++ b/Makefile @@ -18,39 +18,34 @@ dep: dev: go build \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${DEV_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=2023-01-01T00:00:00 \ - -X github.com/pydio/cells-sync/common.BuildRevision=dev" \ - -o cells-sync main.go + -ldflags "-X github.com/pydio/cells-sync/common.Version=${DEV_VERSION}" \ + -o cells-sync dist: go build -a -trimpath \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ - -o cells-sync main.go + -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ + -o cells-sync silicon: GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 go build -a -trimpath \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ - -o cells-sync-m1 main.go + -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ + -o cells-sync-m1 pure: - go build -a -trimpath --tags pure \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ - -o cells-sync-noui main.go + CGO_ENABLED=0 go build -a -trimpath --tags pure \ + -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ + -o cells-sync-noui win: - go build \ - -ldflags "-H=windowsgui -X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ + go build -a -trimpath \ + -ldflags "-H=windowsgui -X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ -o cells-sync.exe +win_pure: + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -trimpath --tags pure \ + -ldflags "-H=windowsgui -X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ + -o cells-sync-noui.exe + rsrc: ${GOPATH}/bin/rsrc -arch amd64 -ico app/resources/icon.ico @@ -69,10 +64,8 @@ libayatana: go mod edit -replace github.com/getlantern/systray=github.com/nekr0z/systray@v1.1.1-0.20210610115307-891b38719d73 go mod download github.com/getlantern/systray go build \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ - -o cells-sync main.go + -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ + -o cells-sync . go mod edit -dropreplace github.com/getlantern/systray xgowin: @@ -81,9 +74,7 @@ xgowin: --image ${XGO_IMAGE} \ --targets windows/amd64 \ -ldflags "-H=windowsgui \ - -X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ + -X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ . xgowinnoui: @@ -91,22 +82,7 @@ xgowinnoui: -out "cells-sync-noui" \ --image ${XGO_IMAGE} \ --targets windows/amd64 \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ - . - -## Still broken -# To limit build to a given minimal version of MacOS, rather use: -# --targets darwin-10.11/amd64 \ -#xgodarwin: -# ${XGO_BIN} -go 1.19 \ - -out "cells-sync" \ - --image ${XGO_IMAGE} \ - --targets darwin-11.1/amd64 \ - -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION} \ - -X github.com/pydio/cells-sync/common.BuildStamp=${TODAY} \ - -X github.com/pydio/cells-sync/common.BuildRevision=${GITREV}" \ + -ldflags "-X github.com/pydio/cells-sync/common.Version=${CELLS_VERSION}" \ . clean: diff --git a/common/common.go b/common/common.go index c4a315b..d567bf3 100644 --- a/common/common.go +++ b/common/common.go @@ -24,6 +24,7 @@ import ( "context" "encoding/json" "fmt" + "runtime/debug" "time" "github.com/pydio/cells/v4/common/log" @@ -34,11 +35,9 @@ import ( ) var ( - Version = "0.1.0" - BuildStamp = "" - BuildRevision = "" - PackageType = "CellsSync" - PackageLabel = "Cells Sync Client" + Version = "0.1.0" + PackageType = "CellsSync" + PackageLabel = "Cells Sync Client" ) // EndpointInfo provides information about a connection to an endpoint @@ -219,17 +218,33 @@ func MessageFromData(d []byte) *Message { // PrintVersion prints information about the current build func PrintVersion() { - var t time.Time - if BuildStamp != "" { - t, _ = time.Parse("2006-01-02T15:04:05", BuildStamp) - } else { - t = time.Now() - } + rev, ts := VcsInfo() fmt.Println("") fmt.Println(" " + fmt.Sprintf("%s (%s)", PackageLabel, Version)) - fmt.Println(" " + fmt.Sprintf("Published on %s", t.Format(time.RFC822Z))) - fmt.Println(" " + fmt.Sprintf("Revision number %s", BuildRevision)) + fmt.Println(" " + fmt.Sprintf("Revision Commit %s", rev)) + fmt.Println(" " + fmt.Sprintf("Commit Stamp %s", ts.Format(time.RFC822Z))) fmt.Println("") } + +// VcsInfo returns the vcs.revision and vcs.time debug info +func VcsInfo() (string, time.Time) { + rev := "" + ts := time.Now() + if info, ok := debug.ReadBuildInfo(); ok { + for _, s := range info.Settings { + fmt.Println(s.Key, s.Value) + switch s.Key { + case "vcs.revision": + rev = s.Value + case "vcs.time": + if s.Value != "" { + ts, _ = time.Parse("2006-01-02T15:04:05Z", s.Value) + } + default: + } + } + } + return rev, ts +} diff --git a/control/http-server.go b/control/http-server.go index ef229cd..1811944 100644 --- a/control/http-server.go +++ b/control/http-server.go @@ -199,12 +199,13 @@ func (h *HttpServer) InitHandlers() { if req.Check { go GetBus().Pub(req, TopicUpdate) } else if req.Version { + rev, ts := common.VcsInfo() // Just publish version back to client message := &common.Message{Type: "UPDATE", Content: &common.UpdateVersion{ PackageName: common.PackageType, Version: common.Version, - Revision: common.BuildRevision, - BuildStamp: common.BuildStamp, + Revision: rev, + BuildStamp: ts.Format(time.RFC822Z), }} session.Write(message.Bytes()) } diff --git a/control/updater.go b/control/updater.go index 7031f01..3cc18d5 100644 --- a/control/updater.go +++ b/control/updater.go @@ -270,10 +270,13 @@ func (u *Updater) ApplyUpdate(ctx context.Context, p *update.Package, dryRun boo } dataDir := config.SyncClientDataDir() - oldPath := filepath.Join(dataDir, "backups", "revision-"+common.BuildStamp) + _, ts := common.VcsInfo() + buildStamp := "revision-" + ts.Format(time.RFC3339) + + oldPath := filepath.Join(dataDir, "backups", buildStamp) err := os.MkdirAll(filepath.Join(dataDir, "backups"), 0755) if err != nil { - oldPath = filepath.Join(dataDir, "revision-"+common.BuildStamp) + oldPath = filepath.Join(dataDir, buildStamp) } reader := net.BodyWithProgressMonitor(resp, pgChan, nil)