Skip to content

Commit

Permalink
Implemented a GitHub Actions testing pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Feb 11, 2024
1 parent ff82ff4 commit 030bc1d
Show file tree
Hide file tree
Showing 19 changed files with 1,196 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/actions/get-dotnet-channel/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Convert Target Framework to Channel
description: Convert Target Framework to Channel

inputs:
target_framework:
description: 'The target framework to use'
required: true

outputs:
channel:
description: 'The converted Channel variable'
value: ${{ steps.set_channel.outputs.channel }}

runs:
using: "composite"
steps:
- name: Set Channel
id: set_channel
run: |
$channel = '${{inputs.target_framework}}'.Replace('coreapp', '').Replace('net', '');
"channel=$channel" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
shell: pwsh
28 changes: 28 additions & 0 deletions .github/actions/get-program-files/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Get ProgramFiles Path
description: Get ProgramFiles path for the architecture

inputs:
architecture:
description: 'The architecture to use'
required: true

outputs:
path:
description: 'The ProgramFiles path for the architecture'
value: ${{ steps.set-path.outputs.path }}

runs:
using: "composite"
steps:
- name: Set Program Files path for ${{inputs.architecture}}
id: set-path
run: |
if ('${{ inputs.architecture == 'x86'}}' -eq 'true') {
$path = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFilesX86);
"path=$path" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
}
if ('${{ inputs.architecture == 'x64'}}' -eq 'true') {
$path = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFiles);
"path=$path" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
}
shell: pwsh
19 changes: 19 additions & 0 deletions .github/actions/test-build-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test Download Build Cache
description: Download the build cache for the specified operating system and build configuration

inputs:
os:
description: 'The operating system to use'
required: true
build_configuration:
description: 'The build configuration to use'
required: true

runs:
using: "composite"
steps:
- name: Download Build Cache
uses: actions/download-artifact@v4
with:
name: build-output-${{inputs.os}}-${{inputs.build_configuration}}
path: HarmonyTests/bin/
89 changes: 89 additions & 0 deletions .github/actions/test-execute-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Test Execute Test
description: Executes the tests

inputs:
os:
description: 'The operating system to use'
required: true
architecture:
description: 'The architecture to use'
required: true
runtime-type:
description: 'Values: "dotnet", "mono", "fx"'
required: true
target_framework:
description: 'The target framework to use'
required: true
build_configuration:
description: 'The build configuration to use'
required: true
upload_tests:
description: 'Whether to upload the test results'
required: true
experimental:
description: 'Whether the tests are mandatory for the build to pass'
required: true

runs:
using: "composite"
steps:
- name: Set Test Args
id: test-args
run: |
$run_settings_args = 'NUnit.DefaultTestNamePattern="{C}:{m}{a}" RunConfiguration.TargetPlatform=${{inputs.architecture}}'
"run_settings_args=$run_settings_args" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
$vstest = '"HarmonyTests/bin/Release/${{inputs.target_framework}}/HarmonyTests.dll" --framework:${{inputs.target_framework}} --logger:trx --logger:"console;verbosity=normal" --blame';
"vstest=$vstest" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
$dotnet = '"HarmonyTests/bin/Release/${{inputs.target_framework}}/HarmonyTests.dll" -f ${{inputs.target_framework}} -l trx -l "console;verbosity=normal" --blame';
"dotnet=$dotnet" | Out-File -FilePath $env:GITHUB_OUTPUT -Append;
shell: pwsh

- name: Get Program Files path for ${{inputs.architecture}}
uses: ./.github/actions/get-program-files
id: get-program-files
with:
architecture: ${{inputs.architecture}}

- name: Perform Tests Windows Mono
if: ${{inputs.os == 'windows' && inputs.runtime-type == 'mono'}}
run: |
$vspath = vswhere -latest -property installationPath;
$vstest = join-path $vspath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe";
$mono = "${{steps.get-program-files.outputs.path}}/Mono/bin/mono.exe";
& "$mono" "$vstest" ${{steps.test-args.outputs.vstest}} -- ${{steps.test-args.outputs.run_settings_args}};
shell: pwsh

