Skip to content

Commit

Permalink
Add integration tests for running with Cake.Git
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Dec 18, 2024
1 parent d72ccdd commit da042b5
Show file tree
Hide file tree
Showing 93 changed files with 1,928 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ build_script:

# Tests
test_script:
- ps: cd .\tests\script-runner\net8.0\
- ps: cd .\tests\script-runner\net8.0-git-cli\
- ps: .\build.ps1 --verbosity=diagnostic

#---------------------------------#
Expand Down
45 changes: 25 additions & 20 deletions .azuredevops/pipelines/templates/jobs/test-frosting.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
parameters:
- name: vmImage
type: string
- name: dotNetVersion
type: string
- name: images
type: object
- name: dotNetVersions
type: object
- name: repositoryInfoProviders
type: object

jobs:
- job: Test_Frosting_${{ replace(replace(parameters.vmImage,'-','_'),'.','_') }}_Net${{ parameters.dotNetVersion }}
displayName: Integration Tests Frosting ${{ parameters.vmImage }} (.NET ${{ parameters.dotNetVersion }})
dependsOn: Build
pool:
vmImage: '${{ parameters.vmImage }}'
steps:
- template: ../steps/prepare-test.yml
parameters:
dotNetVersion: ${{ parameters.dotNetVersion }}
- bash: |
./build.sh --verbosity=diagnostic
workingDirectory: ./tests/frosting/net${{ parameters.dotNetVersion }}.0
displayName: 'Run integration tests'
- publish: $(Build.SourcesDirectory)/tests/frosting/net${{ parameters.dotNetVersion }}.0/build/BuildArtifacts/output
artifact: Integration Tests Frosting ${{ parameters.vmImage }} (.NET ${{ parameters.dotNetVersion }})
displayName: 'Publish generated reports as build artifact'
- ${{ each image in parameters.images }}:
- ${{ each dotnetVersion in parameters.dotNetVersions }}:
- ${{ each repositoryInfoProvider in parameters.repositoryInfoProviders }}:
- job: Test_Frosting_${{ replace(replace(image,'-','_'),'.','_') }}_Net${{ dotNetVersion }}_${{ replace(repositoryInfoProvider,'-','_') }}
displayName: Integration Tests Frosting ${{ image }} (.NET ${{ dotNetVersion }} / ${{ repositoryInfoProvider }})
dependsOn: Build
pool:
vmImage: '${{ image }}'
steps:
- template: ../steps/prepare-test.yml
parameters:
dotNetVersion: ${{ dotNetVersion }}
- bash: |
./build.sh --verbosity=diagnostic
workingDirectory: ./tests/frosting/net${{ dotNetVersion }}.0-${{ repositoryInfoProvider }}
displayName: 'Run integration tests'
- publish: $(Build.SourcesDirectory)/tests/frosting/net${{ dotNetVersion }}.0-${{ repositoryInfoProvider }}/build/BuildArtifacts/output
artifact: Integration Tests Frosting ${{ image }} (.NET ${{ dotNetVersion }} + ${{ repositoryInfoProvider }})
displayName: 'Publish generated reports as build artifact'
45 changes: 25 additions & 20 deletions .azuredevops/pipelines/templates/jobs/test-scripting.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
parameters:
- name: vmImage
type: string
- name: dotNetVersion
type: string
- name: images
type: object
- name: dotNetVersions
type: object
- name: repositoryInfoProviders
type: object

