Skip to content

Commit

Permalink
Create build.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoco007 committed Jan 25, 2021
1 parent c79ba47 commit ad97e14
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 25 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: build

on:
push:
branches:
- main
- develop
- actions
tags:
- '*'
pull_request:

jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up .NET Core
uses: actions/setup-dotnet@v1.7.2
with:
dotnet-version: 3.1.x

- name: Prepare Environment
run: .\prepare_environment.ps1 "Source\SmallMenu\manifest.json"

- name: Fetch Beat Saber Bindings
run: git clone https://nicoco007:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/nicoco007/BeatSaberBindings "BeatSaberBindings\Beat Saber_Data\Managed"

- name: Restore NuGet Packages
run: dotnet restore Source\SmallMenu\SmallMenu.csproj

- name: Build Debug
run: dotnet build --no-restore Source\SmallMenu\SmallMenu.csproj -c Debug -p:BeatSaberDir=..\..\BeatSaberBindings

- name: Upload Debug
uses: actions/upload-artifact@v2.2.0
with:
name: BeatSaberSmallMenus-${{ env.ZIP_VERSION }}-DEBUG
path: Source\SmallMenu\bin\Debug\netstandard2.0\publish

- name: Build Release
run: dotnet build --no-restore Source\SmallMenu\SmallMenu.csproj -c Release -p:BeatSaberDir=..\..\BeatSaberBindings

- name: Upload Release
uses: actions/upload-artifact@v2.2.0
with:
name: BeatSaberSmallMenus-${{ env.ZIP_VERSION }}-RELEASE
path: Source\SmallMenu\bin\Release\netstandard2.0\publish
Binary file added Libraries/0Harmony.dll
Binary file not shown.
Binary file added Libraries/BSML.dll
Binary file not shown.
Binary file added Libraries/IPA.Injector.dll
Binary file not shown.
Binary file added Libraries/IPA.Loader.dll
Binary file not shown.
Binary file added Libraries/SiraUtil.dll
Binary file not shown.
File renamed without changes.
38 changes: 38 additions & 0 deletions Source/SmallMenu/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<Project>

<Target Name="CheckBSMTInstalled" AfterTargets="BeforeBuild" Condition="'$(BSMTTaskAssembly)' == ''">
<Error Text="The BeatSaberModdingTools.Tasks NuGet package doesn't seem to be installed. Please restore NuGet packages before building the project." />
</Target>

<Target Name="SetAssemblyVersion" AfterTargets="CheckBSMTInstalled">
<GetManifestInfo>
<Output TaskParameter="BasePluginVersion" PropertyName="BasePluginVersion" />
</GetManifestInfo>

<PropertyGroup>
<Version>$(BasePluginVersion)</Version>
</PropertyGroup>
</Target>

<Target Name="Organize" AfterTargets="AfterBuild">
<!-- remove deps.json file since it's not used -->
<Delete Files="$(TargetDir)$(TargetName).deps.json" />

<!-- make sure we have a clean slate -->
<RemoveDir Directories="$(PublishDir)" />

<!-- create Plugins folder and move plugin DLL/PDB inside -->
<MakeDir Directories="$(PublishDir)Plugins" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PublishDir)Plugins" />
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb" DestinationFolder="$(PublishDir)Plugins" Condition="$(DebugType) == 'portable'" />
</Target>

<Target Name="CopyToBeatSaberFolder" AfterTargets="AfterBuild" Condition="$(BeatSaberDir) != ''">
<ItemGroup>
<CopyToBeatSaberFolder Include="$(PublishDir)**\*.*" />
</ItemGroup>

<Copy SourceFiles="@(CopyToBeatSaberFolder)" DestinationFiles="@(CopyToBeatSaberFolder->'$(BeatSaberDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