- name: Perform Tests Windows FX
if: ${{inputs.os == 'windows' && inputs.runtime-type == 'fx'}}
run: |
$vspath = vswhere -latest -property installationPath;
$vstest = join-path $vspath "Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe";
& "$vstest" ${{steps.test-args.outputs.vstest}} -- ${{steps.test-args.outputs.run_settings_args}};
shell: pwsh

- name: Perform Tests Windows .NET
if: ${{inputs.os == 'windows' && inputs.runtime-type == 'dotnet'}}
run: |
dotnet test ${{steps.test-args.outputs.dotnet}} -- ${{steps.test-args.outputs.run_settings_args}};
shell: pwsh

- name: Perform Tests Ubuntu/MacOS/MacOS-arm64 .NET/Mono
if: ${{inputs.os == 'ubuntu' || inputs.os == 'macos' || inputs.os == 'macos-arm64'}}
run: |
dotnet test ${{steps.test-args.outputs.dotnet}} -- ${{steps.test-args.outputs.run_settings_args}};
shell: pwsh

- name: Upload Test Result
uses: ./.github/actions/test-upload-result
if: ${{(inputs.upload_tests == 'true') && (always() || failure())}}
with:
os: ${{inputs.os}}
architecture: ${{inputs.architecture}}
runtime-type: ${{inputs.runtime-type}}
target_framework: ${{inputs.target_framework}}
build_configuration: ${{inputs.build_configuration}}
experimental: ${{inputs.experimental == 'true'}}
33 changes: 33 additions & 0 deletions .github/actions/test-setup-dotnet-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Setup .NET Windows
description: Setup .NET for Windows using the provided target framework and architecture

inputs:
architecture:
description: 'The .NET architecture to setup'
required: true
target_framework:
description: 'The .NET target framework to setup'
required: true

runs:
using: "composite"
steps:
- name: Get .NET Channel for ${{inputs.target_framework}}
uses: ./.github/actions/get-dotnet-channel
id: get_channel
with:
target_framework: ${{inputs.target_framework}}

- name: Get Program Files path for ${{inputs.architecture}}
uses: ./.github/actions/get-program-files
id: get-program-files
with:
architecture: ${{inputs.architecture}}

- name: Setup .NET ${{inputs.architecture}}
run: |
Invoke-WebRequest 'https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1;
.\dotnet-install.ps1 -Runtime dotnet -SkipNonVersionedFiles -NoPath -Channel LTS -Architecture ${{inputs.architecture}} -InstallDir "${{steps.get-program-files.outputs.path}}/dotnet";
.\dotnet-install.ps1 -Runtime dotnet -SkipNonVersionedFiles -NoPath -Channel STS -Architecture ${{inputs.architecture}} -InstallDir "${{steps.get-program-files.outputs.path}}/dotnet";
.\dotnet-install.ps1 -Runtime dotnet -SkipNonVersionedFiles -NoPath -Channel ${{steps.get_channel.outputs.channel}} -Architecture ${{inputs.architecture}} -InstallDir "${{steps.get-program-files.outputs.path}}/dotnet";
shell: pwsh
27 changes: 27 additions & 0 deletions .github/actions/test-setup-dotnet/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Setup .NET
description: Setup .NET using the provided target framework and architecture

inputs:
architecture:
description: 'The .NET architecture to setup'
required: true
target_framework:
description: 'The .NET target framework to setup'
required: true

runs:
using: "composite"
steps:
- name: Setup .NET Sdk
uses: actions/setup-dotnet@v4

- name: Get .NET Channel for ${{inputs.target_framework}}
uses: ./.github/actions/get-dotnet-channel
id: get_channel
with:
target_framework: ${{inputs.target_framework}}

- name: Setup .NET ${{steps.get_channel.outputs.channel}}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{steps.get_channel.outputs.channel}}
45 changes: 45 additions & 0 deletions .github/actions/test-setup-mono-windows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Setup Mono Windows
description: Setup Mono for Windows using the latest version

