Skip to content

Commit

Permalink
updates to nuget package testing for samples (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeligia authored Mar 28, 2022
1 parent da6b68e commit dab5f06
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 111 deletions.
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"commands": [
"ilverify"
]
},
"microsoft.coyote.cli": {
"version": "1.5.1",
"commands": [
"coyote"
]
}
}
}
23 changes: 18 additions & 5 deletions .github/workflows/test-coyote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,26 @@ jobs:
with:
dotnet-version: '3.1.x'
- name: Build Coyote projects
run: ./Scripts/build.ps1 -ci $true
run: ./Scripts/build.ps1 -ci
shell: pwsh
- name: Validate Coyote Rewriting
if: ${{ matrix.platform == 'windows-latest' }}
run: ./Tests/compare-rewriting-diff-logs.ps1
shell: pwsh
- name: Run Coyote Tests
run: ./Scripts/run-tests.ps1 -ci $true
run: ./Scripts/run-tests.ps1 -ci
shell: pwsh
- name: Build and test Coyote NuGet packages
if: ${{ matrix.platform == 'windows-latest' }}
run: |
./Scripts/create-nuget-packages.ps1
./Scripts/test-cli-package.ps1
shell: pwsh
- name: Archive Coyote binaries
uses: actions/upload-artifact@v3
with:
name: coyote-binaries
path: ./bin
build-and-test-samples:
name: Build and test Coyote samples
needs: build-and-test
Expand All @@ -73,8 +78,16 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: Build and test Coyote samples
- name: Download Coyote binaries
uses: actions/download-artifact@v3
with:
name: coyote-binaries
path: ./bin
- name: Build Coyote samples
run: |
./Samples/Scripts/build-tests.ps1 -local $true
dotnet ./Samples/Common/bin/net6.0/TestDriver.dll
./Samples/Scripts/build.ps1 -local -nuget
./Samples/Scripts/build-tests.ps1 -local -nuget
shell: pwsh
- name: Test Coyote samples
run: dotnet ./Samples/Common/bin/net6.0/TestDriver.dll
shell: pwsh
17 changes: 13 additions & 4 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="./packages"/>
<add key="repositoryPath" value="./packages"/>
</config>
<packageSources>
<clear/>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
<add key="local" value="./bin/nuget"/>
</packageSources>
<config>
<add key="globalPackagesFolder" value=".\packages"/>
<add key="repositoryPath" value=".\packages"/>
</config>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="local">
<package pattern="Microsoft.Coyote*" />
</packageSource>
</packageSourceMapping>
</configuration>
5 changes: 4 additions & 1 deletion Samples/Common/TestDriver/TestDriver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
<!-- <ProjectReference Include="..\..\WebApps\ImageGalleryAspNet\Tests\Tests.csproj" /> -->
<ProjectReference Include="..\..\WebApps\PetImagesAspNet\PetImages.Tests\PetImages.Tests.csproj" />
</ItemGroup>
<Target Name="CoyoteRewriteNuget" Condition="'$(UseLocalCoyote)'=='false'" AfterTargets="AfterBuild" >
<Target Name="CoyoteRewriteNuget" Condition="'$(UseNugetPackages)'=='true'" AfterTargets="AfterBuild" >
<Exec Command="coyote rewrite rewrite.coyote.json" />
</Target>
<Target Name="CoyoteRewriteLocalNuget" Condition="'$(UseLocalNugetPackages)'=='true'" AfterTargets="AfterBuild" >
<Exec Command="dotnet coyote rewrite rewrite.coyote.json" />
</Target>
<Target Name="CoyoteRewriteLocal" Condition="'$(UseLocalCoyote)'=='true'" AfterTargets="AfterBuild" >
<Exec Command="dotnet ../../../bin/$(TargetFramework)/coyote.dll rewrite rewrite.coyote.json" />
</Target>
Expand Down
3 changes: 3 additions & 0 deletions Samples/Common/build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<LangVersion>10.0</LangVersion>
<TargetFrameworks>net6.0</TargetFrameworks>
<UseLocalCoyote>False</UseLocalCoyote>
<UseLocalNugetPackages>False</UseLocalNugetPackages>
<UseNugetPackages>True</UseNugetPackages>
<UseNugetPackages Condition="'$(UseLocalNugetPackages)'=='yes'">False</UseNugetPackages>
<CodeAnalysisRuleSetLocation>$(MSBuildThisFileDirectory)</CodeAnalysisRuleSetLocation>
<CodeAnalysisRuleSet>$(CodeAnalysisRuleSetLocation)\codeanalysis.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
Expand Down
17 changes: 17 additions & 0 deletions Samples/NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="..\packages"/>
<add key="repositoryPath" value="..\packages"/>
</config>
<packageSources>
<clear/>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
</packageSources>
<packageSourceMapping>
<clear/>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
16 changes: 11 additions & 5 deletions Samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ You can find the compiled binaries in the `bin` directory. You can use the `coyo
automatically test these samples and find bugs. First, read how to use the tool
[here](../get-started/using-coyote.md). Then, follow the instructions in each sample.

## Using the local Coyote binaries
## Using the local Coyote packages

By default, the samples use the published `Microsoft.Coyote` [NuGet
package](https://www.nuget.org/packages/Microsoft.Coyote/). If you want to use the locally built
Coyote binaries instead, then run the following script in `powershell`:
package](https://www.nuget.org/packages/Microsoft.Coyote/).

If you want instead to use the locally built Coyote binaries, then run the following script in
`powershell`:
```
./Samples/Scripts/build.ps1 -local $true
./Samples/Scripts/build.ps1 -local
```

Note: this can make debugging into the Coyote runtime possible.
Finally, if you want instead to use the locally built Coyote NuGet packages, then run the following
script in `powershell`:
```
./Samples/Scripts/build.ps1 -local -nuget
```
14 changes: 10 additions & 4 deletions Samples/Scripts/build-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ param(
[string]$dotnet="dotnet",
[ValidateSet("Debug","Release")]
[string]$configuration="Release",
[bool]$local = $false
[switch]$local,
[switch]$nuget
)

Import-Module $PSScriptRoot\..\..\Scripts\powershell\common.psm1 -Force
Import-Module $PSScriptRoot/../../Scripts/common.psm1 -Force

Write-Comment -prefix "." -text "Building the Coyote samples" -color "yellow"

if ($local.IsPresent -and $nuget.IsPresent) {
# Restore the local coyote tool.
&dotnet tool restore
}

# Check that the expected .NET SDK is installed.
$dotnet = "dotnet"
$dotnet_sdk_path = FindDotNetSdkPath -dotnet $dotnet
Expand All @@ -21,7 +27,7 @@ if ($null -eq $sdk_version) {
}

# Build the tests for the samples.
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\Common\TestDriver\TestDriver.csproj" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../Common/TestDriver/TestDriver.csproj" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent

Write-Comment -prefix "." -text "Successfully built the Coyote samples" -color "green"
54 changes: 30 additions & 24 deletions Samples/Scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ param(
[string]$dotnet="dotnet",
[ValidateSet("Debug","Release")]
[string]$configuration="Release",
[bool]$local = $false
[switch]$local,
[switch]$nuget
)

Import-Module $PSScriptRoot\..\..\Scripts\powershell\common.psm1 -Force
Import-Module $PSScriptRoot/../../Scripts/common.psm1 -Force

Write-Comment -prefix "." -text "Building the Coyote samples" -color "yellow"

if ($local.IsPresent -and $nuget.IsPresent) {
# Restore the local coyote tool.
&dotnet tool restore
}

# Check that the expected .NET SDK is installed.
$dotnet = "dotnet"
$dotnet_sdk_path = FindDotNetSdkPath -dotnet $dotnet
Expand All @@ -21,31 +27,31 @@ if ($null -eq $sdk_version) {
}

# Build the task-based samples.
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\AccountManager\AccountManager.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\BoundedBuffer\BoundedBuffer.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\CoffeeMachineTasks\CoffeeMachineTasks.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../AccountManager/AccountManager.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../BoundedBuffer/BoundedBuffer.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../CoffeeMachineTasks/CoffeeMachineTasks.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent

# Build the actor samples.
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\HelloWorldActors\HelloWorldActors.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\CoffeeMachineActors\CoffeeMachineActors.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\DrinksServingRobotActors\DrinksServingRobotActors.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\CloudMessaging\CloudMessaging.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\Timers\Timers.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\Monitors\Monitors.sln" `
-config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../HelloWorldActors/HelloWorldActors.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../CoffeeMachineActors/CoffeeMachineActors.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../DrinksServingRobotActors/DrinksServingRobotActors.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../CloudMessaging/CloudMessaging.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../Timers/Timers.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../Monitors/Monitors.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent

