public async Task Get_Release_Check_Failure_With_Default_Build_Engine() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); Assert.Empty(ReadTestData <AppDbContext, Notification>()); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); mockBuildEngine.Reset(); var productBuild = AddEntity <AppDbContext, ProductBuild>(new ProductBuild { ProductId = product3.Id, BuildId = 2, }); var productRelease = AddEntity <AppDbContext, ProductPublication>(new ProductPublication { ProductId = product3.Id, ProductBuildId = productBuild.Id, ReleaseId = 3 }); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "FAILURE", Error = "Error", ConsoleText = "https://dem-aps-artifacts.s3.amazonaws.com/dem/jobs/publish_scriptureappbuilder_2/17/console.log" }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(releaseResponse); await buildReleaseService.CheckReleaseAsync(product3.Id); // Verify that notifications are sent to the user and the org admin var notifications = ReadTestData <AppDbContext, Notification>(); Assert.Equal(2, notifications.Count); var userIds = notifications.Select(n => n.UserId); Assert.Contains(user1.Id, userIds); Assert.Contains(user2.Id, userIds); Assert.Equal($"{{\"projectName\":\"Test Project2\",\"productName\":\"TestProd1\",\"releaseStatus\":\"completed\",\"releaseError\":\"Error\",\"buildEngineUrl\":\"https://buildengine.testorg2/release-admin/view?id=3\",\"consoleTextUrl\":\"https://dem-aps-artifacts.s3.amazonaws.com/dem/jobs/publish_scriptureappbuilder_2/17/console.log\",\"jobId\":{product3.WorkflowJobId},\"buildId\":{product3.WorkflowBuildId},\"publishId\":{product3.WorkflowPublishId},\"projectId\":{product3.Project.Id},\"projectUrl\":\"https://dev.scriptoria.io/projects/2\"}}", notifications[0].MessageSubstitutionsJson); Assert.Equal("releaseFailedAdmin", notifications[0].MessageId); Assert.Equal(releaseResponse.ConsoleText, notifications[0].LinkUrl); var modifiedProductPublishes = ReadTestData <AppDbContext, ProductPublication>(); Assert.Single(modifiedProductPublishes); var publish = modifiedProductPublishes.First(); Assert.True(publish.Success.HasValue); Assert.False(publish.Success.Value); Assert.Equal(releaseResponse.ConsoleText, publish.LogUrl); }
public void RaiseReleaseResponseReceived(ReleaseResponse relRs, Association asc) { if (ReleaseResponseReceived != null) { ReleaseResponseReceived(relRs, asc); } }
public async Task Get_Release_Check_Failure() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockNotificationService = Mock.Get(buildReleaseService.sendNotificationService.HubContext); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); mockBuildEngine.Reset(); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "FAILURE", Error = "Error" }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(releaseResponse); await buildReleaseService.CheckReleaseAsync(product2.Id); // Verify that notifications are sent to the user and the org admin mockNotificationService.Verify(x => x.Clients.User(It.Is <string>(i => i == user1.ExternalId))); mockNotificationService.Verify(x => x.Clients.User(It.Is <string>(i => i == user2.ExternalId))); var notifications = ReadTestData <AppDbContext, Notification>(); Assert.Equal(2, notifications.Count); Assert.Equal("{\"projectName\":\"Test Project1\",\"productName\":\"TestProd1\",\"releaseStatus\":\"completed\",\"releaseError\":\"Error\",\"buildEngineUrl\":\"https://buildengine.testorg1\"}", notifications[0].MessageSubstitutionsJson); Assert.Equal("releaseFailed", notifications[0].MessageId); }
public async Task Release_Check_ReleaseAsync() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); mockBuildEngine.Reset(); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "SUCCESS", Error = "" }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(releaseResponse); await buildReleaseService.CheckReleaseAsync(product2.Id); mockBuildEngine.Verify(x => x.SetEndpoint( It.Is <String>(u => u == org1.BuildEngineUrl), It.Is <String>(t => t == org1.BuildEngineApiAccessToken) )); mockBuildEngine.Verify(x => x.GetRelease(It.Is <int>(i => i == product2.WorkflowJobId), It.Is <int>(b => b == product2.WorkflowBuildId), It.Is <int>(r => r == product2.WorkflowPublishId))); var products = ReadTestData <AppDbContext, Product>(); var modifiedProduct = products.First(p => p.Id == product2.Id); Assert.NotNull(modifiedProduct.DatePublished); }
protected override IEnumerator DownloadPack(string rootLocation, ReleaseResponse release, Action <string> errorAction) { var exeAssets = release.assets.Where(a => a.name.EndsWith(".exe")).ToArray(); if (exeAssets.Length == 0) { errorAction("No needed asset in latest release"); yield break; } var versionDirectory = Path.Combine(rootLocation, $"{release.tag_name}-{release.id}"); Directory.CreateDirectory(versionDirectory); foreach (var exe in exeAssets) { var downloadRequest = HttpHelper.InvokeGetRequest(exe.browser_download_url, $"Downloading {exe.name}", handler => { File.WriteAllBytes(Path.Combine(versionDirectory, exe.name), handler.data); }, errorAction); while (downloadRequest.MoveNext()) { yield return(downloadRequest.Current); } } }
protected async Task CreateBuildEngineReleaseAsync(Product product, string channel) { var release = new Release { Channel = channel }; ClearRecurringJob(product.Id); ReleaseResponse releaseResponse = null; if (SetBuildEngineEndpoint(product.Project.Organization)) { releaseResponse = BuildEngineApi.CreateRelease(product.WorkflowJobId, product.WorkflowBuildId, release); } if ((releaseResponse != null) && (releaseResponse.Id != 0)) { product.WorkflowPublishId = releaseResponse.Id; await ProductRepository.UpdateAsync(product); var monitorJob = Job.FromExpression <BuildEngineReleaseService>(service => service.CheckRelease(product.Id)); RecurringJobManager.AddOrUpdate(GetHangfireToken(product.Id), monitorJob, "* * * * *"); } else { // TODO: Send Notification // Throw Exception to force retry throw new Exception("Create release failed"); } }
protected async Task CreateBuildEngineReleaseAsync(Product product, Dictionary <string, object> paramsDictionary, PerformContext context) { var channel = GetChannel(paramsDictionary); var targets = GetTargets(paramsDictionary, "google-play"); var environment = GetEnvironment(paramsDictionary); environment["PRODUCT_ID"] = product.Id.ToString(); environment["PROJECT_ID"] = product.ProjectId.ToString(); var release = new Release { Channel = channel, Targets = targets, Environment = environment }; ClearRecurringJob(product.Id); ReleaseResponse releaseResponse = null; if (SetBuildEngineEndpoint(product.Project.Organization)) { releaseResponse = BuildEngineApi.CreateRelease(product.WorkflowJobId, product.WorkflowBuildId, release); } if ((releaseResponse != null) && (releaseResponse.Id != 0)) { product.WorkflowPublishId = releaseResponse.Id; await ProductRepository.UpdateAsync(product); var build = await BuildRepository.Get().Where(b => b.BuildId == product.WorkflowBuildId).FirstOrDefaultAsync(); if (build == null) { throw new Exception($"Failed to find ProductBuild: {product.WorkflowBuildId}"); } var publish = new ProductPublication { ProductId = product.Id, ProductBuildId = build.Id, ReleaseId = releaseResponse.Id, Channel = channel }; await PublicationRepository.CreateAsync(publish); var monitorJob = Job.FromExpression <BuildEngineReleaseService>(service => service.CheckRelease(product.Id)); RecurringJobManager.AddOrUpdate(GetHangfireToken(product.Id), monitorJob, "* * * * *"); } else { var messageParms = new Dictionary <string, object>() { { "projectName", product.Project.Name }, { "productName", product.ProductDefinition.Name } }; await SendNotificationOnFinalRetryAsync(context, product.Project.Organization, product.Project.Owner, "releaseFailedUnableToCreate", messageParms); // Throw Exception to force retry throw new Exception("Create release failed"); } }
private async Task UpdateProductPublication(ReleaseResponse buildEngineRelease, Product product, bool success) { var publication = await PublicationRepository.Get().Where(p => p.ReleaseId == buildEngineRelease.Id && p.ProductId == product.Id).FirstOrDefaultAsync(); if (publication == null) { throw new Exception($"Failed to find ProductPublish: ReleaseId={buildEngineRelease.Id}"); } publication.Success = success; publication.LogUrl = buildEngineRelease.ConsoleText; await PublicationRepository.UpdateAsync(publication); if (success) { var publishUrlFile = buildEngineRelease.Artifacts.Where(pa => pa.Key == "publishUrl").FirstOrDefault(); if (publishUrlFile.Value != null) { var value = WebClient.DownloadString(publishUrlFile.Value); if (!string.IsNullOrEmpty(value)) { var publishUrl = value.Trim(); product.PublishLink = publishUrl; await ProductRepository.UpdateAsync(product); } } } }
protected async Task ReleaseCreationFailedAsync(Product product, ReleaseResponse buildEngineRelease) { ClearRecurringJob(product.Id); await UpdateProductPublication(buildEngineRelease, product, false); var buildEngineEndpoint = GetBuildEngineEndpoint(product.Project.Organization); var endpointUrl = buildEngineEndpoint.IsValid() ? buildEngineEndpoint.Url : ""; var buildEngineUrl = endpointUrl + "/release-admin/view?id=" + product.WorkflowPublishId.ToString(); var consoleTextUrl = buildEngineRelease.ConsoleText; var messageParms = new Dictionary <string, object>() { { "projectName", product.Project.Name }, { "productName", product.ProductDefinition.Name }, { "releaseStatus", buildEngineRelease.Status }, { "releaseError", buildEngineRelease.Error }, { "buildEngineUrl", buildEngineUrl }, { "consoleTextUrl", consoleTextUrl }, { "jobId", product.WorkflowJobId }, { "buildId", product.WorkflowBuildId }, { "publishId", product.WorkflowPublishId }, { "projectId", product.ProjectId }, { "projectUrl", product.Project.WorkflowAppProjectUrl } }; await sendNotificationService.SendNotificationToOrgAdminsAndOwnerAsync(product.Project.Organization, product.Project.Owner, "releaseFailedOwner", "releaseFailedAdmin", messageParms, consoleTextUrl); }
public static void SendReleaseResponse(Association asc) { var resp = new ReleaseResponse(); asc.Logger.Log("-->" + resp); byte[] message = resp.Write(); if (asc.Stream.CanWrite) { asc.Stream.Write(message, 0, message.Length); } }
private IEnumerator DownloadPack(ReleaseType releaseType) { EditorUtility.DisplayProgressBar("Downloading", $"Downloading latest {releaseType}", 0); try { ReleaseResponse parsed = null; string errorMessage = null; var releaseTask = GitHubApi.GetLatestReleaseForRepo( GithubRepo, releaseType, r => parsed = r, e => errorMessage = e); while (releaseTask.MoveNext()) { yield return(releaseTask.Current); } if (!string.IsNullOrEmpty(errorMessage)) { EditorUtility.DisplayDialog("Error", errorMessage, "Ok"); yield break; } if (buildPacks.Any(p => p.Id == parsed.id)) { EditorUtility.DisplayDialog("Info", $"Version {parsed.tag_name} already downloaded", "Ok"); yield break; } var downloadTask = DownloadPack(packsLocation, parsed, error => { errorMessage = error; }); while (downloadTask.MoveNext()) { yield return(downloadTask.Current); if (!string.IsNullOrEmpty(errorMessage)) { EditorUtility.DisplayDialog("Error", errorMessage, "Ok"); yield break; } } if (!string.IsNullOrEmpty(errorMessage)) { EditorUtility.DisplayDialog("Error", errorMessage, "Ok"); yield break; } } finally { EditorUtility.ClearProgressBar(); UpdatePacksList(); } }
protected ReleaseResponse GetBuildEngineRelease(Product product) { ReleaseResponse releaseResponse = null; if (SetBuildEngineEndpoint(product.Project.Organization)) { releaseResponse = BuildEngineApi.GetRelease(product.WorkflowJobId, product.WorkflowBuildId, product.WorkflowPublishId); } return(releaseResponse); }
protected async Task ReleaseCompletedAsync(Product product, ReleaseResponse buildEngineRelease) { ClearRecurringJob(product.Id); product.DatePublished = DateTime.UtcNow; await ProductRepository.UpdateAsync(product); var messageParms = new Dictionary <string, object>() { { "projectName", product.Project.Name }, { "productName", product.ProductDefinition.Name } }; await sendNotificationService.SendNotificationToUserAsync(product.Project.Owner, "releaseCompletedSuccessfully", messageParms); }
public static Message <ReleaseResponse> ReadReleaseResponse(NetworkBinaryReader dr) { var relRes = new ReleaseResponse(); if (relRes.Write().Skip(1).SequenceEqual(dr.Take(9))) { return(new Message <ReleaseResponse> { Payload = relRes, Type = MessageType.PDU }); } //Invalid release response throw new Exception("Release response was invalid. Did not match signature."); }
protected async Task ReleaseCreationFailedAsync(Product product, ReleaseResponse buildEngineRelease) { ClearRecurringJob(product.Id); var messageParms = new Dictionary <string, object>() { { "projectName", product.Project.Name }, { "productName", product.ProductDefinition.Name }, { "releaseStatus", buildEngineRelease.Status }, { "releaseError", buildEngineRelease.Error }, { "buildEngineUrl", product.Project.Organization.BuildEngineUrl } }; await sendNotificationService.SendNotificationToOrgAdminsAndOwnerAsync(product.Project.Organization, product.Project.Owner, "releaseFailed", messageParms); }
public static void SendReleaseResponse(Association asc) { var resp = new ReleaseResponse(); asc.Logger.Log("-->" + resp); var message = resp.Write(); if (asc.Stream.CanWrite) { asc.Stream.Write(message, 0, message.Length); asc.State = NetworkState.CLOSING_ASSOCIATION; } }
public async Task Release_CreateAsync() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); var mockRecurringTaskManager = Mock.Get(buildReleaseService.RecurringJobManager); mockRecurringTaskManager.Reset(); mockBuildEngine.Reset(); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "initialized", Result = "", Error = "" }; mockBuildEngine.Setup(x => x.CreateRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Release>())).Returns(releaseResponse); var release = new Release { Channel = "production" }; await buildReleaseService.CreateReleaseAsync(product1.Id, "production", null); mockBuildEngine.Verify(x => x.SetEndpoint( It.Is <String>(u => u == org1.BuildEngineUrl), It.Is <String>(t => t == org1.BuildEngineApiAccessToken) )); mockBuildEngine.Verify(x => x.CreateRelease(It.Is <int>(b => b == product1.WorkflowJobId), It.Is <int>(b => b == product1.WorkflowBuildId), It.Is <Release>(b => b.Channel == "production"))); var token = "CreateReleaseMonitor" + product1.Id.ToString(); mockRecurringTaskManager.Verify(x => x.AddOrUpdate( It.Is <string>(t => t == token), It.Is <Job>(job => job.Method.Name == "CheckRelease" && job.Type == typeof(BuildEngineReleaseService)), It.Is <string>(c => c == "* * * * *"), It.IsAny <RecurringJobOptions>() )); var products = ReadTestData <AppDbContext, Product>(); var modifiedProduct = products.First(p => p.Id == product1.Id); Assert.Equal(3, modifiedProduct.WorkflowPublishId); Assert.Null(modifiedProduct.DatePublished); var notifications = ReadTestData <AppDbContext, Notification>(); Assert.Empty(notifications); }
private IEnumerator DownloadViewer(string folderPath) { try { ReleaseResponse parsed = null; string errorMessage = null; var downloadingTask = DownloadReleaseInfo( "latest", r => parsed = r, e => errorMessage = e); while (downloadingTask.MoveNext()) { yield return(downloadingTask.Current); } if (!string.IsNullOrEmpty(errorMessage)) { EditorUtility.DisplayDialog("Error", errorMessage, "Ok"); yield break; } var targetLink = parsed.assets.FirstOrDefault(a => a.name == "build.zip"); if (targetLink == null) { EditorUtility.DisplayDialog("Error", "No needed asset in latest release", "Ok"); yield break; } using (UnityWebRequest w = UnityWebRequest.Get(targetLink.browser_download_url)) { w.SetRequestHeader("User-Agent", "Mozilla/5.0"); yield return(w.SendWebRequest()); while (w.isDone == false) { yield return(null); EditorUtility.DisplayProgressBar("Downloading", "Downloading viewer", w.downloadProgress); } File.WriteAllBytes(Path.Combine(folderPath, $"web-viewer-{parsed.tag_name}-{parsed.id}.zip"), w.downloadHandler.data); } } finally { EditorUtility.ClearProgressBar(); FindBuildPacks(); } }
public async Task Release_Check_ReleaseAsync() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockNotificationService = Mock.Get(buildReleaseService.sendNotificationService.HubContext); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); mockBuildEngine.Reset(); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "SUCCESS", Error = "" }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(releaseResponse); await buildReleaseService.CheckReleaseAsync(product2.Id); mockBuildEngine.Verify(x => x.SetEndpoint( It.Is <String>(u => u == org1.BuildEngineUrl), It.Is <String>(t => t == org1.BuildEngineApiAccessToken) )); mockBuildEngine.Verify(x => x.GetRelease(It.Is <int>(i => i == product2.WorkflowJobId), It.Is <int>(b => b == product2.WorkflowBuildId), It.Is <int>(r => r == product2.WorkflowPublishId))); var products = ReadTestData <AppDbContext, Product>(); var modifiedProduct = products.First(p => p.Id == product2.Id); Assert.NotNull(modifiedProduct.DatePublished); // One notification should be sent to owner on successful build mockNotificationService.Verify(x => x.Clients.User(It.Is <string>(i => i == user1.ExternalId))); var notifications = ReadTestData <AppDbContext, Notification>(); Assert.Single(notifications); Assert.Equal("{\"projectName\":\"Test Project1\",\"productName\":\"TestProd1\"}", notifications[0].MessageSubstitutionsJson); Assert.Equal("releaseCompletedSuccessfully", notifications[0].MessageId); }
protected override IEnumerator DownloadPack(string rootLocation, ReleaseResponse release, Action <string> errorAction) { var targetLink = release.assets.FirstOrDefault(a => a.name == "build.zip"); if (targetLink == null) { errorAction("No needed asset in latest release"); yield break; } var downloadRequest = HttpHelper.InvokeGetRequest(targetLink.browser_download_url, $"Downloading {targetLink.name}", handler => { File.WriteAllBytes(Path.Combine(rootLocation, $"web-viewer-{release.tag_name}-{release.id}.zip"), handler.data); }, errorAction); while (downloadRequest.MoveNext()) { yield return(downloadRequest.Current); } }
public async Task Get_Release_Status_Success() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); mockBuildEngine.Reset(); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "SUCCESS", Error = "", }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(releaseResponse); var status = await buildReleaseService.GetStatusAsync(product2.Id); Assert.Equal(BuildEngineStatus.Success, status); }
public async Task Get_Release_Get_ConsoleText() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); mockBuildEngine.Reset(); var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "FAILURE", Error = "Error", ConsoleText = "https://dem-aps-artifacts.s3.amazonaws.com/dem/jobs/build_scriptureappbuilder_3/3/console.log" }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())).Returns(releaseResponse); var consoleText = await buildReleaseService.GetConsoleText(product2.Id); Assert.Equal("https://dem-aps-artifacts.s3.amazonaws.com/dem/jobs/build_scriptureappbuilder_3/3/console.log", consoleText); }
protected async Task CreateBuildEngineReleaseAsync(Product product, string channel, PerformContext context) { var release = new Release { Channel = channel }; ClearRecurringJob(product.Id); ReleaseResponse releaseResponse = null; if (SetBuildEngineEndpoint(product.Project.Organization)) { releaseResponse = BuildEngineApi.CreateRelease(product.WorkflowJobId, product.WorkflowBuildId, release); } if ((releaseResponse != null) && (releaseResponse.Id != 0)) { product.WorkflowPublishId = releaseResponse.Id; await ProductRepository.UpdateAsync(product); var monitorJob = Job.FromExpression <BuildEngineReleaseService>(service => service.CheckRelease(product.Id)); RecurringJobManager.AddOrUpdate(GetHangfireToken(product.Id), monitorJob, "* * * * *"); } else { var messageParms = new Dictionary <string, object>() { { "projectName", product.Project.Name }, { "productName", product.ProductDefinition.Name } }; await SendNotificationOnFinalRetryAsync(context, product.Project.Organization, product.Project.Owner, "releaseFailedUnableToCreate", messageParms); // Throw Exception to force retry throw new Exception("Create release failed"); } }
public async Task <IActionResult> GetAsync(int id, DateTime?realtime_start, DateTime?realtime_end) { ReleaseResponse result = new ReleaseResponse(); try { api.Arguments.ApiKey = appSettings.ApiKey; api.Arguments.release_id = id; api.Arguments.realtime_start = realtime_start ?? api.Arguments.realtime_start; api.Arguments.realtime_end = realtime_end ?? api.Arguments.realtime_end; result.container = await api.FetchAsync(); SetApiValues(api, result); } catch (Exception exception) { logger.LogError(exception, "GetRelease failed"); return(StatusCode(500)); } return(Ok(result)); }
public JsonResult CurrentRelease(ReleaseRequest rreq) { ReleaseResponse release = null; try { if (rreq != null) { if (Request.Cookies["AUTH_PTEmail"] != null && Request.Cookies["AUTHADMIN"] != null && Request.Cookies["AUTHADMIN"].Value == "Admin") { rreq.emailid = ""; } release = CABusinessProjectTrackingAPIClient.GetHttpResponse <ReleaseResponse>(rreq, CABPTMethodConstants.CURRENTRELEASE); } return(Json(JsonConvert.SerializeObject(release))); } catch (Exception ex) { JsonExceptionResult jsonexc = new JsonExceptionResult(); return(Json(JsonConvert.SerializeObject(new CABPTException(ex, out jsonexc)))); } }
protected abstract IEnumerator DownloadPack(string rootLocation, ReleaseResponse release, Action <string> errorAction);
protected void ReleaseCreationFailed(Product product, ReleaseResponse buildEngineRelease) { ClearRecurringJob(product.Id); }
public static void GetNewestSdkVersion(Action <ReleaseResponse> callback) { string url = "https://raw.githubusercontent.com/GotoFinal/GotoUdon/master/Assets/GotoUdon/Settings/VRCSDKVersion"; UnityWebRequest www = UnityWebRequest.Get(url); try { UnityWebRequestAsyncOperation action = www.SendWebRequest(); DownloadHandler downloadHandler = www.downloadHandler; action.completed += operation => { try { UnityWebRequest request = action.webRequest; var responseCode = request.responseCode; if (responseCode != 200) { callback(new ReleaseResponse { Error = $"Failed to check for new VrChat SDK version: {request.error}" }); www.Dispose(); return; } string version = downloadHandler.text; string description = version == GotoUdonEditor.ImplementedSDKVersion ? "This is recommended version of VRChat SDK for GotoUdon!" : "This version might not be fully supported by GotoUdon. If there is new version of GotoUdon available first update SDK then GotoUdon for best compatibility."; callback(new ReleaseResponse { ReleaseInfo = new ReleaseInfo { Name = $"VRCSDK3-WORLD-{version}_Public", Version = version, Description = description, Assets = new List <ReleaseAsset> { new ReleaseAsset { Name = $"VRCSDK3-WORLD-{version}_Public.unitypackage", DownloadUrl = "https://vrchat.com/download/sdk3-worlds" } } } }); } catch (Exception exception) { ReleaseResponse response = new ReleaseResponse { Error = "Failed to read response from GotoUdon GitHub sdk file: " + exception.Message }; GotoLog.Exception(response.Error, exception); callback(response); } finally { www.Dispose(); } }; } catch (Exception exception) { www.Dispose(); ReleaseResponse response = new ReleaseResponse { Error = "Failed to send request to check VRChat SDK update: " + exception.Message }; GotoLog.Exception(response.Error, exception); callback(response); } }
public async Task Release_Check_ReleaseAsync() { BuildTestData(); var buildReleaseService = _fixture.GetService <BuildEngineReleaseService>(); var mockBuildEngine = Mock.Get(buildReleaseService.BuildEngineApi); var mockWebClient = Mock.Get(buildReleaseService.WebClient); mockBuildEngine.Reset(); mockWebClient.Reset(); Assert.Empty(ReadTestData <AppDbContext, Notification>()); var productBuild = AddEntity <AppDbContext, ProductBuild>(new ProductBuild { ProductId = product2.Id, BuildId = 2, }); var productRelease = AddEntity <AppDbContext, ProductPublication>(new ProductPublication { ProductId = product2.Id, ProductBuildId = productBuild.Id, ReleaseId = 3 }); var consoleText = "https://dem-aps-artifacts.s3.amazonaws.com/dem/jobs/publish_scriptureappbuilder_2/17/console.log"; var publishUrl = "https://dem-aps-artifacts.s3.amazonaws.com/dem/jobs/publish_scriptureappbuilder_2/17/publish_url.txt"; var publishUrlContents = "https://google.play/path/to/app"; var releaseResponse = new ReleaseResponse { Id = 3, BuildId = 2, Status = "completed", Result = "SUCCESS", Error = "", Artifacts = new Dictionary <string, string> { { "publishUrl", publishUrl }, { "consoleText", consoleText } }, ConsoleText = consoleText }; mockBuildEngine.Setup(x => x.GetRelease(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>())) .Returns(releaseResponse); mockWebClient.Setup(x => x.DownloadString(It.Is <string>(addr => addr == publishUrl))) .Returns(publishUrlContents); await buildReleaseService.CheckReleaseAsync(product2.Id); mockBuildEngine.Verify(x => x.SetEndpoint( It.Is <String>(u => u == org1.BuildEngineUrl), It.Is <String>(t => t == org1.BuildEngineApiAccessToken) )); mockBuildEngine.Verify(x => x.GetRelease(It.Is <int>(i => i == product2.WorkflowJobId), It.Is <int>(b => b == product2.WorkflowBuildId), It.Is <int>(r => r == product2.WorkflowPublishId))); var products = ReadTestData <AppDbContext, Product>(); var modifiedProduct = products.First(p => p.Id == product2.Id); Assert.NotNull(modifiedProduct.DatePublished); var modifiedProductPublications = ReadTestData <AppDbContext, ProductPublication>(); Assert.Single(modifiedProductPublications); var publication = modifiedProductPublications.First(); Assert.True(publication.Success.HasValue && publication.Success.Value); Assert.Equal(consoleText, publication.LogUrl); Assert.Equal(publishUrlContents, modifiedProduct.PublishLink); // One notification should be sent to owner on successful build var notifications = ReadTestData <AppDbContext, Notification>(); Assert.Single(notifications); var userIds = notifications.Select(n => n.UserId); Assert.Contains(user1.Id, userIds); Assert.Equal("{\"projectName\":\"Test Project1\",\"productName\":\"TestProd1\"}", notifications[0].MessageSubstitutionsJson); Assert.Equal("releaseCompletedSuccessfully", notifications[0].MessageId); }
public static void GetNewestVersion(string author, string repository, Action <ReleaseResponse> callback) { string url = $"https://api.github.com/repos/{author}/{repository}/releases/latest"; UnityWebRequest www = UnityWebRequest.Get(url); try { UnityWebRequestAsyncOperation action = www.SendWebRequest(); DownloadHandler downloadHandler = www.downloadHandler; action.completed += operation => { UnityWebRequest request = action.webRequest; var responseCode = request.responseCode; if (responseCode != 200) { callback(new ReleaseResponse { Error = $"Failed to check for new version: {request.error}" }); www.Dispose(); return; } GithubRespone githubRespone = JsonUtility.FromJson <GithubRespone>(downloadHandler.text); try { callback(new ReleaseResponse { ReleaseInfo = new ReleaseInfo { Name = githubRespone.name, Version = githubRespone.tag_name, Description = githubRespone.body, Assets = ReadAssets(githubRespone.assets) } }); } catch (Exception exception) { ReleaseResponse response = new ReleaseResponse { Error = "Failed to read response from Gtihub API: " + exception.Message }; GotoLog.Exception(response.Error, exception); callback(response); } finally { www.Dispose(); } }; } catch (Exception exception) { www.Dispose(); ReleaseResponse response = new ReleaseResponse { Error = "Failed to send request to check update: " + exception.Message }; GotoLog.Exception(response.Error, exception); callback(response); } }