From 3e9b6ab0931f772408303c81d054f3e498506a0a Mon Sep 17 00:00:00 2001 From: SyscallBrain <61458775+SyscallBrain@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:14:22 +0000 Subject: [PATCH] ci: manual test APK signed with the release key Runs only from workflow_dispatch on any branch. Optionally runs the unit tests, builds the release APK signed with the ZERODROID_* secrets so it installs over the stable app, and keeps it as a 7-day artifact; nothing is published. --- .github/workflows/test-apk.yml | 96 ++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/test-apk.yml diff --git a/.github/workflows/test-apk.yml b/.github/workflows/test-apk.yml new file mode 100644 index 0000000..f19584a --- /dev/null +++ b/.github/workflows/test-apk.yml @@ -0,0 +1,96 @@ +# Compila um APK de teste do ZeroDroid SÓ quando o dono o lança à mão. +# Não publica nada: o APK fica como "artifact" do run e é apagado ao fim de +# 7 dias. É assinado com a chave de RELEASE (os secrets ZERODROID_*), por isso +# instala-se por cima da versão estável sem desinstalar nem voltar a emparelhar. +# +# Lançar (no Termux, ou em qualquer sítio com o gh): +# gh workflow run test-apk.yml -R SyscallBrain/zerodroid --ref +# gh workflow run test-apk.yml -R SyscallBrain/zerodroid --ref -f testes=false +# Seguir e descarregar: +# gh run watch -R SyscallBrain/zerodroid --exit-status +# gh run download -R SyscallBrain/zerodroid --pattern 'zerodroid-*' +name: Test APK (manual) + +# Único gatilho: o botão "Run workflow" ou o "gh workflow run". Nada de push, +# pull_request ou schedule, por isso nunca corre sozinho. +on: + workflow_dispatch: + inputs: + testes: + description: Correr os testes unitários antes de compilar + type: boolean + default: true + +# O token automático do run só pode ler o repo. +permissions: + contents: read + +jobs: + apk: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + steps: + - name: Check out source + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 + with: + distribution: temurin + java-version: 21 + + # Instala o Gradle do wrapper, valida o gradle-wrapper.jar e guarda a cache. + - uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 + + - name: Unit tests + if: inputs.testes + run: ./gradlew testDebugUnitTest + + # O keystore vive no secret em base64; é escrito num ficheiro temporário + # do runner só durante o build e apagado logo a seguir. + - name: Set up the release signing key + env: + KEYSTORE_BASE64: ${{ secrets.ZERODROID_KEYSTORE_BASE64 }} + run: | + if [ -z "$KEYSTORE_BASE64" ]; then + echo "Falta o secret ZERODROID_KEYSTORE_BASE64: sem ele o APK não instala por cima do estável" >&2 + exit 1 + fi + printf '%s' "$KEYSTORE_BASE64" | base64 --decode > "$RUNNER_TEMP/release.jks" + echo "ZERODROID_KEYSTORE=$RUNNER_TEMP/release.jks" >> "$GITHUB_ENV" + + - name: Build the release APK + env: + ZERODROID_KEYSTORE_PASSWORD: ${{ secrets.ZERODROID_KEYSTORE_PASSWORD }} + ZERODROID_KEY_ALIAS: ${{ secrets.ZERODROID_KEY_ALIAS }} + ZERODROID_KEY_PASSWORD: ${{ secrets.ZERODROID_KEY_PASSWORD }} + run: ./gradlew assembleRelease + + - name: Verify the signature and label the APK + run: | + rm -f "$RUNNER_TEMP/release.jks" + apksigner=$(find "$ANDROID_HOME/build-tools" -name apksigner | sort -V | tail -1) + apk=app/build/outputs/apk/release/app-release.apk + "$apksigner" verify --print-certs "$apk" + version=$(sed -n 's/^[[:space:]]*versionName = "\(.*\)"/\1/p' app/build.gradle.kts) + short=$(git rev-parse --short HEAD) + echo "APK_NAME=zerodroid-$version-$short" >> "$GITHUB_ENV" + mkdir out + cp "$apk" "out/zerodroid-$version-$short.apk" + { + echo "repo: $GITHUB_REPOSITORY" + echo "branch: $GITHUB_REF_NAME" + echo "commit: $(git rev-parse HEAD)" + echo "run: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" + echo "version: $version" + } > out/BUILD-INFO.txt + (cd out && sha256sum -- *.apk > SHA256SUMS && cat SHA256SUMS BUILD-INFO.txt) + + - name: Upload the APK + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: ${{ env.APK_NAME }} + path: out/ + if-no-files-found: error + retention-days: 7