예제 #1
0
        public static DevOpsBuild PollBuild([ActivityTrigger] string buildUrl, ILogger log)
        {
            log.LogInformation($"Polling the build URL: {buildUrl}...");
            DevOpsBuild build = DevOpsHelper.GetBuildStatus(buildUrl, log).Result;

            return(build);
        }
예제 #2
0
        public async Task <bool> IsUpdateAvailable()
        {
            DevOpsBuild buildInfo = await GetBuildInfo(1);

            double buildNumber = double.Parse(buildInfo.BuildNumber, CultureInfo.InvariantCulture);

            return(buildNumber > Constants.BuildInfo.BuildNumber);
        }
예제 #3
0
        public static DevOpsBuild QueueBuild([ActivityTrigger] DevOpsBuildContext buildContext, ILogger log)
        {
            log.LogInformation($"Kicking off a build for {buildContext.BuildTaskName}...");
            string      authToken = EnvironmentHelper.GetAuthToken();
            DevOpsBuild build     = DevOpsHelper.QueueDevOpsBuild(buildContext, authToken, log).Result;

            return(build);
        }
예제 #4
0
 public async Task <GitHubDifference> GetBuildDifferences(DevOpsBuild a, DevOpsBuild b)
 {
     return(await "https://api.github.com"
            .AppendPathSegments("repos", "Artemis-RGB", "Artemis", "compare")
            .AppendPathSegment(a.SourceVersion + "..." + b.SourceVersion)
            .WithHeader("User-Agent", "Artemis 2")
            .WithHeader("Accept", "application/vnd.github.v3+json")
            .GetJsonAsync <GitHubDifference>());
 }
예제 #5
0
        private async Task OfferUpdate(DevOpsBuild buildInfo)
        {
            object result = await _dialogService.ShowDialog <UpdateDialogViewModel>(new Dictionary <string, object> {
                { "buildInfo", buildInfo }
            });

            if (result is bool resultBool && resultBool == false)
            {
                SuspendAutoUpdate = true;
            }
        }
예제 #6
0
        public UpdateDialogViewModel(DevOpsBuild buildInfo, IUpdateService updateService, IDialogService dialogService, IMessageService messageService)
        {
            _updateService  = updateService;
            _dialogService  = dialogService;
            _messageService = messageService;

            CurrentBuild = Constants.BuildInfo.BuildNumberDisplay;
            LatestBuild  = buildInfo.BuildNumber;
            Changes      = new BindableCollection <string>();

            Task.Run(GetBuildChanges);
        }
예제 #7
0
        public async Task ApplyUpdate()
        {
            _logger.Information("ApplyUpdate: Applying update");

            // Ensure the installer is up-to-date, get installer build info
            DevOpsBuild buildInfo = await GetBuildInfo(6);

            string installerPath = Path.Combine(Constants.DataFolder, "installer", "Artemis.Installer.exe");

            // Always update installer if it is missing ^^
            if (!File.Exists(installerPath))
            {
                await UpdateInstaller();
            }
            // Compare the creation date of the installer with the build date and update if needed
            else
            {
                if (File.GetLastWriteTime(installerPath) < buildInfo.FinishTime)
                {
                    await UpdateInstaller();
                }
            }

            _logger.Information("ApplyUpdate: Running installer at {installerPath}", installerPath);

            try
            {
                Process.Start(new ProcessStartInfo(installerPath, "-autoupdate")
                {
                    UseShellExecute = true,
                    Verb            = "runas"
                });
            }
            catch (Win32Exception e)
            {
                if (e.NativeErrorCode == 0x4c7)
                {
                    _logger.Warning("ApplyUpdate: Operation was cancelled, user likely clicked No in UAC dialog.");
                }
                else
                {
                    throw;
                }
            }
        }
예제 #8
0
        public async Task <bool> OfferUpdateIfFound()
        {
            _logger.Information("Checking for updates");

            DevOpsBuild buildInfo = await GetBuildInfo(1);

            double buildNumber = double.Parse(buildInfo.BuildNumber, CultureInfo.InvariantCulture);

            string buildNumberDisplay = buildNumber.ToString(CultureInfo.InvariantCulture);

            _logger.Information("Latest build is {buildNumber}, we're running {localBuildNumber}", buildNumberDisplay, Constants.BuildInfo.BuildNumberDisplay);

            if (buildNumber <= Constants.BuildInfo.BuildNumber)
            {
                return(false);
            }

            if (_windowService.IsMainWindowOpen)
            {
                await OfferUpdate(buildInfo);
            }
            else if (_autoInstallUpdates.Value)
            {
                new ToastContentBuilder()
                .AddText("Installing new version", AdaptiveTextStyle.Header)
                .AddText($"Build {buildNumberDisplay} is available, currently on {Constants.BuildInfo.BuildNumberDisplay}.")
                .AddProgressBar(null, null, true)
                .Show();

                await ApplyUpdate();
            }
            else
            {
                // If auto-install is disabled and the window is closed, best we can do is notify the user and stop.
                new ToastContentBuilder()
                .AddText("New version available", AdaptiveTextStyle.Header)
                .AddText($"Build {buildNumberDisplay} is available, currently on {Constants.BuildInfo.BuildNumberDisplay}.")
                .AddButton("Update", ToastActivationType.Background, "update")
                .AddButton("Later", ToastActivationType.Background, "later")
                .Show(t => t.Activated += TOnActivated);
            }

            return(true);
        }
