public GitHubActions.Job ProcessJob(AzurePipelines.Job job, AzurePipelines.Resources resources)
        {
            GeneralProcessing   generalProcessing = new GeneralProcessing(_verbose);
            VariablesProcessing vp = new VariablesProcessing(_verbose);
            StepsProcessing     sp = new StepsProcessing();

            GitHubActions.Job newJob = new GitHubActions.Job
            {
                name            = job.displayName,
                needs           = job.dependsOn,
                _if             = ConditionsProcessing.TranslateConditions(job.condition),
                runs_on         = generalProcessing.ProcessPool(job.pool),
                strategy        = generalProcessing.ProcessStrategy(job.strategy),
                container       = generalProcessing.ProcessContainer(resources),
                env             = vp.ProcessSimpleVariables(job.variables),
                timeout_minutes = job.timeoutInMinutes,
                steps           = sp.AddSupportingSteps(job.steps)
            };
            MatrixVariableName = generalProcessing.MatrixVariableName;
            VariableList       = vp.VariableList;

            if (newJob.steps == null & job.template != null)
            {
                //Initialize the array with no items
                job.steps = new AzurePipelines.Step[0];
                //Process the steps, adding the default checkout step
                newJob.steps = sp.AddSupportingSteps(job.steps, true);
                //TODO: There is currently no conversion path for templates
                newJob.job_message += "Note: Azure DevOps template does not have an equivalent in GitHub Actions yet";
            }
            else if (newJob.steps == null && job.strategy?.runOnce?.deploy?.steps != null)
            {
                //Initialize the array with no items
                job.steps = new AzurePipelines.Step[0];
                //Process the steps, adding the default checkout step
                newJob.steps = sp.AddSupportingSteps(job.strategy?.runOnce?.deploy?.steps, false);
                //TODO: There is currently no conversion path for templates
                newJob.job_message += "Note: Azure DevOps strategy>runOnce>deploy does not have an equivalent in GitHub Actions yet";
            }
            if (job.environment != null)
            {
                newJob.job_message += "Note: Azure DevOps job environment does not have an equivalent in GitHub Actions yet";
            }
            if (job.continueOnError == true)
            {
                newJob.continue_on_error = job.continueOnError;
            }

            return(newJob);
        }
