Skip to content

Commit

Permalink
Optimize MSBuild logging and caching (#9)
Browse files Browse the repository at this point in the history
* MSBuild: Output performance summary after build

* Simplify logging args, add concurrency group

* Update build triggers, paths filter

* Add build cache expiration policy

* Fix cache expiration check
  • Loading branch information
Qonfused authored Dec 3, 2023
1 parent 08d76ac commit 746a9cf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, closed, reopened]
types: [opened, synchronize]
paths:
- '.github/workflows/build.yml'
- '**/*.cs'
- '**/*.sln'
- '**/*.proj'
Expand All @@ -14,16 +15,19 @@ on:
- '**/*.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 /clp:Summary /p:Configuration=Release /p:Platform="Any CPU"
MSBUILD_DEFAULTS: /m:2 /v:m /p:Configuration=Release /p:Platform="Any CPU"
NUGET_CACHES: |
~/.nuget/packages
NUGET_DEFAULTS: -Verbosity quiet -NonInteractive -ConfigFile NuGet.Config -UseLockFile
NUGET_DEFAULTS: -Verbosity quiet -NonInteractive -UseLockFile
jobs:
# Runs test suite
build:
Expand Down Expand Up @@ -76,3 +80,39 @@ jobs:
# 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,
})
}
}
File renamed without changes.

0 comments on commit 746a9cf

Please sign in to comment.