Skip to content

Commit 0866b9d

Browse files
committed
Add version command
1 parent f48c854 commit 0866b9d

File tree

6 files changed

+89
-11
lines changed

6 files changed

+89
-11
lines changed

components/local-app/BUILD.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const generatePackage = function (goos, goarch, binaryName, mainFile) {
77
let pkg = {
88
name,
99
type: "go",
10-
srcs: ["go.mod", "go.sum", "**/*.go"],
10+
srcs: ["go.mod", "go.sum", "**/*.go", "version.txt"],
1111
deps: [
1212
"components/supervisor-api/go:lib",
1313
"components/gitpod-protocol/go:lib",
@@ -19,14 +19,12 @@ const generatePackage = function (goos, goarch, binaryName, mainFile) {
1919
packaging: "app",
2020
dontTest: dontTest,
2121
buildCommand: [
22-
"go",
23-
"build",
24-
"-trimpath",
25-
"-ldflags",
26-
"-buildid= -w -s -X 'github.com/gitpod-io/local-app/pkg/constants.Version=commit-${__git_commit}'",
27-
"-o",
28-
binaryName,
29-
mainFile,
22+
"sh",
23+
"-c",
24+
'go build -trimpath -ldflags "-X github.com/gitpod-io/local-app/pkg/constants.GitCommit=${__git_commit} -X github.com/gitpod-io/local-app/pkg/constants.BuildTime=$(date +%s)" -o ' +
25+
binaryName +
26+
" " +
27+
mainFile,
3028
],
3129
},
3230
binaryName,

components/local-app/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ leeway run components/local-app:install-cli
4141
leeway run components/local-app:cli-completion
4242
```
4343

44+
### Versioning and Release Management
45+
46+
The CLI is versioned independently of other Gitpod artifacts due to its auto-updating behaviour.
47+
To create a new version that existing clients will consume increment the number in `version.txt`. Make sure to use semantic versioning. The minor version can be greater than 10, e.g. `0.342` is a valid version.
48+
4449
## local-app
4550

4651
**Beware**: this is very much work in progress and will likely break things.

components/local-app/cmd/version.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"time"
9+
10+
"github.com/gitpod-io/local-app/pkg/constants"
11+
"github.com/gitpod-io/local-app/pkg/prettyprint"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var versionCmd = &cobra.Command{
16+
Use: "version",
17+
Short: "Prints the CLI version",
18+
RunE: func(cmd *cobra.Command, args []string) error {
19+
type Version struct {
20+
Version string `print:"version"`
21+
GitCommit string `print:"commit"`
22+
BuildTime string `print:"built at"`
23+
}
24+
v := Version{
25+
Version: constants.Version,
26+
GitCommit: constants.GitCommit,
27+
BuildTime: constants.MustParseBuildTime().Format(time.RFC3339),
28+
}
29+
return WriteTabular([]Version{v}, formatOpts{}, prettyprint.WriterFormatNarrow)
30+
},
31+
}
32+
33+
func init() {
34+
rootCmd.AddCommand(versionCmd)
35+
}

components/local-app/pkg/constants/constants.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,36 @@
44

55
package constants
66

7+
import (
8+
_ "embed"
9+
"fmt"
10+
"strconv"
11+
"strings"
12+
"time"
13+
14+
version "github.com/gitpod-io/local-app"
15+
)
16+
717
var (
8-
// Version - set during build
9-
Version = "dev"
18+
// Version is fed from the main CLI version
19+
Version = strings.TrimSpace(version.Version)
20+
21+
// GitCommit - set during build
22+
GitCommit = "unknown"
23+
24+
// BuildTime - set during build
25+
BuildTime = "unknown"
1026
)
27+
28+
// MustParseBuildTime parses the build time or panics
29+
func MustParseBuildTime() time.Time {
30+
if BuildTime == "unknown" {
31+
return time.Time{}
32+
}
33+
34+
sec, err := strconv.ParseInt(BuildTime, 10, 64)
35+
if err != nil {
36+
panic(fmt.Sprintf("cannot parse build time: %v", err))
37+
}
38+
return time.Unix(sec, 0)
39+
}

components/local-app/version.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package version
6+
7+
import _ "embed"
8+
9+
//go:embed "version.txt"
10+
var Version string

components/local-app/version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.1

0 commit comments

Comments
 (0)