diff --git a/components/local-app/BUILD.yaml b/components/local-app/BUILD.yaml index 9eee7881858b21..ffe157a3c0b404 100644 --- a/components/local-app/BUILD.yaml +++ b/components/local-app/BUILD.yaml @@ -13,7 +13,33 @@ packages: image: - ${imageRepoBase}/local-app:${version} - ${imageRepoBase}/local-app:commit-${__git_commit} - + - name: update-manifest + type: go + srcs: + - go.mod + - go.sum + - "**/*.go" + - version.txt + deps: + - components/supervisor-api/go:lib + - components/gitpod-protocol/go:lib + - components/local-app-api/go:lib + - components/public-api/go:lib + config: + packaging: app + dontTest: true + buildCommand: ["go", "build", "-o", "update-manifest", "./main/update-manifest/main.go"] + - name: app-with-manifest + type: generic + deps: + - :app + - :update-manifest + config: + commands: + - ["sh", "-c", "mkdir -p bin && mv components-local-app--app/bin/* bin/"] + - ["pwd"] + - ["sh", "-c", "components-local-app--update-manifest/update-manifest --cwd bin | tee bin/manifest.json"] + # - ["rm", "-rf", "components-local-app--update-manifest", "components-local-app--app"] scripts: - name: install-cli description: "Install gitpod-cli as `gitpod` command and add auto-completion. Usage: '. $(leeway run components/local-app:install-cli)'" diff --git a/components/local-app/main/update-manifest/main.go b/components/local-app/main/update-manifest/main.go new file mode 100644 index 00000000000000..4746315bc63f39 --- /dev/null +++ b/components/local-app/main/update-manifest/main.go @@ -0,0 +1,39 @@ +// Copyright (c) 2023 Gitpod GmbH. All rights reserved. +// Licensed under the GNU Affero General Public License (AGPL). +// See License.AGPL.txt in the project root for license information. + +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/Masterminds/semver/v3" + "github.com/gitpod-io/local-app/pkg/constants" + "github.com/gitpod-io/local-app/pkg/selfupdate" + "github.com/sagikazarmark/slog-shim" + "github.com/spf13/pflag" +) + +var ( + version = pflag.String("version", constants.Version.String(), "version to use") + cwd = pflag.String("cwd", ".", "working directory") +) + +func main() { + pflag.Parse() + + ver := semver.MustParse(*version) + mf, err := selfupdate.GenerateManifest(ver, *cwd, selfupdate.DefaultFilenameParser) + if err != nil { + slog.Error("cannot generate manifest", "err", err) + os.Exit(1) + } + fc, err := json.MarshalIndent(mf, "", " ") + if err != nil { + slog.Error("cannot marshal manifest", "err", err) + os.Exit(1) + } + fmt.Println(string(fc)) +} diff --git a/components/local-app/pkg/config/config.go b/components/local-app/pkg/config/config.go index 1da790a96348f4..fdc9456126ce25 100644 --- a/components/local-app/pkg/config/config.go +++ b/components/local-app/pkg/config/config.go @@ -22,8 +22,8 @@ type Config struct { ActiveContext string `yaml:"activeContext,omitempty"` Contexts map[string]*ConnectionContext - Telemetry *Telemetry `yaml:"telemetry"` - Autoupdate bool `yaml:"autoupdate"` + Telemetry Telemetry `yaml:"telemetry"` + Autoupdate bool `yaml:"autoupdate"` } type Telemetry struct { @@ -83,7 +83,7 @@ func LoadConfig(fn string) (res *Config, err error) { cfg := &Config{ Filename: fn, Contexts: make(map[string]*ConnectionContext), - Telemetry: &Telemetry{ + Telemetry: Telemetry{ Enabled: !telemetry.DoNotTrack(), Identity: telemetry.GenerateIdentity(), }, diff --git a/components/local-app/pkg/selfupdate/selfupdate.go b/components/local-app/pkg/selfupdate/selfupdate.go index 57dae9965734c0..93a88d9e90b9e8 100644 --- a/components/local-app/pkg/selfupdate/selfupdate.go +++ b/components/local-app/pkg/selfupdate/selfupdate.go @@ -46,7 +46,7 @@ type Binary struct { type FilenameParserFunc func(filename string) (os, arch string, ok bool) -var regexDefaultFilenamePattern = regexp.MustCompile(`^.*-(linux|darwin|windows)-(amd64|arm64)(\.exe)?$`) +var regexDefaultFilenamePattern = regexp.MustCompile(`.*-(linux|darwin|windows)-(amd64|arm64)(\.exe)?`) func DefaultFilenameParser(filename string) (os, arch string, ok bool) { matches := regexDefaultFilenamePattern.FindStringSubmatch(filename)