Skip to content

Commit

Permalink
Use app version set at build time on desktop (#1071)
Browse files Browse the repository at this point in the history
* use same app version on desktop

* use same app version on desktop

* disable testRelay

* Update CI branch
  • Loading branch information
atavism authored May 9, 2024
1 parent a150bd7 commit 83208b5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish releases

on:
push:
branches: [ atavism/pro-client-updates ]
branches: [ main ]
tags:
- '*'

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ STAGING = false
UPDATE_SERVER_URL ?=
VERSION ?= 9999.99.99
# Note - we don't bother stripping symbols or DWARF table as Android's packaging seems to take care of that for us
LDFLAGS := -X github.com/getlantern/lantern-client/internalsdk/common.RevisionDate=$(REVISION_DATE) -X github.com/getlantern/lantern-client/internalsdk/common.ApplicationVersion=$(VERSION)
LDFLAGS := -X github.com/getlantern/lantern-client/internalsdk/common.RevisionDate=$(REVISION_DATE) \
-X github.com/getlantern/lantern-client/internalsdk/common.ApplicationVersion=$(VERSION) \
-X github.com/getlantern/lantern-client/internalsdk/common.BuildDate=$(BUILD_DATE)

# Ref https://pkg.go.dev/cmd/link
# -w omits the DWARF table
Expand Down
13 changes: 6 additions & 7 deletions desktop/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/getlantern/flashlight/v7/bandit"
"github.com/getlantern/flashlight/v7/browsers/simbrowser"
flashlightClient "github.com/getlantern/flashlight/v7/client"
"github.com/getlantern/flashlight/v7/common"
"github.com/getlantern/flashlight/v7/config"
"github.com/getlantern/flashlight/v7/email"
"github.com/getlantern/flashlight/v7/geolookup"
Expand All @@ -38,11 +37,11 @@ import (

"github.com/getlantern/lantern-client/desktop/analytics"
"github.com/getlantern/lantern-client/desktop/autoupdate"
uicommon "github.com/getlantern/lantern-client/desktop/common"
"github.com/getlantern/lantern-client/desktop/features"
"github.com/getlantern/lantern-client/desktop/notifier"
"github.com/getlantern/lantern-client/desktop/settings"
"github.com/getlantern/lantern-client/desktop/ws"
"github.com/getlantern/lantern-client/internalsdk/common"
proclient "github.com/getlantern/lantern-client/internalsdk/pro"
)

Expand All @@ -53,7 +52,7 @@ var (
)

func init() {
autoupdate.Version = ApplicationVersion
autoupdate.Version = common.ApplicationVersion
autoupdate.PublicKey = []byte(packagePublicKey)
}

Expand Down Expand Up @@ -128,7 +127,7 @@ func NewApp(flags flashlight.Flags, configDir string, proClient proclient.ProCli

func newAnalyticsSession(settings *settings.Settings) analytics.Session {
if settings.IsAutoReport() {
session := analytics.Start(settings.GetDeviceID(), ApplicationVersion)
session := analytics.Start(settings.GetDeviceID(), common.ApplicationVersion)
go func() {
session.SetIP(geolookup.GetIP(eventual.Forever))
}()
Expand Down Expand Up @@ -204,8 +203,8 @@ func (app *App) Run(isMain bool) {

app.flashlight, err = flashlight.New(
common.DefaultAppName,
ApplicationVersion,
RevisionDate,
common.ApplicationVersion,
common.RevisionDate,
app.configDir,
app.Flags.VPN,
func() bool { return app.settings.GetDisconnected() }, // check whether we're disconnected
Expand Down Expand Up @@ -596,7 +595,7 @@ func recordStopped() {

// ShouldReportToSentry determines if we should report errors/panics to Sentry
func ShouldReportToSentry() bool {
return !uicommon.IsDevEnvironment()
return !common.IsDevEnvironment()
}

// GetTranslations accesses translations with the given filename
Expand Down
6 changes: 3 additions & 3 deletions desktop/app/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strconv"

"github.com/getlantern/lantern-client/desktop/settings"
"github.com/getlantern/lantern-client/internalsdk/common"
"github.com/getlantern/lantern-client/internalsdk/pro"

"github.com/getlantern/flashlight/v7/common"
"github.com/getlantern/flashlight/v7/issue"
"github.com/getlantern/flashlight/v7/util"
"github.com/getlantern/osversion"
Expand Down Expand Up @@ -54,7 +54,7 @@ func newIssueReporter(app *App) *issueReporter {
// lantern-cloud/issue service, which is then forwarded to the ticket system via API
func (reporter *issueReporter) sendIssueReport(msg *issueMessage) error {
settings := reporter.settings
uc := common.NewUserConfigData(
uc := common.NewUserConfig(
common.DefaultAppName,
settings.GetDeviceID(),
settings.GetUserID(),
Expand Down Expand Up @@ -114,7 +114,7 @@ func (reporter *issueReporter) sendIssueReport(msg *issueMessage) error {
msg.Note,
subscriptionLevel,
msg.Email,
ApplicationVersion,
common.ApplicationVersion,
"",
"",
osVersion,
Expand Down
12 changes: 0 additions & 12 deletions desktop/app/version.go

This file was deleted.

10 changes: 5 additions & 5 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ func reportIssue(email, issueType, description *C.char) (*C.char, *C.char) {
C.GoString(description),
subscriptionLevel,
C.GoString(email),
app.ApplicationVersion,
common.ApplicationVersion,
deviceID,
osVersion,
"",
Expand All @@ -620,7 +620,7 @@ func checkUpdates() *C.char {
op := ops.Begin("check_update").
Set("user_id", userID).
Set("device_id", deviceID).
Set("current_version", app.ApplicationVersion)
Set("current_version", common.ApplicationVersion)
defer op.End()
updateURL, err := autoupdate.CheckUpdates()
if err != nil {
Expand All @@ -634,11 +634,11 @@ func checkUpdates() *C.char {
// loadSettings loads the initial settings at startup, either from disk or using defaults.
func loadSettings(configDir string) *settings.Settings {
path := filepath.Join(configDir, "settings.yaml")
if common.Staging {
if common.IsStagingEnvironment() {
path = filepath.Join(configDir, "settings-staging.yaml")
}
settings := settings.LoadSettingsFrom(app.ApplicationVersion, app.RevisionDate, app.BuildDate, path)
if common.Staging {
settings := settings.LoadSettingsFrom(common.ApplicationVersion, common.RevisionDate, common.BuildDate, path)
if common.IsStagingEnvironment() {
settings.SetUserIDAndToken(9007199254740992, "OyzvkVvXk7OgOQcx-aZpK5uXx6gQl5i8BnOuUkc0fKpEZW6tc8uUvA")
}
return settings
Expand Down
2 changes: 1 addition & 1 deletion internalsdk/android_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestProxying(t *testing.T) {
require.NoError(t, err, "Proxying request via HTTP should have worked")
err = testProxiedRequest(helper, result.SOCKS5Addr, result.DNSGrabAddr, true)
assert.NoError(t, err, "Proxying request via SOCKS should have worked")
testRelay(t)
// testRelay(t)
}
}

Expand Down
64 changes: 7 additions & 57 deletions desktop/common/common.go → internalsdk/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"strings"

fcommon "github.com/getlantern/flashlight/v7/common"
"github.com/getlantern/golog"
)

// Environment represents the different
// environment modes Lantern may be running in
// Environment represents different environments Lantern may be running in
type Environment int

const (
Expand All @@ -19,14 +17,6 @@ const (
Staging
)

// ServerType is a type that represents different Lantern
// back-end services
type ServerType int

const (
AuthServer ServerType = iota
)

var (
// EnvMapping is a mapping for the Environment enum
EnvMapping = map[string]Environment{
Expand All @@ -35,23 +25,19 @@ var (
Staging.String(): Staging,
}

// AuthServerAddr is the auth server address to use
AuthServerAddr = "https://auth4.lantern.network"

// DisablePort is a boolean flag that corresponds with the DISABLE_PORT_RANDOMIZATION env var
DisablePort bool

// Environment is the environment flashlight is currently running in
env Environment

// ZipkinEndpoint specifies the URL to which zipkin spans should be sent
ZipkinEndpoint = "https://zipkin-pro-server-neu.128.network/api/v2/spans"
// ZipkinAPIKey specifies the API key to use when sending spans to Zipkin, should match https://github.com/getlantern/pro-server-neu-infrastructure-zipkin/blob/main/.codedeploy/default#L30
ZipkinAPIKey = "38249ee3-ca14-45b7-9c58-3e668c3e6791"

log = golog.LoggerFor("lantern-desktop.common")
)

func init() {
DisablePort, _ = strconv.ParseBool(os.Getenv("DISABLE_PORT_RANDOMIZATION"))
envVar := strings.ToLower(os.Getenv("ENVIRONMENT"))
env = EnvMapping[envVar]
}

func (e Environment) String() string {
switch e {
case Development:
Expand All @@ -73,42 +59,6 @@ func (e Environment) IsStaging() bool {
return e == Staging
}

func (s ServerType) String() string {
switch s {
case AuthServer:
return "auth"
default:
return ""
}
}

func init() {
DisablePort, _ = strconv.ParseBool(os.Getenv("DISABLE_PORT_RANDOMIZATION"))
envVar := strings.ToLower(os.Getenv("ENVIRONMENT"))
env = EnvMapping[envVar]

if env.IsStaging() {
AuthServerAddr = "https://auth-staging.lantern.network"
}
}

// GetAPIAddr returns the API address to use for the given
// server type. If an address is specified with a command line flag
// that value overides the default
func GetAPIAddr(serverType ServerType, flagAddr string) string {
var defaultAddr string
switch serverType {
case AuthServer:
defaultAddr = AuthServerAddr
}
addr := flagAddr
if addr == "" {
addr = defaultAddr
}
log.Debugf("Using %s server at %s", serverType.String(), addr)
return addr
}

// IsDevEnvironment checks if flashlight is currently being run in development mode
func IsDevEnvironment() bool {
return DisablePort && env.IsDevelopment()
Expand Down
24 changes: 4 additions & 20 deletions internalsdk/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,11 @@ var (
// GlobalStagingURL is the URL for fetching the global config in a staging environment.
GlobalStagingURL = "https://globalconfig.flashlightproxy.com/global.yaml.gz"

// StagingMode if true, run Lantern against our staging infrastructure.
// This is set by the linker using -ldflags
StagingMode = "false"

Staging = false

ProAPIHost = "api.getiantem.org"

log = golog.LoggerFor("flashlight.common")

forceAds bool

// Set by the linker using -ldflags in the project's Makefile.
// Defaults to 'production' so as not to mistakingly push development work
// to a production environment
Environment = "production"
)

func init() {
Expand All @@ -64,19 +53,14 @@ func init() {

// ForceStaging forces staging mode.
func ForceStaging() {
StagingMode = "true"
env = Staging
initInternal()
}

func initInternal() {
var err error
log.Debugf("****************************** stagingMode: %v", StagingMode)
Staging, err = strconv.ParseBool(StagingMode)
if err != nil {
log.Errorf("Error parsing boolean flag: %v", err)
return
}
if Staging {
isStaging := IsStagingEnvironment()
log.Debugf("****************************** stagingMode: %v", isStaging)
if isStaging {
ProAPIHost = "api-staging.getiantem.org"
}
forceAds, _ = strconv.ParseBool(os.Getenv("FORCEADS"))
Expand Down
3 changes: 3 additions & 0 deletions internalsdk/common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ var (

// This gets set at build time
RevisionDate = ""

// This gets set at build time
BuildDate = ""
)

func init() {
Expand Down

0 comments on commit 83208b5

Please sign in to comment.