Include build information and add version command (#194)
Includes relevant fields listed on
https://goreleaser.com/customization/templates/ into build artifacts.
The version command outputs the version by default:
```
$ bricks version
0.0.21-devel
```
Or all build information if `--json` is specified:
```
$ bricks version --json
{
"ProjectName": "bricks",
"Version": "0.0.21-devel",
"Branch": "version-info",
"Tag": "v0.0.20",
"ShortCommit": "193b56b",
"FullCommit": "193b56b0929128c0836d35e913c46fd66fa2a93c",
"CommitTime": "2023-02-02T22:04:42+01:00",
"Summary": "v0.0.20-5-g193b56b",
"Major": 0,
"Minor": 0,
"Patch": 20,
"Prerelease": "",
"IsSnapshot": true,
"BuildTime": "2023-02-02T22:07:36+01:00"
}
```
2023-02-03 14:38:53 +00:00
|
|
|
package build
|
|
|
|
|
|
|
|
import (
|
2024-10-07 14:06:20 +00:00
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
Include build information and add version command (#194)
Includes relevant fields listed on
https://goreleaser.com/customization/templates/ into build artifacts.
The version command outputs the version by default:
```
$ bricks version
0.0.21-devel
```
Or all build information if `--json` is specified:
```
$ bricks version --json
{
"ProjectName": "bricks",
"Version": "0.0.21-devel",
"Branch": "version-info",
"Tag": "v0.0.20",
"ShortCommit": "193b56b",
"FullCommit": "193b56b0929128c0836d35e913c46fd66fa2a93c",
"CommitTime": "2023-02-02T22:04:42+01:00",
"Summary": "v0.0.20-5-g193b56b",
"Major": 0,
"Minor": 0,
"Patch": 20,
"Prerelease": "",
"IsSnapshot": true,
"BuildTime": "2023-02-02T22:07:36+01:00"
}
```
2023-02-03 14:38:53 +00:00
|
|
|
"testing"
|
2024-10-07 14:06:20 +00:00
|
|
|
|
|
|
|
"github.com/databricks/cli/libs/git"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/mod/modfile"
|
Include build information and add version command (#194)
Includes relevant fields listed on
https://goreleaser.com/customization/templates/ into build artifacts.
The version command outputs the version by default:
```
$ bricks version
0.0.21-devel
```
Or all build information if `--json` is specified:
```
$ bricks version --json
{
"ProjectName": "bricks",
"Version": "0.0.21-devel",
"Branch": "version-info",
"Tag": "v0.0.20",
"ShortCommit": "193b56b",
"FullCommit": "193b56b0929128c0836d35e913c46fd66fa2a93c",
"CommitTime": "2023-02-02T22:04:42+01:00",
"Summary": "v0.0.20-5-g193b56b",
"Major": 0,
"Minor": 0,
"Patch": 20,
"Prerelease": "",
"IsSnapshot": true,
"BuildTime": "2023-02-02T22:07:36+01:00"
}
```
2023-02-03 14:38:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetDetails(t *testing.T) {
|
|
|
|
GetInfo()
|
|
|
|
}
|
2024-10-07 14:06:20 +00:00
|
|
|
|
|
|
|
// This test is stored in the internal package to avoid build errors since this
|
|
|
|
// test itself is run during the CLI generation process.
|
2024-10-07 14:12:51 +00:00
|
|
|
// This test ensures that the OpenAPI SHA the CLI is being generated from matches
|
|
|
|
// the OpenAPI SHA of the Go SDK version used in the CLI. We should always upgrade
|
|
|
|
// the Go SDK version before generating the CLI because downstream generated assets
|
|
|
|
// like the bundle schema depend on the Go SDK itself.
|
2024-10-07 14:06:20 +00:00
|
|
|
func TestConsistentDatabricksSdkVersion(t *testing.T) {
|
|
|
|
// Read the go.mod file
|
|
|
|
b, err := os.ReadFile("../../go.mod")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// Parse the go.mod file to get the databricks-sdk version
|
|
|
|
modFile, err := modfile.Parse("../../go.mod", b, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
modulePath := "github.com/databricks/databricks-sdk-go"
|
|
|
|
var version string
|
|
|
|
for _, r := range modFile.Require {
|
|
|
|
if r.Mod.Path == modulePath {
|
|
|
|
version = r.Mod.Version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require.NotEmpty(t, version)
|
|
|
|
|
|
|
|
// Clone the Databricks Go SDK to get the version of the OpenAPI spec used to
|
|
|
|
// generate the SDK. We cannot use go mod vendor to download the SDK because
|
|
|
|
// that command only downloads the necessary files and thus skips ".codegen".
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
err = git.Clone(context.Background(), "https://github.com/databricks/databricks-sdk-go.git", version, tmpDir)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
cliSha, err := os.ReadFile("../../.codegen/_openapi_sha")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
sdkSha, err := os.ReadFile(filepath.Join(tmpDir, ".codegen/_openapi_sha"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assert.Equal(t, strings.TrimSpace(string(cliSha)), strings.TrimSpace(string(sdkSha)), "please update the SDK version before generating the CLI")
|
|
|
|
}
|