Refactor RemoteNET projects (#13) #124
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
types: [opened, synchronize] | |
paths: | |
- '.github/workflows/build.yml' | |
- '**/*.cs' | |
- '**/*.sln' | |
- '**/*.proj' | |
- '**/*.csproj' | |
- '**/*.vcxproj' | |
- '**/*.props' | |
- '**/*.targets' | |
- '**/packages.lock.json' | |
workflow_dispatch: | |
concurrency: | |
group: ci-${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
MSBUILD_CACHES: | | |
**/bin | |
**/obj | |
**/Win32 | |
**/x64 | |
MSBUILD_DEFAULTS: /m:2 /v:m /p:Configuration=Release /p:Platform="Any CPU" | |
NUGET_CACHES: | | |
~/.nuget/packages | |
NUGET_DEFAULTS: -Verbosity quiet -NonInteractive -UseLockFile | |
jobs: | |
# Runs test suite | |
build: | |
runs-on: windows-latest | |
name: "MSBuild Runner" | |
steps: | |
# Fetches remote repository without --progress option. | |
# | |
# The default behavior of @actions/checkout outputs many noisy lines of | |
# status output in the workflow log, which is problematic for log size. | |
- name: Checkout latest repository commit | |
uses: actions/checkout@v4 | |
with: | |
show-progress: false | |
# Setup the .NET environment | |
- name: Install .NET Core | |
uses: actions/setup-dotnet@v3 | |
# Setup MSBuild environment | |
- name: Setup MSBuild.exe | |
uses: microsoft/setup-msbuild@v1.3.1 | |
- name: Restore Build Cache | |
id: msbuild-cache | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.MSBUILD_CACHES }} | |
key: ${{ runner.os }}-msbuild-${{ github.ref_name }}-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-msbuild-${{ github.ref_name }} | |
${{ runner.os }}-msbuild- | |
# Setup NuGet environment | |
- name: Setup NuGet | |
uses: NuGet/setup-nuget@v1.2.0 | |
- name: Restore NuGet Cache | |
id: nuget-cache | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.NUGET_CACHES }} | |
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-nuget- | |
- name: Restore NuGet packages | |
if: steps.nuget-cache.outputs.cache-hit != 'true' | |
run: nuget restore SDK.sln ${{ env.NUGET_DEFAULTS }} | |
# Build MTGO reference assemblies | |
- name: Build Reference Assemblies | |
run: msbuild Ref.sln /t:Build ${{ env.MSBUILD_DEFAULTS }} | |
# Build the SDK | |
- name: Build SDK Solution | |
run: msbuild SDK.sln /t:Build ${{ env.MSBUILD_DEFAULTS }} | |
# Evict expired cache entries | |
- name: Purge expired cache entries | |
uses: actions/github-script@v6 | |
env: | |
MSBUILD_HIT: ${{ steps.msbuild-cache.outputs.cache-hit }} | |
NUGET_HIT: ${{ steps.nuget-cache.outputs.cache-hit }} | |
with: | |
script: | | |
// Extract environmental variables into their JS equivalents | |
const MSBUILD = process.env.MSBUILD_HIT !== 'true' | |
const NUGET = process.env.NUGET_HIT !== 'true' | |
// Exit early if no cache hits | |
if (!MSBUILD && !NUGET) | |
return // No cache hit | |
// Fetch the repository's Actions cache list | |
const caches = await github.rest.actions.getActionsCacheList({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}) | |
// Purge expired MSBuild and NuGet caches from the current ref | |
for (const { id, ref, key } of caches.data.actions_caches) { | |
if (ref != context.ref) | |
continue // Cache is not accessible in this context | |
if ((MSBUILD && key.startsWith("${{ runner.os }}-msbuild-")) || | |
(NUGET && key.startsWith("${{ runner.os }}-nuget-"))) { | |
await github.rest.actions.deleteActionsCacheById({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
cache_id: id, | |
}) | |
} | |
} |