Skip to content

Commit 4163180

Browse files
committed
Add branch APK build workflow
1 parent b23a7d7 commit 4163180

1 file changed

Lines changed: 126 additions & 0 deletions

File tree

.github/workflows/build-apk.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Build APK
2+
run-name: Build APK (${{ github.ref_name }})
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- "apk/**"
9+
10+
permissions:
11+
contents: read
12+
13+
env:
14+
APK_FILE: pythonhere-debug.apk
15+
BUILDOZER_BUILD_LOG: buildozer-build.log
16+
BUILDOZER_IMAGE: kivy/buildozer@sha256:fcfb08f4f7beecfdea10e23968c16933b935a2c820e012d8415f318cd8586aab
17+
RUST_TOOLCHAIN: 1.83.0
18+
19+
jobs:
20+
build-apk:
21+
name: Build Android debug APK
22+
runs-on: ubuntu-22.04
23+
timeout-minutes: 60
24+
25+
steps:
26+
- uses: actions/checkout@v6
27+
28+
- name: Install uv and set Python
29+
uses: astral-sh/setup-uv@v8.1.0
30+
with:
31+
python-version: "3.10"
32+
33+
- name: Install system dependencies
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y xvfb
37+
38+
- name: Install dependencies
39+
run: uv sync --managed-python --locked --group dev
40+
41+
- name: Run tests
42+
run: uv run ./run_tests.sh
43+
44+
- name: Run lint
45+
run: |
46+
uv run ruff check pythonhere tests
47+
uv run ruff format --check pythonhere tests
48+
uv run pylint pythonhere
49+
50+
- name: Build package
51+
run: uv run python -m build
52+
53+
- name: Check distribution
54+
run: uv run twine check dist/*
55+
56+
- name: Build Android APK with Buildozer Docker image
57+
shell: bash
58+
run: |
59+
set -o pipefail
60+
61+
docker run --rm \
62+
-v "$PWD":/home/user/hostcwd \
63+
-w /home/user/hostcwd \
64+
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
65+
"$BUILDOZER_IMAGE" \
66+
bash -lc '
67+
set -euo pipefail
68+
69+
export RUSTUP_HOME="$HOME/.rustup"
70+
export CARGO_HOME="$HOME/.cargo"
71+
export PATH="$CARGO_HOME/bin:$PATH"
72+
73+
if ! command -v cargo >/dev/null; then
74+
curl https://sh.rustup.rs -sSf \
75+
| sh -s -- -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN"
76+
fi
77+
78+
rustc --version
79+
cargo --version
80+
buildozer android debug
81+
' 2>&1 | tee "$BUILDOZER_BUILD_LOG"
82+
83+
- name: Prepare APK artifact
84+
id: artifact
85+
shell: bash
86+
run: |
87+
set -euo pipefail
88+
89+
safe_ref="${GITHUB_REF_NAME//\//-}"
90+
short_sha="${GITHUB_SHA::7}"
91+
artifact_base="pythonhere-debug-${safe_ref}-${short_sha}"
92+
93+
apk="$(find bin -name '*.apk' -type f | head -n 1)"
94+
95+
if [[ -z "$apk" ]]; then
96+
echo "::error::No APK found"
97+
exit 1
98+
fi
99+
100+
sudo cp "$apk" "${APK_FILE}"
101+
sudo chown "$(id -u):$(id -g)" "${APK_FILE}"
102+
103+
sha256sum "${APK_FILE}" > "${APK_FILE}.sha256"
104+
105+
echo "name=${artifact_base}" >> "$GITHUB_OUTPUT"
106+
ls -lh "${APK_FILE}" "${APK_FILE}.sha256"
107+
cat "${APK_FILE}.sha256"
108+
109+
- name: Upload APK artifact
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: ${{ steps.artifact.outputs.name }}
113+
path: |
114+
${{ env.APK_FILE }}
115+
${{ env.APK_FILE }}.sha256
116+
if-no-files-found: error
117+
retention-days: 8
118+
119+
- name: Upload Buildozer build log
120+
if: always()
121+
uses: actions/upload-artifact@v4
122+
with:
123+
name: buildozer-build-log
124+
path: ${{ env.BUILDOZER_BUILD_LOG }}
125+
if-no-files-found: ignore
126+
retention-days: 8

0 commit comments

Comments
 (0)