Skip to content

Commit e1a9413

Browse files
committed
Add Adb provider tests to CI
Exclude adb tests by path Test Test Remove secrets for adb workflow Fix exclude path Test adb ci test test Revert "test" This reverts commit 85d90f2. Fix PR suggestions fix excluding adb test (require abs path) test Potential fix for code scanning alert no. 135: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Fix Adb test path Add Android build-tools dir to PATH so aapt will be available test
1 parent b88b632 commit e1a9413

File tree

6 files changed

+106
-5
lines changed

6 files changed

+106
-5
lines changed

.github/workflows/app-runner.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: AppRunner
2+
permissions: read-all
23

34
on:
45
push:
@@ -18,4 +19,10 @@ jobs:
1819
module-name: SentryAppRunner
1920
module-path: app-runner
2021
test-path: Tests
22+
exclude-path: Adb.Tests.ps1
2123
settings-path: PSScriptAnalyzerSettings.psd1
24+
25+
test-adb:
26+
uses: ./.github/workflows/test-adb-provider.yml
27+
with:
28+
module-path: app-runner
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Test ADB Provider
2+
permissions:
3+
contents: read
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
module-path:
9+
description: 'Path to the module directory'
10+
required: true
11+
type: string
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
defaults:
17+
run:
18+
working-directory: ${{ inputs.module-path }}
19+
shell: pwsh
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Enable KVM group permissions
26+
run: |
27+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
28+
sudo udevadm control --reload-rules
29+
sudo udevadm trigger --name-match=kvm
30+
31+
- name: Setup Android directories
32+
run: |
33+
mkdir -p $HOME/.android/avd
34+
touch $HOME/.android/repositories.cfg
35+
36+
- name: Install Android SDK Build Tools
37+
shell: bash
38+
run: |
39+
${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --install "build-tools;35.0.0"
40+
echo "${ANDROID_HOME}/build-tools/35.0.0" >> $GITHUB_PATH
41+
42+
- name: Run ADB Provider Integration Tests
43+
uses: reactivecircus/android-emulator-runner@d94c3fbe4fe6a29e4a5ba47c12fb47677c73656b
44+
timeout-minutes: 45
45+
with:
46+
api-level: 35
47+
target: 'google_apis'
48+
arch: x86_64
49+
force-avd-creation: true
50+
disable-animations: true
51+
disable-spellchecker: true
52+
emulator-options: >
53+
-no-window
54+
-no-snapshot-save
55+
-gpu swiftshader_indirect
56+
-noaudio
57+
-no-boot-anim
58+
-camera-back none
59+
-camera-front none
60+
script: |
61+
adb wait-for-device
62+
echo "Android emulator is ready"
63+
adb devices
64+
cd ${{ inputs.module-path }} && pwsh -Command "Invoke-Pester Tests/Adb.Tests.ps1 -CI"

.github/workflows/test-powershell-module.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ on:
2323
required: false
2424
type: string
2525
default: ''
26+
exclude-path:
27+
description: 'Comma-separated list of test file paths to exclude (relative to test-path)'
28+
required: false
29+
type: string
30+
default: ''
2631
settings-path:
2732
description: 'Path to PSScriptAnalyzer settings file (relative to repo root)'
2833
required: false
@@ -98,6 +103,16 @@ jobs:
98103
$config.Filter.ExcludeTag = $excludeTags.Split(',').Trim()
99104
}
100105
106+
$excludePath = "${{ inputs.exclude-path }}"
107+
if ($excludePath) {
108+
$testPath = "${{ inputs.test-path }}"
109+
$config.Run.ExcludePath = $excludePath.Split(',').Trim() | ForEach-Object {
110+
$relativePath = Join-Path $testPath $_
111+
# ExcludePath requires absolute paths
112+
Join-Path (Get-Location) $relativePath
113+
}
114+
}
115+
101116
$testResults = Invoke-Pester -Configuration $config
102117
103118
Write-Host "Test Summary:" -ForegroundColor Cyan

app-runner/Private/DeviceProviders/AdbProvider.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class AdbProvider : DeviceProvider {
312312
$pidOutput = $this.InvokeCommand('pidof', @($this.DeviceSerial, $packageName))
313313

314314
if ($pidOutput) {
315-
$processId = $pidOutput.ToString().Trim()
315+
$processId = (@($pidOutput)[0]).ToString().Trim()
316316
if ($processId -match '^\d+$') {
317317
return $processId
318318
}

app-runner/Tests/Adb.Tests.ps1

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ BeforeDiscovery {
2424

2525
$TestTargets = @()
2626

27+
# Detect if running in CI environment
28+
$isCI = $env:CI -eq 'true'
29+
2730
# Check for ADB availability for AdbProvider
2831
if (Get-Command 'adb' -ErrorAction SilentlyContinue) {
2932
# Check if any devices are connected
@@ -32,11 +35,23 @@ BeforeDiscovery {
3235
$TestTargets += Get-TestTarget -Platform 'Adb'
3336
}
3437
else {
35-
Write-Warning "No Android devices connected via ADB. AdbProvider tests will be skipped."
38+
$message = "No Android devices connected via ADB"
39+
if ($isCI) {
40+
throw "$message. This is required in CI."
41+
}
42+
else {
43+
Write-Warning "$message. AdbProvider tests will be skipped."
44+
}
3645
}
3746
}
3847
else {
39-
Write-Warning "ADB not found in PATH. AdbProvider tests will be skipped."
48+
$message = "ADB not found in PATH"
49+
if ($isCI) {
50+
throw "$message. This is required in CI."
51+
}
52+
else {
53+
Write-Warning "$message. AdbProvider tests will be skipped."
54+
}
4055
}
4156
}
4257

@@ -58,7 +73,7 @@ BeforeAll {
5873
}
5974
}
6075

61-
Describe '<Platform>' -Tag 'RequiresDevice', 'Android' -ForEach $TestTargets {
76+
Describe '<Platform>' -Tag 'Adb' -ForEach $TestTargets {
6277
Context 'Device Connection Management' -Tag $TargetName {
6378
AfterEach {
6479
Invoke-TestCleanup

app-runner/Tests/SauceLabs.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ BeforeAll {
9494
}
9595
}
9696

97-
Describe '<Platform>' -Tag 'RequiresDevice', 'SauceLabs' -ForEach $TestTargets {
97+
Describe '<Platform>' -Tag 'SauceLabs' -ForEach $TestTargets {
9898
Context 'Device Connection Management' -Tag $TargetName {
9999
AfterEach {
100100
Invoke-TestCleanup

0 commit comments

Comments
 (0)