public static string SerializeJob(GitHubActions.Job gitHubActionJob, List <string> variableList = null) { string yaml = GenericObjectSerialization.SerializeYaml <GitHubActions.Job>(gitHubActionJob); yaml = ProcessGitHubActionYAML(yaml, variableList); yaml = StepsPostProcessing(yaml); return(yaml); }
private GitHubActions.Job ProcessIndividualJob(AzurePipelines.Job job, AzurePipelines.Resources resources) { GitHubActions.Job newJob = new GitHubActions.Job { name = job.displayName, needs = job.dependsOn, _if = ProcessCondition(job.condition), runs_on = ProcessPool(job.pool), strategy = ProcessStrategy(job.strategy), container = ProcessContainer(resources), env = ProcessSimpleVariables(job.variables), timeout_minutes = job.timeoutInMinutes, steps = ProcessSteps(job.steps) }; 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 = ProcessSteps(job.steps, true); //TODO: Find a way to allow GitHub jobs to reference another job as a template 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 = ProcessSteps(job.strategy?.runOnce?.deploy?.steps, false); //TODO: Find a way to allow GitHub jobs to reference another job as a template 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 (newJob._if != null) { if (newJob.job_message != null) { newJob.job_message += Environment.NewLine; } } if (job.continueOnError) { newJob.continue_on_error = job.continueOnError; } return(newJob); }
/// <summary> /// Convert a single Azure DevOps Pipeline task to a GitHub Actions task /// </summary> /// <param name="input">Yaml to convert</param> /// <returns>Converion object, with original yaml, processed yaml, and comments on the conversion</returns> public ConversionResponse ConvertAzurePipelineTaskToGitHubActionTask(string input) { string yaml = ""; string processedInput = ConversionUtility.StepsPreProcessing(input); GitHubActions.Step gitHubActionStep = new GitHubActions.Step(); //Process the YAML for the individual job AzurePipelines.Job azurePipelinesJob = GenericObjectSerialization.DeserializeYaml <AzurePipelines.Job>(processedInput); if (azurePipelinesJob != null && azurePipelinesJob.steps != null && azurePipelinesJob.steps.Length > 0) { //As we needed to create an entire (but minimal) pipelines job, we need to now extract the step for processing StepsProcessing stepsProcessing = new StepsProcessing(); gitHubActionStep = stepsProcessing.ProcessStep(azurePipelinesJob.steps[0]); //Find all variables in this text block, we need this for a bit later VariablesProcessing vp = new VariablesProcessing(_verbose); List <string> variableList = vp.SearchForVariables(processedInput); //Create the GitHub YAML and apply some adjustments if (gitHubActionStep != null) { //add the step into a github job so it renders correctly GitHubActions.Job gitHubJob = new GitHubActions.Job { steps = new GitHubActions.Step[1] //create an array of size 1 }; //Load the step into the single item array gitHubJob.steps[0] = gitHubActionStep; //Finally, we can serialize the job back to yaml yaml = GitHubActionsSerialization.SerializeJob(gitHubJob, variableList); } } //Load failed tasks and comments for processing List <string> allComments = new List <string>(); if (gitHubActionStep != null) { allComments.Add(gitHubActionStep.step_message); } //Return the final conversion result, with the original (pipeline) yaml, processed (actions) yaml, and any comments return(new ConversionResponse { pipelinesYaml = input, actionsYaml = yaml, comments = allComments }); }
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); }