Skip to content

Commit

Permalink
Release v1.0.0-beta.2
Browse files Browse the repository at this point in the history
  • Loading branch information
operate-services-sdk-bot authored and XiangGuoUnity committed Feb 9, 2023
1 parent 37921e4 commit afc7d57
Show file tree
Hide file tree
Showing 94 changed files with 1,958 additions and 467 deletions.
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@ All notable changes to UGS CLI will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.0-beta.1]
## [1.0.0-beta.2] - 2023-02-03

### Added

- Remote Config new-file command to create a default remote config file.
- Deploy Module with `fetch` command to fetch files from all services that implement `IFetchService`
- Currently supports RemoteConfig only
- Command metrics tracking

### Changed
- Subcommands are now sorted in alphabetical order

### Fixed

- Cancelling ``ugs deploy <your-path-to-deploy>`` doesn't logs stacktraces anymore.
- `-e/--environment-name` and `-p/--project-id` options enabled for `deploy` command.
- `ugs deploy` with duplicate path will remove duplicate and deploy.
- `ugs deploy` with directory missing permission will log correct error.

## [1.0.0-beta.1] - 2023-01-16

### Added
- CLI Core Module: Configuration, Service Account Authentication Commands.
Expand Down
4 changes: 2 additions & 2 deletions License.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Unity Gaming Services Command-line Interface (UGS CLI) copyright © 2022 Unity Technologies.