예제 #9
0
        public async Task <bool> OfferUpdateIfFound()
        {
            _logger.Information("Checking for updates");

            DevOpsBuild buildInfo = await GetBuildInfo(1);

            double buildNumber = double.Parse(buildInfo.BuildNumber, CultureInfo.InvariantCulture);

            string buildNumberDisplay = buildNumber.ToString(CultureInfo.InvariantCulture);

            _logger.Information("Latest build is {buildNumber}, we're running {localBuildNumber}", buildNumberDisplay, Constants.BuildInfo.BuildNumberDisplay);

            if (buildNumber <= Constants.BuildInfo.BuildNumber)
            {
                return(false);
            }

            if (_windowService.IsMainWindowOpen)
            {
                await OfferUpdate(buildInfo);
            }
            else if (_autoInstallUpdates.Value)
            {
                // Lets go
                _messageService.ShowNotification(
                    "Installing new version",
                    $"Build {buildNumberDisplay} is available, currently on {Constants.BuildInfo.BuildNumberDisplay}.",
                    PackIconKind.Update
                    );
                await ApplyUpdate();
            }
            else
            {
                // If auto-install is disabled and the window is closed, best we can do is notify the user and stop.
                _messageService.ShowNotification(
                    "New version available",
                    $"Build {buildNumberDisplay} is available, currently on {Constants.BuildInfo.BuildNumberDisplay}.",
                    PackIconKind.Update
                    );
            }

            return(true);
        }
예제 #10
0
        public static async Task <DevOpsBuild> OrchestrateBuild([OrchestrationTrigger] DurableOrchestrationContext context)
        {
            DevOpsBuildContext buildContext = context.GetInput <DevOpsBuildContext>();
            DevOpsBuild        build        = await context.CallActivityAsync <DevOpsBuild>("BuildManager_QueueBuild", buildContext);

            DateTime expiry          = context.CurrentUtcDateTime + TimeSpan.FromMinutes(Constants.PollSettings.expiryMinutes);
            TimeSpan pollingInterval = TimeSpan.FromSeconds(Constants.PollSettings.pollingIntervalSecs);

            while (context.CurrentUtcDateTime < expiry)
            {
                build = await context.CallActivityAsync <DevOpsBuild>("BuildManager_GetBuildStatus", build.Url);

                if (build.Status == BuildStatus.completed)
                {
                    // For worker builds we need to get the artifacts and upload it
                    if (Constants.LanguageWorkersForBuild.Contains(buildContext.Agent) &&
                        EnvironmentHelper.ShouldUploadArtifact())
                    {
                        var artifactContext = ContextProvider.GetWorkerArtifactContext(build.Id, buildContext.Agent);
                        var artifact        = await context.CallActivityAsync <DevOpsArtifact>("BuildManager_GetBuildArtifact", artifactContext);

                        if (artifact != null)
                        {
                            // TODO: change the platform here
                            var uploadContext = ContextProvider.GetWorkerArtifactUploadContext(artifact,
                                                                                               $"{Utilities.BuildTypeToCon(buildContext.BuildType)}", buildContext.Agent);

                            await context.CallActivityAsync("BuildManager_UploadToStorage", uploadContext);
                        }
                        // TODO: if it is null, a special failed tests file should be dropped at the storage account
                    }
                    return(build);
                }

                // Orchestration sleeps until this time.
                var nextCheck = context.CurrentUtcDateTime + pollingInterval;
                await context.CreateTimer(nextCheck, CancellationToken.None);
            }

            // TODO: Need to verify that this is ok
            // and probably throw a "failure" log
            return(build);
        }
예제 #11
0
        public static async Task <DevOpsBuild> QueueDevOpsBuild(DevOpsBuildContext buildContext, string authToken, ILogger logger)
        {
            Uri         url         = new Uri(Endpoints.GetQueueBuildUrl(buildContext.Organization, buildContext.Project));
            DevOpsBuild devOpsBuild = new DevOpsBuild
            {
                Definition = new Definition
                {
                    Id = buildContext.DefinitionId
                }
            };

            if (buildContext.Parameters.Count != 0)
            {
                devOpsBuild.Parameters = JsonConvert.SerializeObject(buildContext.Parameters);
            }
            var bearerToken = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", authToken)));

            var response = await DevOpsClient.HttpInvoke("POST", url, bearerToken, devOpsBuild, logger);

            response.EnsureSuccessStatusCode();
            var responseContent = await response.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <DevOpsBuild>(responseContent));
        }