jobs:
- job: Test_Script_Runner_${{ replace(replace(parameters.vmImage,'-','_'),'.','_') }}_Net${{ parameters.dotNetVersion }}
displayName: Integration Tests Script Runner ${{ parameters.vmImage }} (.NET ${{ parameters.dotNetVersion }})
dependsOn: Build
pool:
vmImage: '${{ parameters.vmImage }}'
steps:
- template: ../steps/prepare-test.yml
parameters:
dotNetVersion: ${{ parameters.dotNetVersion }}
- bash: |
./build.sh --verbosity=diagnostic
workingDirectory: ./tests/script-runner/net${{ parameters.dotNetVersion }}.0
displayName: 'Run integration tests'
- publish: $(Build.SourcesDirectory)/tests/script-runner/net${{ parameters.dotNetVersion }}.0/BuildArtifacts/output
artifact: Integration Tests Script Runner ${{ parameters.vmImage }} (.NET ${{ parameters.dotNetVersion }})
displayName: 'Publish generated reports as build artifact'
- ${{ each image in parameters.images }}:
- ${{ each dotnetVersion in parameters.dotNetVersions }}:
- ${{ each repositoryInfoProvider in parameters.repositoryInfoProviders }}:
- job: Test_Script_Runner_${{ replace(replace(image,'-','_'),'.','_') }}_Net${{ dotNetVersion }}_${{ replace(repositoryInfoProvider,'-','_') }}
displayName: Integration Tests Script Runner ${{ image }} (.NET ${{ dotNetVersion }} / ${{ repositoryInfoProvider }})
dependsOn: Build
pool:
vmImage: '${{ image }}'
steps:
- template: ../steps/prepare-test.yml
parameters:
dotNetVersion: ${{ dotNetVersion }}
- bash: |
./build.sh --verbosity=diagnostic
workingDirectory: ./tests/script-runner/net${{ dotNetVersion }}.0-${{ repositoryInfoProvider }}
displayName: 'Run integration tests'
- publish: $(Build.SourcesDirectory)/tests/script-runner/net${{ dotNetVersion }}.0-${{ repositoryInfoProvider }}/BuildArtifacts/output
artifact: Integration Tests Script Runner ${{ image }} (.NET ${{ dotNetVersion }} + ${{ repositoryInfoProvider }})
displayName: 'Publish generated reports as build artifact'
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
8.x
- name: Run integration tests
run: ./build.ps1 --verbosity=diagnostic
working-directory: ./tests/script-runner/net8.0/
working-directory: ./tests/script-runner/net8.0-git-cli/
shell: powershell
- name: Publish generated reports as build artifact
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4
Expand Down
64 changes: 8 additions & 56 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,15 @@ jobs:
- publish: $(Build.SourcesDirectory)/BuildArtifacts/Packages/NuGet
artifact: NuGet Package
displayName: 'Publish NuGet package as build artifact'
# Integration Tests Frosting Windows 2019 (.NET 8)
# Integration Tests Frosting
- template: .azuredevops/pipelines/templates/jobs/test-frosting.yml
parameters:
vmImage: 'windows-2019'
dotNetVersion: 8
# Integration Tests Frosting Windows 2019 (.NET 9)
- template: .azuredevops/pipelines/templates/jobs/test-frosting.yml
parameters:
vmImage: 'windows-2022'
dotNetVersion: 9
# Integration Tests Script Runner Windows 2019 (.NET 8)
- template: .azuredevops/pipelines/templates/jobs/test-scripting.yml
parameters:
vmImage: 'windows-2019'
dotNetVersion: 8
# Integration Tests Script Runner Windows 2022 (.NET 9)
- template: .azuredevops/pipelines/templates/jobs/test-scripting.yml
parameters:
vmImage: 'windows-2022'
dotNetVersion: 9
# Integration Tests Frosting macOS 13 (.NET 8)
- template: .azuredevops/pipelines/templates/jobs/test-frosting.yml
parameters:
vmImage: 'macOS-13'
dotNetVersion: 8
# Integration Tests Frosting macOS 14 (.NET 9)
- template: .azuredevops/pipelines/templates/jobs/test-frosting.yml
parameters:
vmImage: 'macOS-14'
dotNetVersion: 9
# Integration Tests Script Runner macOS 13 (.NET 8)
- template: .azuredevops/pipelines/templates/jobs/test-scripting.yml
parameters:
vmImage: 'macOS-13'
dotNetVersion: 8
# Integration Tests Script Runner macOS 14 (.NET 9)
- template: .azuredevops/pipelines/templates/jobs/test-scripting.yml
parameters:
vmImage: 'macOS-14'
dotNetVersion: 9
# Integration Tests Frosting Ubuntu 22.04 (.NET 8)
- template: .azuredevops/pipelines/templates/jobs/test-frosting.yml
parameters:
vmImage: 'ubuntu-22.04'
dotNetVersion: 8
# Integration Tests Frosting Ubuntu 24.04 (.NET 9)
- template: .azuredevops/pipelines/templates/jobs/test-frosting.yml
parameters:
vmImage: 'ubuntu-24.04'
dotNetVersion: 9
# Integration Tests Script Runner Ubuntu 22.04 (.NET tool)
- template: .azuredevops/pipelines/templates/jobs/test-scripting.yml
parameters:
vmImage: 'ubuntu-22.04'
dotNetVersion: 8
# Integration Tests Script Runner Ubuntu 24.04 (.NET tool)
images: [ 'windows-2019', 'windows-2022', 'macOS-13', 'macOS-14', 'ubuntu-22.04', 'ubuntu-24.04' ]
dotNetVersions: [ 8, 9 ]
repositoryInfoProviders: [ 'git-cli', 'cake-git' ]
# Integration Tests Script Runner
- template: .azuredevops/pipelines/templates/jobs/test-scripting.yml
parameters:
vmImage: 'ubuntu-24.04'
dotNetVersion: 9
images: [ 'windows-2019', 'windows-2022', 'macOS-13', 'macOS-14', 'ubuntu-22.04', 'ubuntu-24.04' ]
dotNetVersions: [ 8, 9 ]
repositoryInfoProviders: [ 'git-cli', 'cake-git' ]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
124 changes: 124 additions & 0 deletions tests/frosting/net8.0-cake-git/build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Reflection;
using Cake.Common;
using Cake.Common.Diagnostics;
using Cake.Common.Tools.InspectCode;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Frosting;