This software is subject to, and made available under, the terms of service for Unity Gaming Services Command-line Interface (UGS CLI) (see https://unity3d.com/legal/one-operate-services-terms-of-service), and is an "Operate Service" as defined therein.
This software is subject to, and made available under, the terms of service for Unity Gaming Services Command-line Interface (UGS CLI)(see https://unity.com/legal). Your use of this software constitutes your acceptance of such terms.

Your use of the Services constitutes your acceptance of such terms. Unless expressly provided otherwise, the software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the terms of service for details on these and other terms and conditions.
Unless expressly provided otherwise, the software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the terms of service for details on these and other terms and conditions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Requires [Windows] 10 or later.

### Linux

Requires [Ubuntu], [Alpine] and most other major distros.
Requires [Ubuntu], [Alpine] or most other major distros.

### macOS

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using Spectre.Console;
using Unity.Services.Cli.CloudCode.Deploy;
using Unity.Services.Cli.CloudCode.Exceptions;
using Unity.Services.Cli.CloudCode.Input;
using Unity.Services.Cli.CloudCode.Service;
using Unity.Services.Cli.CloudCode.UnitTest.Utils;
using Unity.Services.Cli.Common.Console;
using Unity.Services.Cli.Deploy.Model;
using Unity.Services.Cli.Common.Utils;
using Unity.Services.Cli.Deploy.Service;
using Unity.Services.CloudCode.Authoring.Editor.Core.Deployment;
using Unity.Services.CloudCode.Authoring.Editor.Core.Model;
Expand All @@ -35,14 +31,12 @@ public class CloudCodeDeploymentServiceTests
"test_b.js"
};

readonly Mock<IUnityEnvironment> m_MockUnityEnvironment = new();
readonly Mock<ICliCloudCodeClient> m_MockCloudCodeClient = new();
readonly Mock<ICliEnvironmentProvider> m_MockEnvironmentProvider = new();
readonly Mock<ICloudCodeInputParser> m_MockCloudCodeInputParser = new();
readonly Mock<ICloudCodeService> m_MockCloudCodeService = new();
readonly Mock<ICloudCodeDeploymentHandler> m_MockCloudCodeDeploymentHandler = new();
readonly Mock<ICloudCodeServicesWrapper> m_MockServicesWrapper = new();
readonly Mock<IDeployFileService> m_MockDeployFileService = new();
readonly Mock<ICliDeploymentOutputHandler> m_MockCliDeploymentOutputHandler = new();
readonly Mock<ICloudCodeScriptsLoader> m_MockCloudCodeScriptsLoader = new();
readonly Mock<ILogger> m_MockLogger = new();
Expand All @@ -65,14 +59,12 @@ public class CloudCodeDeploymentServiceTests
[SetUp]
public void SetUp()
{
m_MockUnityEnvironment.Reset();
m_MockCloudCodeClient.Reset();
m_MockEnvironmentProvider.Reset();
m_MockCloudCodeInputParser.Reset();
m_MockCloudCodeService.Reset();
m_MockCloudCodeDeploymentHandler.Reset();
m_MockServicesWrapper.Reset();
m_MockDeployFileService.Reset();
m_MockLogger.Reset();
m_MockCliDeploymentOutputHandler.Reset();
m_MockCloudCodeScriptsLoader.Reset();
Expand Down Expand Up @@ -110,7 +102,7 @@ public void SetUp()
.Returns(m_MockCloudCodeScriptsLoader.Object);


m_DeploymentService = new CloudCodeDeploymentService(m_MockUnityEnvironment.Object, m_MockServicesWrapper.Object);
m_DeploymentService = new CloudCodeDeploymentService(m_MockServicesWrapper.Object);

m_MockCloudCodeScriptsLoader.Setup(
c => c.LoadScriptsAsync(
Expand All @@ -130,25 +122,23 @@ public async Task DeployAsync_CallsLoadFilePathsFromInputCorrectly()
{
CloudProjectId = TestValues.ValidProjectId,
};
m_MockUnityEnvironment.Setup(x => x.FetchIdentifierAsync())
.ReturnsAsync(TestValues.ValidEnvironmentId);
m_MockDeployFileService.Setup(d => d.ListFilesToDeploy(input.Paths, "*.js"))
.Returns(k_ValidFilePaths);

var result = await m_DeploymentService!.Deploy(
input,
(StatusContext)null!,
k_ValidFilePaths,
TestValues.ValidProjectId,
TestValues.ValidEnvironmentId,
null!,
CancellationToken.None);

m_MockUnityEnvironment.Verify(x => x.FetchIdentifierAsync(), Times.Once);
m_MockCloudCodeClient.Verify(
x => x.Initialize(
TestValues.ValidEnvironmentId,
TestValues.ValidProjectId,
CancellationToken.None),
Times.Once);
m_MockEnvironmentProvider.VerifySet(x => { x.Current = TestValues.ValidEnvironmentId; }, Times.Once);
m_MockCloudCodeDeploymentHandler.Verify(x => x.DeployAsync(It.IsAny<List<IScript>>()), Times.Once);
m_MockCloudCodeDeploymentHandler.Verify(x => x.DeployAsync(It.IsAny<List<IScript>>(), false), Times.Once);
Assert.AreEqual(k_DeployedContents, result.Deployed);
Assert.AreEqual(k_FailedContents, result.Failed);
}
Expand All @@ -163,16 +153,15 @@ public void DeployAsync_DoesNotThrowOnApiException()
};

m_MockCloudCodeDeploymentHandler.Setup(ex => ex
.DeployAsync(It.IsAny<IEnumerable<IScript>>())).ThrowsAsync(new ApiException());
m_MockUnityEnvironment.Setup(x => x.FetchIdentifierAsync())
.ReturnsAsync(TestValues.ValidEnvironmentId);
m_MockDeployFileService.Setup(d => d.ListFilesToDeploy(input.Paths, "*.js"))
.Returns(k_ValidFilePaths);
.DeployAsync(It.IsAny<IEnumerable<IScript>>(), false)).ThrowsAsync(new ApiException());

Assert.DoesNotThrowAsync(
() => m_DeploymentService!.Deploy(
input,
(StatusContext)null!,
k_ValidFilePaths,
TestValues.ValidProjectId,
TestValues.ValidEnvironmentId,
null!,
CancellationToken.None));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Unity.Services.Cli.CloudCode.Service;
using Unity.Services.Cli.Deploy.Input;
using Unity.Services.Cli.Deploy.Model;
using Unity.Services.Cli.Common.Utils;
using Unity.Services.Cli.Deploy.Service;
using Unity.Services.CloudCode.Authoring.Editor.Core.Deployment;
using Unity.Services.Gateway.CloudCodeApiV1.Generated.Client;
Expand All @@ -11,7 +10,6 @@ namespace Unity.Services.Cli.CloudCode.Deploy;

internal class CloudCodeDeploymentService : IDeploymentService
{
readonly IUnityEnvironment m_UnityEnvironment;
readonly ICloudCodeInputParser m_CloudCodeInputParser;
readonly ICloudCodeService m_CloudCodeService;
readonly ICliDeploymentOutputHandler m_CliDeploymentOutputHandler;
Expand All @@ -20,15 +18,11 @@ internal class CloudCodeDeploymentService : IDeploymentService
readonly ICliCloudCodeClient m_CliCloudCodeClient;
readonly ICloudCodeDeploymentHandler m_CloudCodeDeploymentHandler;
string m_ServiceType;
string m_DeployFileExtension;

public CloudCodeDeploymentService(
IUnityEnvironment unityEnvironment,
ICloudCodeServicesWrapper servicesWrapper
)
{
m_UnityEnvironment = unityEnvironment;

m_CloudCodeInputParser = servicesWrapper.CloudCodeInputParser;
m_CloudCodeService = servicesWrapper.CloudCodeService;
m_CliDeploymentOutputHandler = servicesWrapper.CliDeploymentOutputHandler;
Expand All @@ -38,38 +32,42 @@ ICloudCodeServicesWrapper servicesWrapper
m_CloudCodeDeploymentHandler = servicesWrapper.CloudCodeDeploymentHandler;

m_ServiceType = "Cloud Code";
m_DeployFileExtension = ".js";
DeployFileExtension = ".js";
}

string IDeploymentService.ServiceType => m_ServiceType;

string IDeploymentService.DeployFileExtension => m_DeployFileExtension;
public string DeployFileExtension { get; }

public async Task<DeploymentResult> Deploy(
DeployInput input,
IReadOnlyList<string> filePaths,
string projectId,
string environmentId,
StatusContext? loadingContext,
CancellationToken cancellationToken)
{
var environmentId = await m_UnityEnvironment.FetchIdentifierAsync();

m_CliCloudCodeClient.Initialize(environmentId, input.CloudProjectId!, cancellationToken);
m_CliCloudCodeClient.Initialize(environmentId, projectId, cancellationToken);
m_EnvironmentProvider.Current = environmentId;

loadingContext?.Status($"Reading {m_ServiceType} Scripts...");

var scriptList = await m_CloudCodeScriptsLoader.LoadScriptsAsync(
input.Paths,
filePaths,
m_ServiceType,
m_DeployFileExtension,
DeployFileExtension,
m_CloudCodeInputParser,
m_CloudCodeService,
m_CliDeploymentOutputHandler.Contents,
cancellationToken);

loadingContext?.Status($"Deploying {m_ServiceType} Scripts...");

var dryrun = false;


try
{
await m_CloudCodeDeploymentHandler.DeployAsync(scriptList);
await m_CloudCodeDeploymentHandler.DeployAsync(scriptList, dryrun);
}
catch (ApiException)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
using Unity.Services.Cli.CloudCode.Exceptions;
using Unity.Services.Cli.CloudCode.Service;
using Unity.Services.Cli.Deploy.Model;
using Unity.Services.Cli.Deploy.Service;
using Unity.Services.CloudCode.Authoring.Editor.Core.Model;

namespace Unity.Services.Cli.CloudCode.Deploy;

internal class CloudCodeScriptsLoader : ICloudCodeScriptsLoader
{
readonly IDeployFileService m_DeployFileService;

public CloudCodeScriptsLoader(IDeployFileService deployFileService)
{
m_DeployFileService = deployFileService;
}

public async Task<List<IScript>> LoadScriptsAsync(
ICollection<string> paths,
IReadOnlyCollection<string> paths,
string serviceType,
string extension,
ICloudCodeInputParser cloudCodeInputParser,
Expand All @@ -25,8 +17,7 @@ public async Task<List<IScript>> LoadScriptsAsync(
CancellationToken cancellationToken)
{
var scriptList = new List<IScript>();
var filePaths = m_DeployFileService.ListFilesToDeploy(paths, extension);
foreach (var path in filePaths)
foreach (var path in paths)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Unity.Services.Cli.CloudCode.Deploy;
interface ICloudCodeScriptsLoader
{
Task<List<IScript>> LoadScriptsAsync(
ICollection<string> paths,
IReadOnlyCollection<string> paths,
string serviceType,
string extension,
ICloudCodeInputParser cloudCodeInputParser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Jint" Version="3.0.0-beta-2042" />
<PackageReference Include="Unity.Services.CloudCode.Authoring.Editor.Core" Version="0.2.0" />
<PackageReference Include="Unity.Services.CloudCode.Authoring.Editor.Core" Version="0.2.3" />
<PackageReference Include="Unity.Services.Gateway.CloudCodeApiV1.Generated" Version="1.0.1" />
<PackageReference Include="YamlDotNet" Version="12.1.0" />
<PackageReference Include="YamlDotNet" Version="12.3.1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="JavaScripts\script_parameters.js" />
</ItemGroup>
<PropertyGroup>
<DefineConstants Condition=" '$(ExtraDefineConstants)' != '' ">$(DefineConstants);$(ExtraDefineConstants)</DefineConstants>
<DefineConstants></DefineConstants>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using NUnit.Framework;
using Spectre.Console;
using Unity.Services.Cli.Common.Console;
using Unity.Services.Cli.Common.Features;
using Unity.Services.Cli.Common.Logging;
using Unity.Services.Cli.Common.Models;
using Unity.Services.Cli.Common.Networking;
using Unity.Services.Cli.Common.SystemEnvironment;
using Unity.Services.Cli.Common.Telemetry;
using Unity.Services.Cli.Common.Telemetry.AnalyticEvent.AnalyticEventFactory;
using Unity.Services.Gateway.IdentityApiV1.Generated.Api;

namespace Unity.Services.Cli.Common.UnitTest;
Expand All @@ -25,6 +25,7 @@ class CommonModuleTests
List<ServiceDescriptor>? m_Services;
Mock<IServiceCollection>? m_MockedServiceCollection;
readonly Mock<ISystemEnvironmentProvider> m_MockSystemEnvironmentProvider;
readonly Mock<IAnalyticEventFactory> m_MockAnalyticEventFactory = new();
Parser? m_Parser;

public CommonModuleTests()
Expand All @@ -36,11 +37,12 @@ public CommonModuleTests()
public void SetUp()
{
m_MockSystemEnvironmentProvider.Reset();
m_MockAnalyticEventFactory.Reset();
m_CommandLineBuilder = new(new RootCommand("Test root command"));
m_Parser = m_CommandLineBuilder.UseHost(_ => Host.CreateDefaultBuilder(),
host =>
{
CommonModule.ConfigureCommonServices(host, new Logger(), new StaticFeatures(), AnsiConsole.Create(new AnsiConsoleSettings()));
CommonModule.ConfigureCommonServices(host, new Logger(), AnsiConsole.Create(new AnsiConsoleSettings()), m_MockAnalyticEventFactory.Object);

}).UseDefaults().AddGlobalCommonOptions().Build();
m_Parser!.InvokeAsync("");
Expand Down Expand Up @@ -90,6 +92,16 @@ public void CreateAndRegisterCliPromptServiceSucceeds()
Assert.AreEqual(1, m_Services!.Count);
}

[Test]
public void CreateAndRegisterCliAnalyticsSenderService_RegisterAllServices()
{
CommonModule.CreateAndRegisterCliAnalyticsSenderService(m_MockedServiceCollection!.Object);
Assert.NotNull(m_Services!.Find(p => p.ServiceType.Name is "AnalyticService"));
Assert.NotNull(m_Services!.Find(p => p.ServiceType.Name is "BigQueryExporter"));
Assert.NotNull(m_Services!.Find(p => p.ServiceType.Name is "IAnalyticConfiguration"));
Assert.NotNull(m_Services!.Find(p => p.ServiceType.Name is "AnalyticBuilder"));
}

[Test]
public void CreateAndRegisterProgressBarServiceNoQuietAliasSetsConsole()
{
Expand Down Expand Up @@ -133,7 +145,7 @@ public void CreateTelemetrySender_SetsCorrectBasePath()
public void CreateTelemetrySender_SetsBaseProductTags()
{
var telemetrySender = CommonModule.CreateTelemetrySender(m_MockSystemEnvironmentProvider.Object);
StringAssert.AreEqualIgnoringCase(telemetrySender.ProductTags[TagKeys.ProductName],"com.unity.ugs-cli");
StringAssert.AreEqualIgnoringCase(telemetrySender.ProductTags[TagKeys.ProductName], CommonModule.m_CliProductName);
StringAssert.AreEqualIgnoringCase(telemetrySender.ProductTags[TagKeys.CliVersion], TelemetryConfigurationProvider.GetCliVersion());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,6 @@ public void HandleForbidden403Exception()
$"{m_ExceptionHelper!.HttpErrorTroubleshootingLinks[HttpStatusCode.Forbidden]}");
}

[Test]
public void HandlerCancelledOperation()
{
var cancelledException = new TaskCanceledException();

Assert.DoesNotThrow(
() => m_ExceptionHelper!.HandleException(
cancelledException, k_MockHelper.MockLogger.Object, m_Context!));

TestsHelper.VerifyLoggerWasCalled(k_MockHelper.MockLogger, expectedTimes: Times.Never);
Assert.AreEqual(ExitCode.Cancelled, m_Context!.ExitCode);
}

[Test]
public void ExceptionHandler_DoesNotThrowWhenDiagnosticsFailToSend()
{
Expand Down
Loading

0 comments on commit afc7d57

Please sign in to comment.