Example #2
0
        private GitHubActions.Step CreateScriptStep(string shellType, AzurePipelines.Step step)
        {
            GitHubActions.Step gitHubStep = new GitHubActions.Step
            {
                run   = step.script,
                shell = shellType
            };

            if (gitHubStep.run == null)
            {
                if (step.powershell != null)
                {
                    gitHubStep.run = step.powershell;
                }
                else if (step.pwsh != null)
                {
                    gitHubStep.run = step.pwsh;
                }
                else if (step.bash != null)
                {
                    gitHubStep.run = step.bash;
                }
                else
                {
                    if (step.inputs != null)
                    {
                        string runValue = GetStepInput(step, "script");
                        gitHubStep.run = runValue;
                    }
                }
            }
            if (gitHubStep.shell == "")
            {
                gitHubStep.shell = null;
            }
            if (step.condition != null)
            {
                gitHubStep._if = ConditionsProcessing.TranslateConditions(step.condition);
            }

            return(gitHubStep);
        }
        public AzurePipelines.Job[] ExtractAzurePipelinesJobsV2(JToken jobsJson, string strategyYaml)
        {
            GeneralProcessing gp = new GeneralProcessing(_verbose);

            AzurePipelines.Job[] jobs = new AzurePipelines.Job[jobsJson.Count()];
            if (jobsJson != null)
            {
                int i = 0;
                foreach (JToken jobJson in jobsJson)
                {
                    AzurePipelines.Job job = new AzurePipelines.Job
                    {
                        job         = jobJson["job"]?.ToString(),
                        deployment  = jobJson["deployment"]?.ToString(),
                        displayName = jobJson["displayName"]?.ToString(),
                        template    = jobJson["template"]?.ToString()
                    };
                    if (jobJson["pool"] != null)
                    {
                        job.pool = gp.ProcessPoolV2(jobJson["pool"].ToString());
                    }
                    if (jobJson["strategy"] != null)
                    {
                        job.strategy = gp.ProcessStrategyV2(jobJson["strategy"].ToString());
                    }
                    else if (strategyYaml != null)
                    {
                        job.strategy = gp.ProcessStrategyV2(strategyYaml);
                    }
                    if (jobJson["dependsOn"] != null)
                    {
                        job.dependsOn = gp.ProcessDependsOnV2(jobJson["dependsOn"].ToString());
                    }
                    if (jobJson["condition"] != null)
                    {
                        job.condition = ConditionsProcessing.TranslateConditions(jobJson["condition"].ToString());
                    }
                    if (jobJson["environment"] != null)
                    {
                        job.environment = gp.ProcessEnvironmentV2(jobJson["environment"].ToString());
                    }
                    if (jobJson["timeoutInMinutes"] != null)
                    {
                        int.TryParse(jobJson["timeoutInMinutes"].ToString(), out int timeOut);
                        if (timeOut > 0)
                        {
                            job.timeoutInMinutes = timeOut;
                        }
                    }
                    if (jobJson["continueOnError"] != null)
                    {
                        bool.TryParse(jobJson["continueOnError"].ToString(), out bool continueOnError);
                        job.continueOnError = continueOnError;
                    }
                    if (jobJson["variables"] != null)
                    {
                        VariablesProcessing vp = new VariablesProcessing(_verbose);
                        job.variables = vp.ProcessParametersAndVariablesV2(null, jobJson["variables"].ToString());
                    }
                    if (jobJson["steps"] != null)
                    {
                        try
                        {
                            job.steps = GenericObjectSerialization.DeserializeYaml <AzurePipelines.Step[]>(jobJson["steps"].ToString());
                        }
                        catch (Exception ex)
                        {
                            ConversionUtility.WriteLine($"DeserializeYaml<AzurePipelines.Step[]>(jobJson[\"steps\"].ToString() swallowed an exception: " + ex.Message, _verbose);
                        }
                    }
                    jobs[i] = job;
                    i++;
                }
            }

            return(jobs);
        }
Example #4
0
 //process the conditions
 private string ProcessCondition(string condition)
 {
     return(ConditionsProcessing.TranslateConditions(condition));
 }
