コード例 #1
0
        private string RunStartupScriptGeneratorForPlatform(
            IProgrammingPlatform platform,
            RunScriptGeneratorContext ctx)
        {
            var scriptGenPath = FilePaths.RunScriptGeneratorDir + "/" + platform.Name;
            var scriptGenArgs = new List <string>();

            // 'create-script' is only supported for these platform as of now
            if (platform is NodePlatform || platform is PythonPlatform)
            {
                scriptGenArgs.Add("create-script");
            }

            scriptGenArgs.AddRange(new[] { "-appPath", ctx.SourceRepo.RootPath, "-output", _tempScriptPath });

            if (ctx.PassThruArguments != null)
            {
                scriptGenArgs.AddRange(ctx.PassThruArguments);
            }

            (int exitCode, string stdout, string stderr) = ProcessHelper.RunProcess(
                scriptGenPath, scriptGenArgs, Environment.CurrentDirectory, RunScriptGeneratorTimeout);

            if (exitCode != ProcessConstants.ExitSuccess)
            {
                _logger.LogError("Generated run script returned exit code '{exitCode}'", exitCode);
                throw new Exception($"{scriptGenPath} failed");
            }

            return(File.ReadAllText(_tempScriptPath));
        }
コード例 #2
0
        public string GenerateBashScript(RunScriptGeneratorContext ctx)
        {
            if (ctx.SourceRepo == null)
            {
                throw new ArgumentNullException(nameof(ctx.SourceRepo), "Source repository must be supplied.");
            }

            IProgrammingPlatform targetPlatform = null;

            if (!string.IsNullOrEmpty(ctx.Platform))
            {
                targetPlatform = _programmingPlatforms
                                 .Where(p => p.Name.EqualsIgnoreCase(ctx.Platform))
                                 .FirstOrDefault();

                if (targetPlatform == null)
                {
                    throw new UnsupportedPlatformException($"Platform '{ctx.Platform}' is not supported.");
                }
            }
            else
            {
                _logger.LogDebug("No platform provided for run-script command; attempting to determine platform...");
                foreach (var platform in _programmingPlatforms)
                {
                    _logger.LogDebug($"Checking if platform '{platform.Name}' is compatible...");
                    var detectionResult = platform.Detect(ctx);
                    if (detectionResult != null)
                    {
                        _logger.LogDebug($"Detected platform '{detectionResult.Language}' with version '{detectionResult.LanguageVersion}'.");
                        if (string.IsNullOrEmpty(detectionResult.LanguageVersion))
                        {
                            throw new UnsupportedVersionException($"Couldn't detect a version for platform '{detectionResult.Language}' in the repo.");
                        }

                        targetPlatform = platform;
                        break;
                    }
                }

                if (targetPlatform == null)
                {
                    throw new UnsupportedPlatformException("Unable to determine the platform for the given repo.");
                }
            }

            return(RunStartupScriptGeneratorForPlatform(targetPlatform, ctx));
        }