Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK Version Constant Metadata #887

Merged
merged 6 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: ^1.17
cache: true
- name: Set up JDK
uses: actions/setup-java@v3
with:
Expand Down
3 changes: 1 addition & 2 deletions dart/lib/src/service_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class ServiceBase {
var metadata = <String, String>{};
metadata['TrinsicOkapiVersion'] = okapi.Metadata.getMetadata().version;
metadata['TrinsicSDKLanguage'] = "dart";
// TODO - embed a constant in this module to specify the version explicitly.
metadata['TrinsicSDKVersion'] = "unknown";
metadata['TrinsicSDKVersion'] = getSdkVersion();

if (request != null) {
if (serviceOptions.authToken == "") {
Expand Down
5 changes: 5 additions & 0 deletions dart/lib/src/trinsic_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ ServiceOptions trinsicConfig({String authToken = ""}) {
serverPort: int.parse(port),
serverUseTls: useTls.toLowerCase() != "false");
}

String getSdkVersion() {
const sdkVersion = "1.0.0";
return sdkVersion;
}
85 changes: 70 additions & 15 deletions devops/build_sdks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import os
import platform
import shutil
from os.path import join, abspath, dirname, isdir, split
import subprocess
from os.path import join, abspath, dirname, isdir, split
from typing import Dict

try:
Expand Down Expand Up @@ -109,6 +109,10 @@ def build_python(args) -> None:
join(python_dir, "setup.cfg"),
{"version = ": f"version = {get_package_versions(args)}"},
)
update_line(
join(python_dir, "trinsic", "__init__.py"),
{'sdk_version = "': f' sdk_version = "{get_package_versions(args)}"'},
)
copy_okapi_libs(abspath(join(python_dir, "..", "libs")))


Expand All @@ -119,6 +123,10 @@ def build_java(args) -> None:
join(java_dir, "build.gradle"),
{"def jarVersion": f'def jarVersion = "{get_package_versions(args)}"'},
)
update_line(
join(java_dir, "src", "main", "java", "trinsic", "TrinsicUtilities.java"),
{"final String sdkVersion = ": f' final String sdkVersion = "{get_package_versions(args)}";'},
)
copy_okapi_libs(abspath(join(java_dir, "..", "libs")))


Expand All @@ -138,10 +146,34 @@ def build_ruby(args) -> None:
def build_golang(args) -> None:
# Update version in setup.cfg
golang_dir = abspath(join(get_language_dir("go"), "services"))
update_line(
join(golang_dir, "services.go"),
{"const sdkVersion = ": f' const sdkVersion = "{get_package_versions(args)}"'},
)
# Copy in the binaries
copy_okapi_libs(golang_dir, "windows-gnu")


def build_dart(args) -> None:
lang_dir = get_language_dir("dart")
update_line(
join(lang_dir, "lib", "src", "trinsic_util.dart"),
{
'const sdkVersion = "1.0.0";': f' const sdkVersion = "{get_package_versions(args)}";'
},
)


def build_typescript(args) -> None:
lang_dir = get_language_dir("web")
update_line(
join(lang_dir, "src", "Version.ts"),
{
' const sdkVersion = "1.0.0";': f' const sdkVersion = "{get_package_versions(args)}";'
},
)


def get_package_versions(args) -> str:
return (args.package_version or get_github_version()).lstrip("v")

Expand Down Expand Up @@ -200,6 +232,19 @@ def write_doc_file(input_path: str, output_file: str):
write_doc_file(get_language_dir("go"), "index")


def build_docs(args):
build_java_docs(args)
build_dotnet_docs(args)
build_go_docs(args)


def build_none(args) -> None:
"""
This is here, so you can specify no language to update - eg just download plugins
"""
pass


def parse_arguments():
parser = argparse.ArgumentParser(description="Process SDK building")
parser.add_argument("--package-version", help="Manual override package version")
Expand All @@ -213,20 +258,30 @@ def main():
# Get command line arguments
args = parse_arguments()
langs_to_build = [lang.lower() for lang in (args.language + ",").split(",")]
build_all = "all" in langs_to_build
# Update version information
if build_all or "python" in langs_to_build:
build_python(args)
if build_all or "java" in langs_to_build:
build_java(args)
if build_all or "ruby" in langs_to_build:
build_ruby(args)
if build_all or "golang" in langs_to_build:
build_golang(args)
if build_all or "docs" in langs_to_build:
build_java_docs(args)
build_dotnet_docs(args)
build_go_docs(args)

# Mapping of (language -> compilation function)
lang_funcs = {
"golang": build_golang,
"ruby": build_ruby,
"python": build_python,
"java": build_java,
"dart": build_dart,
"typescript": build_typescript,
"none": build_none,
}
# If "all" is specified, set the array of languages to build to the list of all languages we _can_ build.
if "all" in langs_to_build:
langs_to_build = list(lang_funcs.keys())

if len(langs_to_build) == 0:
raise Exception("No languages specified")