# Build the web app samples.
# Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\WebApps\ImageGalleryAspNet\ImageGallery.sln" `
# -config $configuration -local $local
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot\..\WebApps\PetImagesAspNet\PetImages.sln" `
-config $configuration -local $local
# Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../WebApps/ImageGalleryAspNet/ImageGallery.sln" `
# -config $configuration -local $local.IsPresent -nuget $nuget.IsPresent
Invoke-DotnetBuild -dotnet $dotnet -solution "$PSScriptRoot/../WebApps/PetImagesAspNet/PetImages.sln" `
-config $configuration -local $local.IsPresent -nuget $nuget.IsPresent

Write-Comment -prefix "." -text "Successfully built the Coyote samples" -color "green"
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
</ItemGroup>
<Target Name="CoyoteRewriteNuget" Condition="'$(UseLocalCoyote)'=='false'" AfterTargets="AfterBuild" >
<Target Name="CoyoteRewriteNuget" Condition="'$(UseNugetPackages)'=='true'" AfterTargets="AfterBuild" >
<Exec Command="coyote rewrite rewrite.coyote.json" />
</Target>
<Target Name="CoyoteRewriteLocalNuget" Condition="'$(UseLocalNugetPackages)'=='true'" AfterTargets="AfterBuild" >
<Exec Command="dotnet coyote rewrite rewrite.coyote.json" />
</Target>
<Target Name="CoyoteRewriteLocal" Condition="'$(UseLocalCoyote)'=='true'" AfterTargets="AfterBuild" >
<Exec Command="dotnet ../../../../bin/$(TargetFramework)/coyote.dll rewrite rewrite.coyote.json" />
</Target>
Expand Down
2 changes: 1 addition & 1 deletion Scripts/CI/azure-nuget-sign-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ steps:
inputs:
targetType: filePath
filePath: '.\Scripts\build.ps1'
arguments: "-ci $true"
arguments: "-ci"
failOnStderr: true
pwsh: true

Expand Down
8 changes: 4 additions & 4 deletions Scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
param(
[ValidateSet("Debug", "Release")]
[string]$configuration = "Release",
[bool]$ci = $false
[switch]$ci
)

$ScriptDir = $PSScriptRoot

Import-Module $ScriptDir/powershell/common.psm1 -Force
Import-Module $ScriptDir/common.psm1 -Force

Write-Comment -prefix "." -text "Building Coyote" -color "yellow"

Expand All @@ -34,10 +34,10 @@ if ($null -eq $sdk_version) {
}

Write-Comment -prefix "..." -text "Using configuration '$configuration'"
$solution = Join-Path -Path $ScriptDir -ChildPath "\.." -AdditionalChildPath "Coyote.sln"
$solution = Join-Path -Path $ScriptDir -ChildPath ".." -AdditionalChildPath "Coyote.sln"
$command = "build -c $configuration $solution /p:Platform=""Any CPU"""

if ($ci) {
if ($ci.IsPresent) {
# Build any supported .NET versions that are installed on this machine.
if ($version_net4) {
# Build .NET Framework 4.x as well as the latest version.
Expand Down
32 changes: 14 additions & 18 deletions Scripts/powershell/common.psm1 → Scripts/common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ function Invoke-CoyoteTool([String]$cmd, [String]$dotnet, [String]$framework, [S
}

# Builds the specified .NET project
function Invoke-DotnetBuild([String]$dotnet, [String]$solution, [String]$config, [bool]$local) {
function Invoke-DotnetBuild([String]$dotnet, [String]$solution, [String]$config, [bool]$local, [bool]$nuget) {
Write-Comment -prefix "..." -text "Building $solution"

$command = "build -c $config $solution"
if ($local) {
$command = "$command /p:UseLocalCoyote=true"
$nuget_config_file = "$PSScriptRoot/../NuGet.config"
$restore_command = "restore $solution"
$build_command = "build -c $config $solution --no-restore"
if ($local -and $nuget) {
$restore_command = "$restore_command --configfile $nuget_config_file"
$build_command = "$build_command /p:UseLocalNugetPackages=true "
} elseif ($local) {
$restore_command = "$restore_command --configfile $nuget_config_file"
$build_command = "$build_command /p:UseLocalCoyote=true"
}

$error_msg = "Failed to build $solution"
Invoke-ToolCommand -tool $dotnet -cmd $command -error_msg $error_msg
Invoke-ToolCommand -tool $dotnet -cmd $restore_command -error_msg "Failed to restore $solution"
Invoke-ToolCommand -tool $dotnet -cmd $build_command -error_msg "Failed to build $solution"
}

# Runs the specified .NET test using the specified framework.
Expand Down Expand Up @@ -71,16 +77,6 @@ function Invoke-ToolCommand([String]$tool, [String]$cmd, [String]$error_msg) {
}
}

function TraverseLink($path) {
$item = Get-Item $path
if ($item.LinkType -eq "SymbolicLink") {
$target = $item.Target
Write-Host "Traversing link $target"
return TraverseLink($target)
}
return $path
}

function FindProgram([String]$name) {
$result = $null
$path = $ENV:PATH.split([System.IO.Path]::PathSeparator) | ForEach-Object {
Expand Down Expand Up @@ -137,7 +133,7 @@ function FindDotNetRuntimePath([String]$dotnet, [String]$runtime) {

# Finds the dotnet SDK version.
function FindDotNetSdkVersion([String]$dotnet_sdk_path) {
$globalJson = Join-Path -Path $PSScriptRoot -ChildPath ".." -AdditionalChildPath @("..", "global.json")
$globalJson = Join-Path -Path $PSScriptRoot -ChildPath ".." -AdditionalChildPath @("global.json")
$json = Get-Content $globalJson | Out-String | ConvertFrom-Json
$global_version = $json.sdk.version
Write-Comment -prefix "..." -text "Searching for .NET SDK version '$global_version' in '$dotnet_sdk_path'"
Expand All @@ -153,7 +149,7 @@ function FindDotNetSdkVersion([String]$dotnet_sdk_path) {

# Finds the dotnet runtime version.
function FindDotNetRuntimeVersion([String]$dotnet_runtime_path) {
$globalJson = Join-Path -Path $PSScriptRoot -ChildPath ".." -AdditionalChildPath @("..", "global.json")
$globalJson = Join-Path -Path $PSScriptRoot -ChildPath ".." -AdditionalChildPath @("global.json")
$json = Get-Content $globalJson | Out-String | ConvertFrom-Json
$global_version = $json.sdk.version
return FindMatchingVersion -path $dotnet_runtime_path -version $global_version
Expand Down
Loading

0 comments on commit dab5f06

Please sign in to comment.