Example #5
0
        //TODO: Add more task types
        public GitHubActions.Step ProcessStep(AzurePipelines.Step step)
        {
            GitHubActions.Step gitHubStep = null;
            if (step.task != null)
            {
                step = CleanStepInputs(step);
                //TODO: Should we be handling versions seperately?
                switch (step.task)
                {
                case "Ant@1":
                    gitHubStep = CreateAntStep(step);
                    break;

                case "ArchiveFiles@2":
                    gitHubStep = CreateArchiveFilesStep(step);
                    break;

                case "AzureAppServiceManage@0":
                    gitHubStep = CreateAzureAppServiceManageStep(step);
                    break;

                case "AzureResourceGroupDeployment@2":
                    gitHubStep = CreateAzureManageResourcesStep(step);
                    break;

                case "AzureFunctionAppContainer@1":
                case "AzureRmWebAppDeployment@3":
                case "AzureWebAppContainer@1":
                case "AzureRmWebAppDeployment@4":
                    gitHubStep = CreateAzureWebAppDeploymentStep(step);
                    break;

                case "CmdLine@2":
                    gitHubStep = CreateScriptStep("cmd", step);
                    break;

                case "CopyFiles@2":
                    gitHubStep = CreateCopyFilesStep(step);
                    break;

                case "Docker@1":
                case "Docker@2":
                    gitHubStep = CreateDockerStep(step);
                    break;

                case "DotNetCoreCLI@2":
                    gitHubStep = CreateDotNetCommandStep(step);
                    break;

                case "DownloadBuildArtifacts@0":
                    gitHubStep = CreateDownloadBuildArtifacts(step);
                    break;

                case "Gradle@2":
                    gitHubStep = CreateGradleStep(step);
                    break;

                case "Maven@3":
                    gitHubStep = CreateMavenStep(step);
                    break;

                case "NodeTool@0":
                    gitHubStep = CreateNodeToolStep(step);
                    break;

                case "NuGetCommand@2":
                    gitHubStep = CreateNuGetCommandStep(step);
                    break;

                case "NuGetToolInstaller@1":
                    gitHubStep = CreateNuGetToolInstallerStep();
                    break;

                case "PowerShell@2":
                    gitHubStep = CreateScriptStep("powershell", step);
                    break;

                case "PublishPipelineArtifact@0":
                case "PublishBuildArtifacts@1":
                    gitHubStep = CreatePublishBuildArtifactsStep(step);
                    break;

                case "PythonScript@0":
                    gitHubStep = CreatePythonStep(step);
                    break;

                case "SqlAzureDacpacDeployment@1":
                    gitHubStep = CreateSQLAzureDacPacDeployStep(step);
                    break;

                case "UseDotNet@2":
                    gitHubStep = CreateUseDotNetStep(step);
                    break;

                case "UsePythonVersion@0":
                    gitHubStep = CreateUsePythonStep(step);
                    break;

                case "UseRubyVersion@0":
                    gitHubStep = CreateUseRubyStep(step);
                    break;

                case "VSBuild@1":
                    gitHubStep = CreateMSBuildStep(step);
                    break;

                case "VSTest@2":
                    gitHubStep = CreateFunctionalTestingStep(step);
                    break;

                case "XamarinAndroid@1":
                    gitHubStep = CreateXamarinAndroidStep(step);
                    break;

                case "XamariniOS@2":
                    gitHubStep = CreateXamariniOSStep(step);
                    break;

                default:
                    gitHubStep = CreateScriptStep("powershell", step);
                    string        newYaml      = GenericObjectSerialization.SerializeYaml <AzurePipelines.Step>(step);
                    string[]      newYamlSplit = newYaml.Split(Environment.NewLine);
                    StringBuilder yamlBuilder  = new StringBuilder();
                    for (int i = 0; i < newYamlSplit.Length; i++)
                    {
                        string line = newYamlSplit[i];
                        if (line.Trim().Length > 0)
                        {
                            yamlBuilder.Append("#");
                            yamlBuilder.Append(line);
                        }
                    }
                    gitHubStep.step_message = "Note: This step does not have a conversion path yet: " + step.task;
                    gitHubStep.run          = "Write-Host " + gitHubStep.step_message + " " + yamlBuilder.ToString();
                    break;
                }
            }
            else if (step.script != null)
            {
                gitHubStep = new GitHubActions.Step
                {
                    run  = step.script,
                    with = step.inputs
                };
            }
            else if (step.pwsh != null)
            {
                gitHubStep = CreateScriptStep("pwsh", step);
            }
            else if (step.powershell != null)
            {
                gitHubStep = CreateScriptStep("powershell", step);
            }
            else if (step.bash != null)
            {
                gitHubStep = CreateScriptStep("bash", step);
            }
            else if (step.publish != null)
            {
                //The shortcut to the build publish step
                //https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#publish
                gitHubStep = CreatePublishBuildArtifactsStep(step);
            }

            if (gitHubStep != null)
            {
                //Add in generic name and conditions
                if (step.displayName != null)
                {
                    gitHubStep.name = step.displayName;
                }
                if (step.condition != null)
                {
                    gitHubStep._if = ConditionsProcessing.TranslateConditions(step.condition);
                }
                //Double check the with. Sometimes we start to add a property, but for various reasons, we don't use it, and have to null out the with so it doesn't display an empty node in the final yaml
                if (gitHubStep.with != null)
                {
                    if (gitHubStep.with.Count >= 0)
                    {
                        //Look to see if there is non-null data in the collection
                        bool foundData = false;
                        foreach (KeyValuePair <string, string> item in gitHubStep.with)
                        {
                            //If data was found, break out of the loop, we don't need to look anymore
                            if (item.Value != null)
                            {
                                foundData = true;
                                break;
                            }
                        }
                        //If no data was found, null out the with property
                        if (foundData == false)
                        {
                            gitHubStep.with = null;
                        }
                    }
                }
            }
            return(gitHubStep);
        }