Skip to content

Commit

Permalink
Add tests (#30)
Browse files Browse the repository at this point in the history
* check for viability

* attempt 2

* make directory exist

silly git

* checkout

* add simple test

* im becoming jokerfied

* correct artifact creation

* Add tests using a legacy-style csproj based on RPM

* nuget needs a sln file to not freak out

🙄

* I cannot type

* fix "repo" root

* always get that one wrong

* fix for real

* Unify CI workflow

* delete nuget workflow
  • Loading branch information
drewcassidy committed Sep 5, 2024
1 parent 32a9d13 commit eafb4d6
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 18 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/nuget.yml → .github/workflows/internal-ci.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
name: Build for NuGet
# This is an internal workflow for KSPBuildTools and not intended to be used by other projects

name: CI

on:
push:
tags:
- '*.*.*'
branches:
- 'main'
paths:
- '**/*.csproj'
- '**/*.props'
- '**/*.targets'
- '.github/workflows/nuget.yml'
- 'main'
pull_request:
paths:
- '**/*.csproj'
- '**/*.props'
- '**/*.targets'
- '.github/workflows/nuget.yml'
workflow_dispatch:

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget

jobs:
test-plugin:
uses: './.github/workflows/internal-test-plugin.yml'

test-plugin-legacy:
uses: './.github/workflows/internal-test-plugin-legacy.yml'

build:
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
runs-on: ubuntu-latest
needs: [ test-plugin, test-plugin-legacy ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # get full history, not shallow clone

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Build
run: dotnet build KSPBuildTools.csproj

Expand All @@ -55,7 +55,7 @@ jobs:
environment:
name: "NuGet"
url: "https://www.nuget.org/packages/KSPBuildTools"
if: github.event_name == 'push'
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
Expand All @@ -80,4 +80,4 @@ jobs:
- name: Publish Package to Github
run: |
dotnet nuget push --source "github" ${{ env.NuGetDirectory }}/*.nupkg
dotnet nuget push --source "github" ${{ env.NuGetDirectory }}/*.nupkg
26 changes: 26 additions & 0 deletions .github/workflows/internal-test-plugin-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This is an internal test for KSPBuildTools and not intended to be used by other projects
name: Test Plugin Mod (Legacy)

on:
workflow_call:

env:
TESTDIR: tests/plugin-mod-legacy

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-ckan

- uses: ./.github/actions/compile
with:
solution-file-path: ${{ env.TESTDIR }}/PluginModLegacy.sln
ksp-zip-url: https://github.com/KSPModdingLibs/KSPLibs/raw/main/KSP-1.12.5.zip

- uses: ./.github/actions/assemble-release
with:
artifacts: ${{ env.TESTDIR }}/GameData
output-file-name: plugin-mod-legacy
26 changes: 26 additions & 0 deletions .github/workflows/internal-test-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This is an internal test for KSPBuildTools and not intended to be used by other projects
name: Test Plugin Mod

on:
workflow_call:

env:
TESTDIR: tests/plugin-mod

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/setup-ckan

- uses: ./.github/actions/compile
with:
solution-file-path: ${{ env.TESTDIR }}/plugin-mod.csproj
ksp-zip-url: https://github.com/KSPModdingLibs/KSPLibs/raw/main/KSP-1.12.5.zip

- uses: ./.github/actions/assemble-release
with:
artifacts: ${{ env.TESTDIR }}/GameData
output-file-name: plugin-mod
5 changes: 5 additions & 0 deletions KSPBuildTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@
<None Include="KSPCommon.targets" Pack="True" PackagePath="build/KSPBuildTools.targets" />
<None Include="README.md" Pack="True" PackagePath="/"/>
</ItemGroup>

<ItemGroup>
<Compile Remove="$(MSBuildThisFileDirectory)tests/**" />
<None Remove="$(MSBuildThisFileDirectory)tests/**" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions tests/plugin-mod-legacy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packages
obj
bin
GameData
22 changes: 22 additions & 0 deletions tests/plugin-mod-legacy/PluginModLegacy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "plugin-mod-legacy", "PluginModLegacy\plugin-mod-legacy.csproj", "{F19C7AB4-50C2-4378-9673-CC039CA12E10}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F19C7AB4-50C2-4378-9673-CC039CA12E10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F19C7AB4-50C2-4378-9673-CC039CA12E10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F19C7AB4-50C2-4378-9673-CC039CA12E10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F19C7AB4-50C2-4378-9673-CC039CA12E10}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions tests/plugin-mod-legacy/PluginModLegacy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("PluginModLegacy")]
[assembly: AssemblyDescription ("Test mod using a legacy csproj")]

// This supposedly helps avoid plugin depencency problems.
[assembly: KSPAssembly("plugin-mod-legacy", 1, 2, 3)]
4 changes: 4 additions & 0 deletions tests/plugin-mod-legacy/PluginModLegacy/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Krafs.Publicizer" version="1.0.3" targetFramework="net48" developmentDependency="true" />
</packages>
77 changes: 77 additions & 0 deletions tests/plugin-mod-legacy/PluginModLegacy/plugin-mod-legacy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.props" Condition="Exists('$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F19C7AB4-50C2-4378-9673-CC039CA12E10}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>JSI</RootNamespace>
<AssemblyName>PluginModMono</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<CodePage>65001</CodePage>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Profile|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Profile\</OutputPath>
<DefineConstants>ENABLE_PROFILER</DefineConstants>
<Optimize>true</Optimize>
<DebugType>portable</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<RepoRootPath>$(MSBuildThisFileDirectory)../</RepoRootPath>
<BinariesOutputRelativePath>GameData/plugin-mod-legacy</BinariesOutputRelativePath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)/$(MSBuildToolsVersion)\Microsoft.Common.props" />
<Import Project="$(MSBuildThisFileDirectory)../../../KSPCommon.targets" />
<Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />
<ItemGroup>
<Compile Include="Properties/AssemblyInfo.cs"/>
</ItemGroup>
<ItemGroup>
<Publicize Include="Assembly-CSharp" />
</ItemGroup>
<Target Name="MakeModDir" BeforeTargets="BeforeBuild">
<MakeDir Directories="$(RepoRootPath)GameData/plugin-mod-legacy" />
</Target>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.props')" Text="$([System.String]::Format('$(ErrorText)', '$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.props'))" />
<Error Condition="!Exists('$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.targets'))" />
</Target>
<Import Project="$(MSBuildThisFileDirectory)../packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.targets" Condition="Exists('$(MSBuildThisFileDirectory)packages/Krafs.Publicizer.1.0.3/build/Krafs.Publicizer.targets')" />
</Project>
3 changes: 3 additions & 0 deletions tests/plugin-mod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
obj
bin
GameData
51 changes: 51 additions & 0 deletions tests/plugin-mod/plugin-mod.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="MinVer" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Static Properties -->
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<LangVersion>7.3</LangVersion>
<IsPackable>false</IsPackable>
<PlatformTarget>x64</PlatformTarget>
<NoWarn>1701;1702;CS0649;CS1591;</NoWarn>
<AssemblyCopyright>2024 KSPModdingLibs Contributors</AssemblyCopyright>
<AssemblyName>PluginMod</AssemblyName>
<RepoRootPath>$(MSBuildThisFileDirectory)</RepoRootPath>
<BinariesOutputRelativePath>GameData/plugin-mod</BinariesOutputRelativePath>
</PropertyGroup>

<!-- DLL Dependencies-->
<ItemGroup>
<Reference Include="0Harmony, Culture=neutral, PublicKeyToken=null">
<HintPath>$(KSPRoot)/GameData/000_Harmony/0Harmony.dll</HintPath>
<CKANIdentifier>Harmony2</CKANIdentifier>
<CKANVersion>2.2.1.0</CKANVersion>
<Private>False</Private>
</Reference>
</ItemGroup>

<!-- Version Files -->
<ItemGroup>
<KSPVersionFile Include=".">
<Destination>$(RepoRootPath)$(BinariesOutputRelativePath)/plugin-mod.version</Destination>
</KSPVersionFile>
</ItemGroup>

<PropertyGroup>
<GenerateKSPAssemblyAttribute>true</GenerateKSPAssemblyAttribute>
<GenerateKSPAssemblyDependencyAttributes>true</GenerateKSPAssemblyDependencyAttributes>
</PropertyGroup>

<Target Name="MakeModDir" BeforeTargets="BeforeBuild">
<MakeDir Directories="$(RepoRootPath)GameData/plugin-mod" />
</Target>

<Import Project="$(MSBuildThisFileDirectory)../../KSPCommon.targets" />
</Project>

0 comments on commit eafb4d6

Please sign in to comment.