Repository navigation
137 lines (128 loc) · 6.55 KB
/
Copy pathE-coder-android.yml
File metadata and controls
137 lines (128 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: ECoder Android app
# Builds ECoder-android.apk (agents-lab/E-coder/android/: a full-screen window around the web app), signs it with the key in the
# repository's secrets, opens it on an emulator and puts it on the E-coder-android release.
on:
workflow_dispatch:
push:
branches: [main]
paths:
- "agents-lab/E-coder/android/**"
- ".github/workflows/E-coder-android.yml"
pull_request:
paths:
- "agents-lab/E-coder/android/**"
- ".github/workflows/E-coder-android.yml"
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: "Build and sign the .apk (no Gradle: aapt2, javac, d8, zipalign, apksigner)"
env:
KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
run: |
tools=$(ls -d "$ANDROID_HOME"/build-tools/34.* 2>/dev/null | sort -V | tail -n 1)
if [ -z "$tools" ]; then tools=$(ls -d "$ANDROID_HOME"/build-tools/* | sort -V | tail -n 1); fi
platform="$ANDROID_HOME/platforms/android-34"
if [ ! -f "$platform/android.jar" ]; then platform=$(ls -d "$ANDROID_HOME"/platforms/android-* | sort -V | tail -n 1); fi
export ANDROID_BUILD_TOOLS="$tools" ANDROID_JAR="$platform/android.jar"
echo "build-tools: $tools, platform: $platform"
if [ -n "$KEYSTORE_B64" ]; then
echo "$KEYSTORE_B64" | base64 -d > "$RUNNER_TEMP/release.p12"
printf '%s' "$KEYSTORE_PASSWORD" > "$RUNNER_TEMP/release-password.txt"
python3 agents-lab/E-coder/android/build.py --keystore "$RUNNER_TEMP/release.p12" --password-file "$RUNNER_TEMP/release-password.txt" --alias shells
echo "SIGNED=release" >> "$GITHUB_ENV"
else
echo "::warning::No signing key secret here (a pull request from a fork): signed with a throwaway key."
python3 agents-lab/E-coder/android/build.py
echo "SIGNED=throwaway" >> "$GITHUB_ENV"
fi
echo "APKSIGNER=$tools/apksigner" >> "$GITHUB_ENV"
- name: The certificate is the one app.json names
if: env.SIGNED == 'release'
run: |
expected=$(python3 -c "import json; print(json.load(open('agents-lab/E-coder/android/app.json'))['certSha256'])")
found=$("$APKSIGNER" verify --print-certs agents-lab/E-coder/android/dist/ECoder-android.apk | sed -n 's/^Signer #1 certificate SHA-256 digest: //p')
echo "expected $expected"
echo "found $found"
[ "$expected" = "$found" ]
(cd agents-lab/E-coder/android/dist && sha256sum ECoder-android.apk > ECoder-android.apk.sha256 && cat ECoder-android.apk.sha256)
- uses: actions/upload-artifact@v4
with:
name: ecoder-android
path: agents-lab/E-coder/android/dist/
if-no-files-found: error
emulator:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: ecoder-android
path: agents-lab/E-coder/android/dist
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Open the app on an emulator and check it stays up
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
target: google_apis
arch: x86_64
profile: pixel_6
disable-animations: true
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
script: python3 agents-lab/E-coder/android/smoke.py agents-lab/E-coder/android/dist/ECoder-android.apk
- uses: actions/upload-artifact@v4
if: always()
with:
name: ecoder-android-emulator-check
path: |
agents-lab/E-coder/android/dist/*.png
agents-lab/E-coder/android/dist/android-logcat.txt
retention-days: 7
publish:
needs: [build, emulator]
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: ecoder-android
path: dist
# The E-coder-android release keeps one address for the download. The file there is replaced only when
# agents-lab/E-coder/android/app.json names a new versionName, never by a rebuild of the same version.
- name: Put the .apk on the E-coder-android release
env:
GH_TOKEN: ${{ github.token }}
run: |
version=$(python3 -c "import json; print(json.load(open('agents-lab/E-coder/android/app.json'))['versionName'])")
echo "$version" > dist/ECoder-android.version.txt
if ! gh release view E-coder-android --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
printf '%s\n' "E-coder for Android: a full-screen window around the web app (https://juw12.github.io/projects/e-coder/)." "" \
"Download [ECoder-android.apk](https://github.com/$GITHUB_REPOSITORY/releases/download/E-coder-android/ECoder-android.apk), open the file on the phone and allow \"install unknown apps\" for your browser once." \
"It is not from a store: Android asks before it installs." > notes.md
gh release create E-coder-android dist/ECoder-android.apk dist/ECoder-android.apk.sha256 dist/ECoder-android.version.txt \
--title "E-coder for Android" --notes-file notes.md --latest=false --repo "$GITHUB_REPOSITORY"
echo "Made the E-coder-android release with ECoder-android.apk $version"
exit 0
fi
published=$(gh release download E-coder-android --repo "$GITHUB_REPOSITORY" --pattern ECoder-android.version.txt --output - 2>/dev/null || true)
if [ "$published" = "$version" ]; then
echo "the E-coder-android release already has ECoder-android.apk $version"
exit 0
fi
gh release upload E-coder-android dist/ECoder-android.apk dist/ECoder-android.apk.sha256 dist/ECoder-android.version.txt --clobber --repo "$GITHUB_REPOSITORY"
echo "ECoder-android.apk on the E-coder-android release is now $version (was: ${published:-none})"