Skip to content

Commit

Permalink
Merge pull request #225 from samsmithnz/feature/newtasks24dec
Browse files Browse the repository at this point in the history
Fixes to various tasks and improving tests
  • Loading branch information
samsmithnz authored Dec 25, 2020
2 parents 8f2ad78 + ec13b78 commit eedaf2e
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 58 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
run: dotnet test src/AzurePipelinesToGitHubActionsConverter.Tests/AzurePipelinesToGitHubActionsConverter.Tests.csproj --configuration Release --no-build /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
if: runner.OS == 'Linux' #Only push the Linux coverage
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: src/AzurePipelinesToGitHubActionsConverter.Tests/TestResults/coverage.info
Expand All @@ -50,10 +51,12 @@ jobs:
run: dotnet pack src/AzurePipelinesToGitHubActionsConverter.Core/AzurePipelinesToGitHubActionsConverter.Core.csproj --configuration Release --no-build /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }}
- name: Upload nuget package back to GitHub
uses: actions/upload-artifact@v2
if: runner.OS == 'Linux' #Only pack the Linux nuget package
with:
name: nugetPackage
path: src/AzurePipelinesToGitHubActionsConverter.Core/bin/Release


NuGetPush:
runs-on: ubuntu-latest
needs: build
Expand Down
8 changes: 4 additions & 4 deletions src/AzurePipelinesToGitHubActionsConverter.Core/Conversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ private ConversionResponse ConvertAzurePipelineToGitHubActionV2(string yaml)
gitHubActions.jobs = sp.ProcessStagesV2(json["stages"], json["strategy"]);
}
//If we don't have stages, but have jobs:
else if (json["stages"] == null && json["jobs"] != null)
else if (json["stages"] == null & json["jobs"] != null)
{
JobProcessing jp = new JobProcessing(_verbose);
gitHubActions.jobs = jp.ProcessJobsV2(jp.ExtractAzurePipelinesJobsV2(json["jobs"], json["strategy"]), gp.ExtractResourcesV2(resourcesYaml));
_matrixVariableName = jp.MatrixVariableName;
}
//Otherwise, if we don't have stages or jobs, we just have steps, and need to load them into a new job
else if (json["stages"] == null && json["jobs"] == null)
else if (json["stages"] == null & json["jobs"] == null)
{
//Pool
string poolYaml = json["pool"]?.ToString();
Expand Down Expand Up @@ -254,8 +254,8 @@ private List<KeyValuePair<int, string>> ProcessHeaderComments(string gitHubYaml,
//Compare the cleaned up line with the step comments
if (line.IndexOf(stepComment.Replace("#", "")) >= 0)
{
//The zero indexed current line + 1, number of comments, and summary line
int lineNumber = i + 1 + stepComments.Count() + 1;
//The zero indexed current line + 1, number of comments //, and summary line
int lineNumber = i + 1 + stepComments.Count(); // + 1;
stepCommentWithLines.Add(new KeyValuePair<int, string>(lineNumber, stepComment));
currentLine = i + 1;
foundStepComment = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ public static List<string> FindBracketedContentsInString(string text)

private static IEnumerable<string> Nested(string value)
{
//From: https://stackoverflow.com/questions/38479148/separate-nested-parentheses-in-c-sharp
if (string.IsNullOrEmpty(value))
{
yield break; // or throw exception
}
////From: https://stackoverflow.com/questions/38479148/separate-nested-parentheses-in-c-sharp
//if (string.IsNullOrEmpty(value))
//{
// yield break; // or throw exception
//}

Stack<int> brackets = new Stack<int>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static string ConvertMessageToYamlComment(string message)
public static string StepsPreProcessing(string input)
{
//If the step isn't wrapped in a "steps:" node, we need to add this, so we can process the step
if (input.Trim().StartsWith("steps:") == false && input.Trim().Length > 0)
if (input.Trim().StartsWith("steps:") == false & input.Trim().Length > 0)
{
//we need to add steps, before we do, we need to see if the task needs an indent
string[] stepLines = input.Split(System.Environment.NewLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ public StagesProcessing(bool verbose)
//for each stage
foreach (JToken stageJson in stagesJson)
{
AzurePipelines.Stage stage = new AzurePipelines.Stage
AzurePipelines.Stage stage = new AzurePipelines.Stage();
if (stageJson["stage"] != null)
{
stage = stageJson["stage"]?.ToString(),
displayName = stageJson["displayName"]?.ToString(),
condition = stageJson["condition"]?.ToString()
};
stage.stage = stageJson["stage"].ToString();
}
if (stageJson["displayName"] != null)
{
stage.displayName = stageJson["displayName"].ToString();
}
if (stageJson["condition"] != null)
{
stage.condition = stageJson["condition"].ToString();
}
if (stageJson["dependsOn"] != null)
{
GeneralProcessing gp = new GeneralProcessing(_verbose);
Expand Down Expand Up @@ -118,20 +125,17 @@ public StagesProcessing(bool verbose)
}

//Build the final list of GitHub jobs and return it
Dictionary<string, GitHubActions.Job> gitHubJobs = null;
if (jobs != null)
{
Dictionary<string, GitHubActions.Job> gitHubJobs = new Dictionary<string, GitHubActions.Job>();
gitHubJobs = new Dictionary<string, GitHubActions.Job>();
foreach (AzurePipelines.Job job in jobs)
{
JobProcessing jobProcessing = new JobProcessing(_verbose);
gitHubJobs.Add(job.job, jobProcessing.ProcessJob(job, null));
}
return gitHubJobs;
}
else
{
return null;
}
return gitHubJobs;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public GitHubActions.Step ProcessStep(AzurePipelines.Step step)
case "ANT@1":
gitHubStep = CreateAntStep(step);
break;
case "ARCHIVEFILES@1":
case "ARCHIVEFILES@2":
gitHubStep = CreateArchiveFilesStep(step);
break;
Expand Down Expand Up @@ -873,7 +874,7 @@ public GitHubActions.Step CreateCheckoutStep(AzurePipelines.Step step = null)
// submodules: false


if (step.checkout != null && step.checkout != "self")
if (step.checkout != null & step.checkout != "self")
{
gitHubStep.with.Add("repository", step.checkout);
}
Expand Down Expand Up @@ -2337,7 +2338,7 @@ private GitHubActions.Step CreatePublishBuildArtifactsStep(AzurePipelines.Step s
}

//In publish task, I we need to delete any usage of build.artifactstagingdirectory variable as it's implied in github actions, and therefore not needed (Adding it adds the path twice)
if (gitHubStep.with.ContainsKey("path") == true && gitHubStep.with["path"] != null)
if (gitHubStep.with.ContainsKey("path") == true & gitHubStep.with["path"] != null)
{
gitHubStep.with["path"].Replace("$(build.artifactstagingdirectory)", "");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ private Deploy ProcessDeploy(JToken deployJson)
}
if (deployJson["steps"] != null)
{
try
{
deploy.steps = YamlSerialization.DeserializeYaml<AzurePipelines.Step[]>(deployJson["steps"].ToString());
}
catch (Exception ex)
{
ConversionUtility.WriteLine($"DeserializeYaml<AzurePipelines.Step[]>(ProcessDeploy[\"steps\"].ToString() swallowed an exception: " + ex.Message, _verbose);
}
//try
//{
deploy.steps = YamlSerialization.DeserializeYaml<AzurePipelines.Step[]>(deployJson["steps"].ToString());
//}
//catch (Exception ex)
//{
// ConversionUtility.WriteLine($"DeserializeYaml<AzurePipelines.Step[]>(ProcessDeploy[\"steps\"].ToString() swallowed an exception: " + ex.Message, _verbose);
//}
}

return deploy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ public GitHubActions.Trigger ProcessTriggerV2(string triggerYaml)
GitHubActions.Trigger push = ProcessComplexTrigger(trigger);

//Build the return results
return new GitHubActions.Trigger
{
push = push?.push
};
return push;
//return new GitHubActions.Trigger
//{
// push = push?.push
//};

}

Expand Down Expand Up @@ -195,10 +196,10 @@ public GitHubActions.Trigger ProcessPullRequestV2(string pullRequestYaml)
//process the schedule
public string[] ProcessSchedules(AzurePipelines.Schedule[] schedules)
{
if (schedules == null)
{
return null;
}
//if (schedules == null)
//{
// return null;
//}
string[] newSchedules = new string[schedules.Length];
for (int i = 0; i < schedules.Length; i++)
{
Expand All @@ -220,17 +221,15 @@ public GitHubActions.Trigger ProcessSchedulesV2(string schedulesYaml)
string[] schedule = ProcessSchedules(schedules);

//Build the return results
GitHubActions.Trigger newSchedule = null;
if (schedule != null)
{
return new GitHubActions.Trigger
newSchedule = new GitHubActions.Trigger
{
schedule = schedule
};
}
else
{
return null;
}
return newSchedule;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static string StepsPostProcessing(string input)
{
int i = 0;
//Search for the first non empty line
while (string.IsNullOrEmpty(stepLines[i].Trim()) == true || stepLines[i].Trim().StartsWith("steps:") == true)
while (string.IsNullOrEmpty(stepLines[i].Trim()) == true | stepLines[i].Trim().StartsWith("steps:") == true)
{
i++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,8 +1179,8 @@ echo Write your commands here
string expected = @"
#Note: This is a third party action: https://github.com/warrenbuckley/Setup-Nuget
#Note: Azure DevOps strategy>runOnce does not have an equivalent in GitHub Actions yet, and only the deploy steps are transferred to steps
#Error (line 40): the step 'IISWebAppManagementOnMachineGroup@0' does not have a conversion path yet
#Error (line 62): the step 'IISWebAppDeploymentOnMachineGroup@0' does not have a conversion path yet
#Error (line 39): the step 'IISWebAppManagementOnMachineGroup@0' does not have a conversion path yet
#Error (line 61): the step 'IISWebAppDeploymentOnMachineGroup@0' does not have a conversion path yet
on:
push:
branches:
Expand Down Expand Up @@ -1949,11 +1949,11 @@ public void JLPipelineTest()

//Assert
string expected = @"
#Error (line 51): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 54): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 75): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 78): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 242): the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
#Error (line 50): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 53): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 74): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 77): the step 'PublishTestResults@2' does not have a conversion path yet
#Error (line 241): the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
on:
push:
branches:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ public void LineNumberPipelineTest()
//#(line 18) Error: the step 'Gulp@1' does not have a conversion path yet
//#(line 10) Error: the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
string expected = @"
#Error (line 12): the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
#Error (line 20): the step 'Gulp@1' does not have a conversion path yet
#Error (line 24): the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
#Error (line 32): the step 'Gulp@1' does not have a conversion path yet
#Error (line 11): the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
#Error (line 19): the step 'Gulp@1' does not have a conversion path yet
#Error (line 23): the step 'PublishCodeCoverageResults@1' does not have a conversion path yet
#Error (line 31): the step 'Gulp@1' does not have a conversion path yet
jobs:
Test_Stage_Code_Coverage:
name: Publish Code Coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void Docker2BuildStepTest()
command: build
repository: contosoRepository
Dockerfile: app/Dockerfile
arguments: --secret id=mysecret,src=mysecret.txt
";

//Act
Expand All @@ -59,7 +59,7 @@ public void Docker2BuildStepTest()
//Assert
string expected = @"
- name: Build
run: docker build . --file app/Dockerfile contosoRepository
run: docker build . --file app/Dockerfile contosoRepository --secret id=mysecret,src=mysecret.txt
";

expected = UtilityTests.TrimNewLines(expected);
Expand Down

0 comments on commit eedaf2e

Please sign in to comment.