Skip to content

Commit bf85516

Browse files
Fix caching for unity builds (#5642)
# Description of Changes This is part of the work to break up #5612 into smaller reviewable chunks. Before this change, the cache key for the unity library was `Unity-${{ github.head_ref }}`. This meant every single PR experienced a cache miss, whether or not it changed any unity dependencies, and would subsequently do a full unity build and upload a new multi-GB entry to the actions cache. The actions cache isn't that big, so this was responsible for a huge amount of cache churn which in turn slowed all other builds down. Now the cache key incorporates the proper dependencies, and the cache is only written to on pushes to master. # API and ABI breaking changes None # Expected complexity level and risk 1 # Testing N/A
1 parent 93104da commit bf85516

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,22 @@ jobs:
820820
env:
821821
CARGO_TARGET_DIR: ${{ github.workspace }}/target
822822
RUST_BACKTRACE: full
823+
UNITY_VERSION: 2022.3.32f1
823824
steps:
824825
- name: Checkout repository
825826
id: checkout-stdb
826827
uses: actions/checkout@v4
827828

829+
# Keep this before generation/hydration so ignored build outputs do not affect hashFiles.
830+
- name: Restore Unity Library
831+
id: restore-unity-library
832+
uses: actions/cache/restore@v4
833+
with:
834+
path: demo/Blackholio/client-unity/Library
835+
key: Unity-v2-${{ runner.os }}-${{ env.UNITY_VERSION }}-${{ hashFiles('demo/Blackholio/client-unity/**', 'sdks/csharp/**', 'crates/bindings-csharp/BSATN.Runtime/**', 'crates/bindings-csharp/Runtime/**', 'crates/bindings-csharp/Directory.Build.props', 'tools/regen/src/csharp.rs', 'global.json') }}
836+
restore-keys: |
837+
Unity-v2-${{ runner.os }}-${{ env.UNITY_VERSION }}-
838+
828839
# Run cheap .NET tests first. If those fail, no need to run expensive Unity tests.
829840

830841
- name: Setup dotnet
@@ -933,16 +944,10 @@ jobs:
933944
yq e -i '.dependencies["com.clockworklabs.spacetimedbsdk"] = "file:../../../../sdks/csharp"' manifest.json
934945
cat manifest.json
935946
936-
- uses: actions/cache@v3
937-
with:
938-
path: demo/Blackholio/client-unity/Library
939-
key: Unity-${{ github.head_ref }}
940-
restore-keys: Unity-
941-
942947
- name: Run Unity tests
943948
uses: game-ci/unity-test-runner@v4
944949
with:
945-
unityVersion: 2022.3.32f1 # Adjust Unity version to a valid tag
950+
unityVersion: ${{ env.UNITY_VERSION }}
946951
projectPath: demo/Blackholio/client-unity # Path to the Unity project subdirectory
947952
githubToken: ${{ secrets.GITHUB_TOKEN }}
948953
testMode: playmode
@@ -953,6 +958,13 @@ jobs:
953958
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
954959
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
955960

961+
- name: Save Unity Library
962+
if: ${{ github.ref == 'refs/heads/master' && steps.restore-unity-library.outputs.cache-hit != 'true' }}
963+
uses: actions/cache/save@v4
964+
with:
965+
path: demo/Blackholio/client-unity/Library
966+
key: ${{ steps.restore-unity-library.outputs.cache-primary-key }}
967+
956968
godot-testsuite:
957969
needs: [merge_queue_noop, lints]
958970
if: ${{ needs.merge_queue_noop.outputs.skip != 'true' }}

0 commit comments

Comments
 (0)