inputs:
architecture:
description: 'The architecture to setup Mono for'
required: true

outputs:
path:
description: 'The Mono path for the architecture'
value: '${{steps.get-program-files.outputs.path}}/Mono/bin/mono.exe'

runs:
using: "composite"
steps:
- name: Setup Mono x86 Manually
if: inputs.architecture == 'x86'
run: |
curl -L https://download.mono-project.com/archive/mono-latest-x86-preview.msi -o mono.msi;
$file = "mono.msi"
$log = "install.log"
$procMain = Start-Process "msiexec" "/i `"$file`" /qn /l*! `"$log`"" -NoNewWindow -PassThru
$procLog = Start-Process "powershell" "Get-Content -Path `"$log`" -Wait" -NoNewWindow -PassThru
$procMain.WaitForExit()
$procLog.Kill()
shell: pwsh

- name: Setup Mono x64 Manually
if: inputs.architecture == 'x64'
run: |
curl -L https://download.mono-project.com/archive/mono-latest-x64-preview.msi -o mono.msi;
$file = "mono.msi"
$log = "install.log"
$procMain = Start-Process "msiexec" "/i `"$file`" /qn /l*! `"$log`"" -NoNewWindow -PassThru
$procLog = Start-Process "powershell" "Get-Content -Path `"$log`" -Wait" -NoNewWindow -PassThru
$procMain.WaitForExit()
$procLog.Kill()
shell: pwsh

- name: Get Program Files path for ${{inputs.architecture}}
uses: ./.github/actions/get-program-files
id: get-program-files
with:
architecture: ${{inputs.architecture}}
34 changes: 34 additions & 0 deletions .github/actions/test-upload-result/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test Upload Result
description: Test Upload Result

inputs:
os:
description: 'The operating system to use'
required: true
architecture:
description: 'The architecture to use'
required: true
runtime-type:
description: 'Values: "dotnet", "mono", "fx"'
required: true
target_framework:
description: 'The target framework to use'
required: true
build_configuration:
description: 'The build configuration to use'
required: true
experimental:
description: 'Whether the tests are mandatory for the build to pass'
required: true
#type: boolean # We don't have boolean types in composites https://github.com/actions/runner/issues/2238

runs:
using: "composite"
steps:
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: ${{success() || failure()}}
with:
name: ${{(inputs.experimental == 'true' && 'experimental-') || ''}}test-results-${{inputs.runtime-type}}-${{inputs.os}}-${{inputs.architecture}}-${{inputs.target_framework}}-${{inputs.build_configuration}}
path: '**/*.trx'
if-no-files-found: ${{(inputs.experimental == 'true' && 'ignore') || 'warn'}}
58 changes: 58 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Template Testing Build
# We build the binaries for all os and configurations
# So we don't have to do that on each test run

on:
workflow_call:
inputs:
os:
required: true
type: string
description: 'The operating system to use'
image:
required: true
type: string
description: 'The image to use'
build_configuration:
required: true
type: string
description: 'The build configuration to use'
publish:
required: true
type: boolean
description: 'Whether to publish the build artifacts'

env:
# Disable the .NET logo in the console output.
DOTNET_NOLOGO: true
# Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending .NET CLI telemetry to Microsoft.
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
build-output-cache:
name: Upload Test Build Output Cache
runs-on: ${{inputs.image}}
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4

- name: Build
run: |
dotnet build -c ${{inputs.build_configuration}} Harmony.sln
- name: Upload Test Build Output Cache
uses: actions/upload-artifact@v4
with:
name: build-output-${{inputs.os}}-${{inputs.build_configuration}}
path: HarmonyTests/bin/**/*

- name: Upload Harmony zip
if: ${{inputs.publish}}
uses: actions/upload-artifact@v4
with:
name: Harmony-${{inputs.build_configuration}}-${{inputs.os}}
path: Harmony/bin/Harmony*.zip
Loading

0 comments on commit 030bc1d

Please sign in to comment.