public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.UseLifetime<Lifetime>()
.InstallTool(new Uri("nuget:?package=JetBrains.ReSharper.CommandLineTools&version=2023.3.4"))
// Register Cake.Frosting.Issues.Recipe tasks.
.AddAssembly(Assembly.GetAssembly(typeof(IssuesTask)))
.Run(args);
}
}

public class BuildContext : IssuesContext<BuildParameters, BuildState>
{
public BuildContext(ICakeContext context)
: base(context)
{
}

protected override BuildParameters CreateIssuesParameters()
{
return new BuildParameters();
}

protected override BuildState CreateIssuesState()
{
return new BuildState(this);
}
}

public class BuildParameters : IssuesParameters
{
public DirectoryPath LogDirectoryPath => this.OutputDirectory.Combine("logs");

public BuildParameters()
{
this.OutputDirectory = this.OutputDirectory.Combine("output");
}
}

public class BuildState : IssuesState
{
public FilePath SolutionFilePath { get; }

public BuildState(BuildContext context)
: base(context, RepositoryInfoProviderType.CakeGit)
{
this.SolutionFilePath =
this.ProjectRootDirectory
.Combine("src")
.CombineWithFilePath("ClassLibrary1.sln");
}
}

public class Lifetime : FrostingLifetime<BuildContext>
{
public override void Setup(BuildContext context, ISetupContext info)
{
// Determine Build Identifier
var platform = context.Environment.Platform.Family.ToString();
var runtime = context.Environment.Runtime.IsCoreClr ? ".NET Core" : ".NET Framework";

context.Parameters.BuildIdentifier = $"Cake Frosting {platform} ({runtime})";

context.Information("Build identifier: {0}", context.Parameters.BuildIdentifier);
}

public override void Teardown(BuildContext context, ITeardownContext info)
{
}
}

[TaskName("Run-InspectCode")]
public sealed class RunInspectCodeTask : FrostingTask<BuildContext>
{
public override bool ShouldRun(BuildContext context)
{
return context.IsRunningOnWindows();
}

public override void Run(BuildContext context)
{
// Run InspectCode.
var inspectCodeLogFilePath = context.Parameters.LogDirectoryPath.CombineWithFilePath("inspectCode.log");

var settings = new InspectCodeSettings() {
OutputFile = inspectCodeLogFilePath,
ArgumentCustomization = x => x.Append("--no-build"),
WorkingDirectory = context.State.ProjectRootDirectory
};

context.InspectCode(
context.State.SolutionFilePath,
settings);

// Pass path to InspectCode log file to Cake.Frosting.Issues.Recipe.
context.Parameters.InputFiles.AddInspectCodeLogFilePath(inspectCodeLogFilePath);
}
}

[TaskName("Lint")]
[IsDependentOn(typeof(RunInspectCodeTask))]
[IsDependeeOf(typeof(ReadIssuesTask))]
public class LintTask : FrostingTask
{
}

[TaskName("Default")]
[IsDependentOn(typeof(IssuesTask))]
public class DefaultTask : FrostingTask
{
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions tests/frosting/net8.0-git-cli/build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="5.0.0" />
<PackageReference Include="Cake.Frosting.Issues.Recipe" Version="*-*" />
</ItemGroup>
</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions tests/frosting/net9.0-cake-git/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$RECIPE_PACKAGE_PATH = "packages/cake.frosting.issues.recipe"
if (Test-Path $RECIPE_PACKAGE_PATH)
{
Write-Host "Cleaning up cached version of $RECIPE_PACKAGE_PATH..."
Remove-Item $RECIPE_PACKAGE_PATH -Recurse;
}
else
{
Write-Host "$RECIPE_PACKAGE_PATH not cached..."
}

dotnet run --project build/Build.csproj -- $args
exit $LASTEXITCODE;
11 changes: 11 additions & 0 deletions tests/frosting/net9.0-cake-git/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

$RECIPE_PACKAGE_PATH = "packages/cake.frosting.issues.recipe"
if [ -d "$RECIPE_PACKAGE_PATH" ]
then
echo "Cleaning up cached version of $RECIPE_PACKAGE_PATH..."
rm -Rf $RECIPE_PACKAGE_PATH
else
echo "$RECIPE_PACKAGE_PATH not cached..."
fi

dotnet run --project ./build/Build.csproj -- "$@"
2 changes: 2 additions & 0 deletions tests/frosting/net9.0-cake-git/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Cake ###
tools/*
File renamed without changes.
Loading

0 comments on commit da042b5

Please sign in to comment.