Skip to content

Commit

Permalink
Remove BuildStamp and BuildRev variables, re-adapt build commands
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Sep 20, 2023
1 parent bffbe6e commit 895d085
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 62 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ 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
with:
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:
Expand Down
64 changes: 20 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -81,32 +74,15 @@ 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:
${XGO_BIN} -go 1.19 \
-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:
Expand Down
41 changes: 28 additions & 13 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"encoding/json"
"fmt"
"runtime/debug"
"time"

"github.com/pydio/cells/v4/common/log"
Expand All @@ -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
Expand Down Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions control/http-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
7 changes: 5 additions & 2 deletions control/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 895d085

Please sign in to comment.