Skip to content

Commit

Permalink
Generate update manifest during build
Browse files Browse the repository at this point in the history
  • Loading branch information
csweichel committed Nov 10, 2023
1 parent 8753a77 commit bae526e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
28 changes: 27 additions & 1 deletion components/local-app/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'"
Expand Down
39 changes: 39 additions & 0 deletions components/local-app/main/update-manifest/main.go
Original file line number Diff line number Diff line change
@@ -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))
}
6 changes: 3 additions & 3 deletions components/local-app/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
},
Expand Down
2 changes: 1 addition & 1 deletion components/local-app/pkg/selfupdate/selfupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bae526e

Please sign in to comment.