# Execute specified languages
for lang in langs_to_build:
if lang not in lang_funcs:
raise Exception(f"Language {lang} is not a valid compilation language.")

lang_funcs[lang](args)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion devops/generate_proto_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def update_typescript():

def update_none() -> None:
"""
This is here so you can specify no language to update - eg just download plugins
This is here, so you can specify no language to update - eg just download plugins
"""
pass

Expand Down
3 changes: 1 addition & 2 deletions go/services/service_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ func (s *serviceBase) BuildMetadata(message proto.Message) (metadata.MD, error)
return nil, err
}
md.Set("TrinsicOkapiVersion", okapiVersion.Version)
// TODO - Figure out the golang package version from a constant
md.Set("TrinsicSDKVersion", "unknown")
md.Set("TrinsicSDKVersion", GetSdkVersion())
md.Set("TrinsicSDKLanguage", "golang")

if message != nil {
Expand Down
6 changes: 6 additions & 0 deletions go/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"google.golang.org/grpc"
)

// GetSdkVersion used to send metadata
func GetSdkVersion() string {
const sdkVersion = "1.0.0"
return sdkVersion
}

//Options for configuring the sdk
type Options struct {
ServiceOptions *options.ServiceOptions
Expand Down
5 changes: 5 additions & 0 deletions java/src/main/java/trinsic/TrinsicUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public static ManagedChannel getChannel(Options.ServiceOptions config) {
else channelBuilder = channelBuilder.useTransportSecurity();
return channelBuilder.build();
}

public static String getSdkVersion() {
final String sdkVersion = "1.0.0";
return sdkVersion;
}
}
6 changes: 2 additions & 4 deletions java/src/main/java/trinsic/services/ServiceBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package trinsic.services;

import static trinsic.TrinsicUtilities.getSdkVersion;
import static trinsic.TrinsicUtilities.getTrinsicServiceOptions;

import com.google.protobuf.InvalidProtocolBufferException;
Expand Down Expand Up @@ -40,10 +41,7 @@ public Metadata buildMetadata(Message request)
throws InvalidProtocolBufferException, DidException {
var metadata = new Metadata();
putMetadata(metadata, "TrinsicSDKLanguage", "java");
putMetadata(
metadata,
"TrinsicSDKVersion",
"unknown"); // TODO - Get the Java jar information from ?gradle?
putMetadata(metadata, "TrinsicSDKVersion", getSdkVersion());
putMetadata(metadata, "TrinsicOkapiVersion", OkapiMetadata.getMetadata().getVersion());
if (request != null) {
if (this.options == null || this.options.getAuthToken().isEmpty())
Expand Down
1 change: 0 additions & 1 deletion java/src/test/java/trinsic/WalletsDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public static void run()
var walletItems = trinsic.wallet().searchWallet().get();
// }

Assertions.assertNotNull(walletItems);
Assertions.assertEquals(1, walletItems.getItemsCount());
}

Expand Down
3 changes: 2 additions & 1 deletion web/src/ServiceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
oberonProofRequest,
okapiVersion,
} from "./OkapiProvider";
import {getSdkVersion} from "./Version";

export default abstract class ServiceBase {
options: ServiceOptions;
Expand Down Expand Up @@ -48,7 +49,7 @@ export default abstract class ServiceBase {
"trinsicsdklanguage".toLowerCase(),
ServiceBase.getLanguageMetadata()
);
metadata.append("trinsicsdkversion".toLowerCase(), "unknown"); // TODO - Get this from npm?
metadata.append("trinsicsdkversion".toLowerCase(), getSdkVersion());
if (request != undefined || request != null) {
if (!this.options.authToken) {
throw new Error("auth token must be set");
Expand Down
4 changes: 4 additions & 0 deletions web/src/Version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function getSdkVersion(): string {
const sdkVersion = "1.0.0";
return sdkVersion;
}
5 changes: 3 additions & 2 deletions web/test/TrustRegistry.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {
AddFrameworkRequest,
GetMembershipStatusRequest,
RegisterMemberRequest,
RegistrationStatus,
SignInRequest,
GetMembershipStatusRequest,
TrinsicService,
} from "../src";
import { v4 as uuid } from "uuid";
import { getTestServerOptions } from "./env";
import { getTestServerOptions, setTestTimeout } from "./env";

const options = getTestServerOptions();
let trinsic: TrinsicService;

describe("TrustRegistryService Unit Tests", () => {
setTestTimeout();
beforeAll(async () => {
trinsic = new TrinsicService(options);
options.authToken = await trinsic
Expand Down
2 changes: 1 addition & 1 deletion web/test/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function getTestServerOptions(): ServiceOptions {
return defaults;
}

export function setTestTimeout(timeoutMs: number = 20000) {
export function setTestTimeout(timeoutMs: number = 40000) {
if (typeof jasmine !== "undefined")
jasmine.DEFAULT_TIMEOUT_INTERVAL = timeoutMs;
if (typeof jest !== "undefined") jest.setTimeout(timeoutMs);
Expand Down