Skip to content

Commit 00f4f06

Browse files
authored
chore: CI Improvements (#2422)
* Project & Library caching, docker stop, permission fix * Just stop the container * Only install of no cache hit * Naming, close docker timeout * Workload restore does that now * I don't think we need the option configuration anymore * Upsi * Limit runs within platform * Free disk space for building * Make the thing unique * Does it take the MAC address? * Clear it * Updated 'ci-docker.sh' * Cleanup * Hostname * Remove redundant mask, and also, go maximum fast * . * Cache unity-of-bugs library too * Clean build for 2022 and older
1 parent 37d4338 commit 00f4f06

File tree

8 files changed

+93
-41
lines changed

8 files changed

+93
-41
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ jobs:
2929
- name: Checkout
3030
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
3131

32+
- name: Free Disk Space (Ubuntu)
33+
uses: jlumbroso/free-disk-space@f68fdb76e2ea636224182cfb7377ff9a1708f9b8 # v1.3.0
34+
with:
35+
android: true
36+
dotnet: false
37+
haskell: true
38+
large-packages: false
39+
docker-images: false
40+
swap-storage: true
41+
3242
- name: Checkout submodules
3343
run: git submodule update --init --recursive src/sentry-dotnet
3444

@@ -38,17 +48,13 @@ jobs:
3848
env:
3949
UNITY_SCRIPT_ARG: unity${{ env.UNITY_VERSION }}
4050

41-
- run: echo "::add-mask::$LICENSE_SERVER_URL"
42-
env:
43-
LICENSE_SERVER_URL: ${{ secrets.LICENSE_SERVER_URL }}
44-
45-
- name: Restore Unity Packages
46-
uses: actions/cache@2f8e54208210a422b2efd51efaa6bd6d7ca8920f # v3
51+
- name: Cache Unity Library
52+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
4753
with:
48-
path: |
49-
samples/unity-of-bugs/Library/Packages
50-
temp/unity-packages/Library/ScriptAssemblies/*.TestRunner.*
51-
key: samples/unity-of-bugs|${{ steps.env.outputs.unityVersion }}-${{ hashFiles('samples/unity-of-bugs/Packages/packages-lock.json') }}
54+
path: samples/unity-of-bugs/Library
55+
key: Library-unity-of-bugs-${{ steps.env.outputs.unityVersion }}-v1
56+
restore-keys: |
57+
Library-unity-of-bugs-${{ steps.env.outputs.unityVersion }}-
5258
5359
- name: Docker Login
5460
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # pinned v3
@@ -72,11 +78,6 @@ jobs:
7278
- name: Restore .NET Workload
7379
run: dotnet workload restore
7480

75-
- name: Install Android dotnet workflow
76-
run: dotnet workload install android --temp-dir "$RUNNER_TEMP"
77-
env:
78-
RUNNER_TEMP: ${{ env.RUNNER_TEMP }}
79-
8081
- name: Download CLI
8182
run: ./scripts/download-sentry-cli.ps1
8283

@@ -134,9 +135,7 @@ jobs:
134135
package-release.zip
135136
136137
- name: Run Unity tests (playmode)
137-
run: |
138-
docker exec unity dotnet msbuild /t:UnityConfigureSentryOptions /p:TestDsn= /p:Configuration=Release /p:OutDir=other src/Sentry.Unity
139-
docker exec unity dotnet msbuild /t:UnityPlayModeTest /p:Configuration=Release /p:OutDir=other test/Sentry.Unity.Tests
138+
run: docker exec unity dotnet msbuild /t:UnityPlayModeTest /p:Configuration=Release /p:OutDir=other test/Sentry.Unity.Tests
140139

141140
- name: Run Unity tests (editmode)
142141
run: docker exec unity dotnet msbuild /t:UnityEditModeTest /p:Configuration=Release /p:OutDir=other test/Sentry.Unity.Editor.Tests

.github/workflows/ci.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ jobs:
133133
docker-images: false
134134
swap-storage: true
135135

136-
- run: echo "::add-mask::$LICENSE_SERVER_URL"
137-
env:
138-
LICENSE_SERVER_URL: ${{ secrets.LICENSE_SERVER_URL }}
139-
140136
- name: Docker Login
141137
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # pinned v3
142138
with:
@@ -162,6 +158,15 @@ jobs:
162158
- name: Extract project archive
163159
run: tar -xvzf test-project.tar.gz
164160

161+
- name: Cache Unity Library
162+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
163+
with:
164+
path: samples/IntegrationTest/Library
165+
key: Library-IntegrationTest-${{ matrix.platform }}-${{ matrix.unity-version }}-v1
166+
restore-keys: |
167+
Library-IntegrationTest-${{ matrix.platform }}-${{ matrix.unity-version }}-
168+
Library-IntegrationTest-${{ matrix.platform }}-
169+
165170
- name: Restore cached build without Sentry
166171
id: cache-build-nosentry
167172
uses: actions/cache@v4
@@ -393,10 +398,6 @@ jobs:
393398
unity-version: ${{ steps.env.outputs.unityVersion }}
394399
unity-modules: ${{ matrix.unity-modules }}
395400

396-
- run: echo "::add-mask::$LICENSE_SERVER_URL"
397-
env:
398-
LICENSE_SERVER_URL: ${{ secrets.LICENSE_SERVER_URL }}
399-
400401
- name: Create Unity license config
401402
run: |
402403
New-Item -Path "$env:UNITY_CONFIG_PATH" -ItemType Directory
@@ -413,6 +414,15 @@ jobs:
413414
- name: Extract project archive
414415
run: tar -xvzf test-project.tar.gz
415416

417+
- name: Cache Unity Library
418+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
419+
with:
420+
path: samples/IntegrationTest/Library
421+
key: Library-IntegrationTest-${{ matrix.os }}-${{ matrix.unity-version }}-v1
422+
restore-keys: |
423+
Library-IntegrationTest-${{ matrix.os }}-${{ matrix.unity-version }}-
424+
Library-IntegrationTest-${{ matrix.os }}-
425+
416426
- name: Restore cached build without Sentry
417427
id: cache-build-nosentry
418428
uses: actions/cache@v4

.github/workflows/sdk.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ jobs:
8181
DEBIAN_FRONTEND: noninteractive
8282

8383
- name: Install .NET SDK
84+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
8485
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d # v5
8586
with:
8687
global-json-file: global.json
8788

8889
- name: Restore .NET Workload
90+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
8991
run: dotnet workload restore
9092

9193
- name: Build

.github/workflows/smoke-test-build-android.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ jobs:
2424
- name: Checkout
2525
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
2626

27-
- run: echo "::add-mask::$LICENSE_SERVER_URL"
28-
env:
29-
LICENSE_SERVER_URL: ${{ secrets.LICENSE_SERVER_URL }}
30-
3127
- name: Docker Login
3228
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # pinned v3
3329
with:
@@ -49,6 +45,15 @@ jobs:
4945
- name: Extract project archive
5046
run: tar -xvzf test-project.tar.gz
5147

48+
- name: Cache Unity Library
49+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
50+
with:
51+
path: samples/IntegrationTest/Library
52+
key: Library-IntegrationTest-Android-${{ env.UNITY_VERSION }}-v1
53+
restore-keys: |
54+
Library-IntegrationTest-Android-${{ env.UNITY_VERSION }}-
55+
Library-IntegrationTest-Android-
56+
5257
- name: Restore cached build without Sentry
5358
id: cache-build-nosentry
5459
uses: actions/cache@v4

.github/workflows/smoke-test-build-ios.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ jobs:
3030
- name: Checkout
3131
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
3232

33-
- run: echo "::add-mask::$LICENSE_SERVER_URL"
34-
env:
35-
LICENSE_SERVER_URL: ${{ secrets.LICENSE_SERVER_URL }}
36-
3733
- name: Docker Login
3834
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # pinned v3
3935
with:
@@ -55,6 +51,15 @@ jobs:
5551
- name: Extract project archive
5652
run: tar -xvzf test-project.tar.gz
5753

54+
- name: Cache Unity Library
55+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
56+
with:
57+
path: samples/IntegrationTest/Library
58+
key: Library-IntegrationTest-iOS-${{ env.UNITY_VERSION }}-v1
59+
restore-keys: |
60+
Library-IntegrationTest-iOS-${{ env.UNITY_VERSION }}-
61+
Library-IntegrationTest-iOS-
62+
5863
- name: Restore cached build without Sentry
5964
id: cache-build-nosentry
6065
uses: actions/cache@v4
@@ -96,21 +101,21 @@ jobs:
96101
env:
97102
BUILD_PLATFORM: ${{ matrix.build_platform }}
98103

99-
- name: Build Project
104+
- name: Build Project with runtime initialization
100105
run: ./test/Scripts.Integration.Test/build-project.ps1 -UnityPath "$env:UNITY_PATH" -Platform "$env:BUILD_PLATFORM" -CheckSymbols:$false -UnityVersion "$env:UNITY_VERSION"
101106
env:
102107
BUILD_PLATFORM: ${{ matrix.build_platform }}
103108

104109
# We create tar explicitly because upload-artifact is slow for many files.
105-
- name: Create archive
110+
- name: Create archive (runtime initialization)
106111
shell: bash
107112
run: |
108113
# Note: remove local.properties file that contains Android SDK & NDK paths in the Unity installation.
109114
rm -rf samples/IntegrationTest/Build/*_BackUpThisFolder_ButDontShipItWithYourGame
110115
tar -cvzf test-app-runtime.tar.gz samples/IntegrationTest/Build
111116
112117
# Upload runtime initialization build
113-
- name: Upload test app
118+
- name: Upload test app (runtime initialization)
114119
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
115120
with:
116121
name: testapp-ios-${{ env.UNITY_VERSION }}-runtime
@@ -125,7 +130,7 @@ jobs:
125130
$content = $content -replace 'IosNativeInitializationType = NativeInitializationType.Runtime', 'IosNativeInitializationType = NativeInitializationType.BuildTime'
126131
Set-Content $optionsPath $content
127132
128-
- name: Build Project for mobile platforms (build-time initialization)
133+
- name: Build Project with build-time initialization
129134
run: ./test/Scripts.Integration.Test/build-project.ps1 -UnityPath "$env:UNITY_PATH" -Platform "$env:BUILD_PLATFORM" -CheckSymbols:$false -UnityVersion "$env:UNITY_VERSION"
130135
env:
131136
BUILD_PLATFORM: ${{ matrix.build_platform }}

.github/workflows/smoke-test-create.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,24 @@ jobs:
3434
username: ${{ env.GITHUB_ACTOR }}
3535
password: ${{ secrets.GITHUB_TOKEN }}
3636

37+
- name: Cache IntegrationTest Project
38+
id: cache-project
39+
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
40+
with:
41+
path: samples/IntegrationTest
42+
key: IntegrationTest-Project-${{ env.UNITY_VERSION }}-${{ hashFiles('test/Scripts.Integration.Test/**') }}-v1
43+
restore-keys: |
44+
IntegrationTest-Project-${{ env.UNITY_VERSION }}-
45+
3746
- name: Start the Unity docker container
47+
if: steps.cache-project.outputs.cache-hit != 'true'
3848
run: ./scripts/ci-docker.sh "$UNITY_VERSION" 'base' "$UNITY_LICENSE_SERVER_CONFIG"
3949
shell: bash
4050
env:
4151
UNITY_LICENSE_SERVER_CONFIG: ${{ secrets.UNITY_LICENSE_SERVER_CONFIG }}
4252

4353
- name: Create new Project
54+
if: steps.cache-project.outputs.cache-hit != 'true'
4455
run: ./test/Scripts.Integration.Test/create-project.ps1 -UnityPath "$env:UNITY_PATH"
4556

4657
# We create tar explicitly because upload-artifact is slow for many files.

scripts/ci-docker.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ fi
2626
echo "Starting up '$image' as '$container'"
2727
suexec="docker exec --user root"
2828

29+
# Format: <job-name>-<image-variant>-<run-id>
30+
uniqueHostname="${GITHUB_JOB:-local}-${imageVariant}-${GITHUB_RUN_ID:-0}"
31+
# Sanitize hostname: replace underscores and spaces with hyphens, ensure lowercase
32+
uniqueHostname=$(echo "$uniqueHostname" | tr '[:upper:]_ ' '[:lower:]--' | tr -s '-')
33+
2934
# We use the host dotnet installation - it's much faster than installing inside the docker container.
3035
set -x
3136
docker run -td --name $container \
37+
--hostname $uniqueHostname \
3238
--user $uid:$gid \
3339
-v "$cwd":/sentry-unity \
3440
-v $ANDROID_HOME:$ANDROID_HOME \
@@ -39,6 +45,10 @@ docker run -td --name $container \
3945
-e GITHUB_ACTIONS="${GITHUB_ACTIONS}" \
4046
--workdir /sentry-unity $image
4147

48+
# Generate unique machine-id to avoid any hardcoded values and license-fetch congestion
49+
$suexec $container rm -f /etc/machine-id
50+
$suexec $container dbus-uuidgen --ensure=/etc/machine-id
51+
4252
$suexec $container groupadd -g $gid $user
4353
$suexec $container useradd -u $uid -g $gid --create-home $user
4454

@@ -50,9 +60,7 @@ echo $licenseConfig | $suexec -i $container sh -c "cat > /usr/share/unity3d/conf
5060
$suexec $container chown -R $uid /usr/share/unity3d/config/
5161

5262
# Unity 2021+ tries to write to this directory during asset import...
53-
if [[ $unityPrefix -ge 2021 ]]; then
54-
$suexec $container chmod -R 755 /opt/unity/Editor/Data/UnityReferenceAssemblies/
55-
fi
63+
$suexec $container chmod -R 755 /opt/unity/Editor/Data/UnityReferenceAssemblies/
5664

5765
echo "Container started successfully: "
5866
docker ps --filter "name=^/$container$"

test/Scripts.Integration.Test/Editor/Builder.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ public static void BuildLinuxIl2CPPPlayer()
154154
public static void BuildAndroidIl2CPPPlayer()
155155
{
156156
Debug.Log("Builder: Building Android IL2CPP Player");
157+
158+
#if UNITY_2021_2_OR_NEWER && !UNITY_6000_0_OR_NEWER
159+
// Clean Android gradle cache to force regeneration of gradle files
160+
// This prevents Unity from reusing gradle files that may contain Sentry symbol upload tasks from previous builds
161+
var androidGradlePath = Path.Combine(Directory.GetCurrentDirectory(), "Library/Bee/Android");
162+
if (Directory.Exists(androidGradlePath))
163+
{
164+
Debug.Log($"Builder: Cleaning Android gradle cache at '{androidGradlePath}'");
165+
Directory.Delete(androidGradlePath, true);
166+
}
167+
#endif
168+
157169
BuildIl2CPPPlayer(BuildTarget.Android, BuildTargetGroup.Android, BuildOptions.StrictMode);
158170
}
159171
public static void BuildAndroidIl2CPPProject()

0 commit comments

Comments
 (0)