</Project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 11 additions & 25 deletions SmallMenu/SmallMenu.csproj → Source/SmallMenu/SmallMenu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(BeatSaberDir)\Libs\0Harmony.dll</HintPath>
<HintPath>..\..\Libraries\0Harmony.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="IPA.Injector">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Injector.dll</HintPath>
<HintPath>..\..\Libraries\IPA.Injector.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="IPA.Loader">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\IPA.Loader.dll</HintPath>
<HintPath>..\..\Libraries\IPA.Loader.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="SiraUtil">
<HintPath>$(BeatSaberDir)\Plugins\SiraUtil.dll</HintPath>
<HintPath>..\..\Libraries\SiraUtil.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="UnityEngine">
Expand All @@ -47,7 +47,7 @@
<Private>false</Private>
</Reference>
<Reference Include="BSML">
<HintPath>$(BeatSaberDir)\Plugins\BSML.dll</HintPath>
<HintPath>..\..\Libraries\BSML.dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
Expand All @@ -57,26 +57,12 @@
<EmbeddedResource Include="UI\Settings.bsml" />
</ItemGroup>

<Target Name="Organize" AfterTargets="AfterBuild">
<!-- remove deps.json file since it's not used -->
<Delete Files="$(TargetDir)$(TargetName).deps.json" />

<!-- make sure we have a clean slate -->
<RemoveDir Directories="$(PublishDir)" />

<!-- create Plugins folder and move plugin DLL/PDB inside -->
<MakeDir Directories="$(PublishDir)Plugins" />
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PublishDir)Plugins" />
<Copy SourceFiles="$(TargetDir)$(TargetName).pdb" DestinationFolder="$(PublishDir)Plugins" Condition="$(DebugType) == 'portable'" />
</Target>

<Target Name="CopyToBeatSaberFolder" AfterTargets="AfterBuild" Condition="$(BeatSaberDir) != ''">
<ItemGroup>
<CopyToBeatSaberFolder Include="$(PublishDir)**\*.*" />
</ItemGroup>

<Copy SourceFiles="@(CopyToBeatSaberFolder)" DestinationFiles="@(CopyToBeatSaberFolder->'$(BeatSaberDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
<ItemGroup>
<PackageReference Include="BeatSaberModdingTools.Tasks" Version="1.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ProjectExtensions><VisualStudio><UserProperties manifest_1json__JsonSchema="https://json-schema.org/draft-04/schema" /></VisualStudio></ProjectExtensions>

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions prepare_environment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
$ErrorActionPreference = "Stop"

$check = [char]0x2713
$cross = [char]0x2717

if ($args.Length -ne 1) {
Write-Host "Invalid number of arguments" -ForegroundColor Red
exit(-1)
}

if ($args[0] -eq "" -or !(Test-Path $args[0])) {
Write-Host "File '$($args[0])' does not exist" -ForegroundColor Red
exit(-1)
}

$manifest_content = Get-Content $args[0] | ConvertFrom-Json

$manifest_version_str = $manifest_content.version
$semver = [regex]::Match($manifest_version_str, '^(?<prerelease>(?<version>(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))(?:-(?:(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?)(?:\+(?:[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$')

$numeric_version = $semver.groups['version'].value
$version_with_prerelease = $semver.groups['prerelease'].value

$git_hash = (git log -n 1 --pretty=%h).Trim()
$git_tag = git tag -l --points-at HEAD

if ($git_tag -ne "" -and $git_tag.Length -gt 0) {
if ($git_tag -ne "v$version_with_prerelease") {
Write-Host "$cross Git tag '$git_tag' does not match manifest version '$version_with_prerelease'" -ForegroundColor Red
exit(-1)
}

Write-Host "$check Using Git tag '$git_tag'" -ForegroundColor Green
$manifest_content.version = $version_with_prerelease
$zip_version = "v$version_with_prerelease"
} elseif ($git_hash -ne "" -and $git_hash.Length -gt 0) {
Write-Host "$check Using Git hash '$git_hash'" -ForegroundColor Green
$manifest_content.version = "$version_with_prerelease+git.$git_hash"
$zip_version = $git_hash
} else {
Write-Host "$cross Could not find Git tag or hash" -ForegroundColor Red
exit(-1)
}

Add-Content "$env:GITHUB_ENV" "ZIP_VERSION=$zip_version"

$manifest_content | ConvertTo-Json | Set-Content $args[0]

0 comments on commit ad97e14

Please sign in to comment.