From 83208b5288a646ccacaa034fa05f76221460ba27 Mon Sep 17 00:00:00 2001 From: atavism Date: Thu, 9 May 2024 07:14:23 -0700 Subject: [PATCH] Use app version set at build time on desktop (#1071) * use same app version on desktop * use same app version on desktop * disable testRelay * Update CI branch --- .github/workflows/release.yml | 2 +- Makefile | 4 +- desktop/app/app.go | 13 +++-- desktop/app/issue.go | 6 +-- desktop/app/version.go | 12 ----- desktop/lib.go | 10 ++-- internalsdk/android_test.go | 2 +- {desktop => internalsdk}/common/common.go | 64 +++-------------------- internalsdk/common/const.go | 24 ++------- internalsdk/common/version.go | 3 ++ 10 files changed, 33 insertions(+), 107 deletions(-) delete mode 100644 desktop/app/version.go rename {desktop => internalsdk}/common/common.go (51%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 51b49a243..0cfd3cd33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Publish releases on: push: - branches: [ atavism/pro-client-updates ] + branches: [ main ] tags: - '*' diff --git a/Makefile b/Makefile index 823735cb7..16b9a4718 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/desktop/app/app.go b/desktop/app/app.go index 9e45bddbf..72647f8e0 100644 --- a/desktop/app/app.go +++ b/desktop/app/app.go @@ -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" @@ -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" ) @@ -53,7 +52,7 @@ var ( ) func init() { - autoupdate.Version = ApplicationVersion + autoupdate.Version = common.ApplicationVersion autoupdate.PublicKey = []byte(packagePublicKey) } @@ -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)) }() @@ -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 @@ -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 diff --git a/desktop/app/issue.go b/desktop/app/issue.go index 141bc86be..8b89cbba9 100644 --- a/desktop/app/issue.go +++ b/desktop/app/issue.go @@ -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" @@ -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(), @@ -114,7 +114,7 @@ func (reporter *issueReporter) sendIssueReport(msg *issueMessage) error { msg.Note, subscriptionLevel, msg.Email, - ApplicationVersion, + common.ApplicationVersion, "", "", osVersion, diff --git a/desktop/app/version.go b/desktop/app/version.go deleted file mode 100644 index 090423fed..000000000 --- a/desktop/app/version.go +++ /dev/null @@ -1,12 +0,0 @@ -package app - -var ( - // This gets set at build time - ApplicationVersion = "9999.99.99" - - // This gets set at build time - RevisionDate = "" - - // This gets set at build time - BuildDate = "" -) diff --git a/desktop/lib.go b/desktop/lib.go index 6431ee066..7d2019813 100644 --- a/desktop/lib.go +++ b/desktop/lib.go @@ -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, "", @@ -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 { @@ -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 diff --git a/internalsdk/android_test.go b/internalsdk/android_test.go index 1e27da7c2..ad195f240 100644 --- a/internalsdk/android_test.go +++ b/internalsdk/android_test.go @@ -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) } } diff --git a/desktop/common/common.go b/internalsdk/common/common.go similarity index 51% rename from desktop/common/common.go rename to internalsdk/common/common.go index 551a0defc..18688e119 100644 --- a/desktop/common/common.go +++ b/internalsdk/common/common.go @@ -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 ( @@ -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{ @@ -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: @@ -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() diff --git a/internalsdk/common/const.go b/internalsdk/common/const.go index e386aa34e..65798315b 100644 --- a/internalsdk/common/const.go +++ b/internalsdk/common/const.go @@ -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() { @@ -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")) diff --git a/internalsdk/common/version.go b/internalsdk/common/version.go index 79626e803..89e4fb48c 100644 --- a/internalsdk/common/version.go +++ b/internalsdk/common/version.go @@ -16,6 +16,9 @@ var ( // This gets set at build time RevisionDate = "" + + // This gets set at build time + BuildDate = "" ) func init() {