Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/scripts/install-android-system-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail

: "${ANDROID_HOME:?ANDROID_HOME deve apontar para o SDK Android}"
package='system-images;android-34;google_apis;x86_64'

# O runner do emulador instala sem retry. Antecipar o download permite recuperar
# arquivos incompletos antes de criar o AVD, inclusive quando há snapshot em cache.
for attempt in 1 2 3; do
echo "Instalando $package (tentativa $attempt/3)"
if timeout 12m sdkmanager --install "$package" --channel=0; then
exit 0
fi

if [[ "$attempt" == 3 ]]; then
echo "::error::Não foi possível instalar a imagem Android após 3 tentativas"
exit 1
fi

# O sdkmanager mantém o ZIP parcial em .temp e pode reutilizá-lo no retry.
# Limitar a limpeza ao diretório temporário do SDK neste runner Linux.
if [[ "$ANDROID_HOME" != /* || "$ANDROID_HOME" == / ]]; then
echo "::error::Caminho do SDK inválido para limpeza: $ANDROID_HOME"
exit 1
fi
rm -rf -- "$ANDROID_HOME/.temp"
sleep 10
done
54 changes: 54 additions & 0 deletions .github/scripts/tests/install-android-system-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -euo pipefail

script="$(cd "$(dirname "$0")/.." && pwd)/install-android-system-image.sh"
fixture="$(mktemp -d)"
trap 'rm -rf "$fixture"' EXIT
mkdir -p "$fixture/bin" "$fixture/sdk"

cat > "$fixture/bin/sdkmanager" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
[[ "$*" == '--install system-images;android-34;google_apis;x86_64 --channel=0' ]] || exit 90
count=0
[[ ! -f "$ANDROID_HOME/count" ]] || read -r count < "$ANDROID_HOME/count"
count=$((count + 1))
echo "$count" > "$ANDROID_HOME/count"
if [[ "$count" -gt 1 && -e "$ANDROID_HOME/.temp/partial.zip" ]]; then
echo 'Download parcial não foi removido' >&2
exit 91
fi
if [[ "$count" -le "$FAILURES" ]]; then
mkdir -p "$ANDROID_HOME/.temp"
touch "$ANDROID_HOME/.temp/partial.zip"
exit 1
fi
EOF
cat > "$fixture/bin/timeout" <<'EOF'
#!/usr/bin/env bash
[[ "$1" == 12m ]] || exit 92
shift
exec "$@"
EOF
printf '#!/usr/bin/env bash\nexit 0\n' > "$fixture/bin/sleep"
chmod +x "$fixture/bin/"*

for failures in 0 1 3; do
rm -f "$fixture/sdk/count" "$fixture/sdk/.temp/partial.zip"
result=0
PATH="$fixture/bin:$PATH" ANDROID_HOME="$fixture/sdk" FAILURES="$failures" \
bash "$script" > "$fixture/output" 2>&1 || result=$?
expected_attempts=$((failures + 1))
expected_result=0
if [[ "$failures" == 3 ]]; then
expected_attempts=3
expected_result=1
fi
read -r attempts < "$fixture/sdk/count"
if [[ "$result" != "$expected_result" || "$attempts" != "$expected_attempts" ]]; then
cat "$fixture/output"
echo "FAIL: failures=$failures (exit=$result, attempts=$attempts)" >&2
exit 1
fi
echo "PASS: failures=$failures, attempts=$attempts, exit=$result"
done
3 changes: 3 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ jobs:
- name: Testar a conferência do deploy antes do APK
run: bash .github/scripts/tests/wait-for-server-deploy.sh

- name: Testar a recuperação do download da imagem Android
run: bash .github/scripts/tests/install-android-system-image.sh

- name: Testar os canais externos nas telas do app
run: dotnet run --project tests/ux-mobile-preview/ux-mobile-preview.csproj --configuration Release -- --verify-external-applications

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/mobile-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ jobs:
~/.android/adb*
key: avd-api34-google_apis-x86_64-pixel_6-v1

- name: Instalar imagem Android com novas tentativas
run: bash .github/scripts/install-android-system-image.sh

- name: Criar o AVD e gerar o snapshot para o cache
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0
Expand Down
Loading