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
101 changes: 101 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# GitLab CI for mobile-agent-testers.
#
# Two parts, mirroring the GitHub workflow:
#
# * `test` (always): the offline checks of .github/workflows/tests.yml. They need
# no phone, no model and no secret, so they run unchanged on any GitLab runner.
# * `testers` (manual): the Android testers of .github/workflows/agent-testers.yml.
# They reuse this repository's own scripts and need a runner with KVM, an
# Android SDK and a booted emulator, plus the same secrets. See the job below.
#
# iOS builds and testers need a macOS runner, which gitlab.com's shared runners are
# not. Add your own macOS runner and reuse scripts/build/ios.sh and
# scripts/ios/run_agent.sh to port those jobs the same way.
#
# Test it offline, with no runner: `python3 -m unittest tests.test_gitlab_ci`.

stages:
- test
- testers

# --- Offline checks: every push and merge request. No phone, no model, no secret. ---
# Same commands as .github/workflows/tests.yml. The two Python versions are the
# python3 of a Mac without Homebrew (where collect.sh runs) and a current one.
.unit-tests:
stage: test
script:
- python3 -m unittest discover -s tests -q
- python3 -m compileall -q scripts tests

unit-tests-3.9:
extends: .unit-tests
image: python:3.9

unit-tests-3.13:
extends: .unit-tests
image: python:3.13

shell-scripts:
stage: test
image: debian:stable-slim
before_script:
- apt-get update -qq && apt-get install -y -qq git shellcheck
script:
- for f in $(git ls-files '*.sh'); do bash -n "$f"; done
- shellcheck -S warning $(git ls-files '*.sh')

# --- The Android testers (manual): build the app, then give it to one agent. ---
#
# Runner: tagged `kvm`, with KVM, the Android SDK (ANDROID_HOME) and a booted
# emulator. scripts/android/run_agent.sh assumes an emulator is already up, exactly
# as it does under the GitHub action (reactivecircus/android-emulator-runner), so
# the emulator's lifecycle is the runner's here too.
#
# Project variables to set (Settings > CI/CD > Variables, masked): the model key
# (LLM_API_KEY for llm_base_url, or CLAUDE_CODE_OAUTH_TOKEN for Claude) and
# ARTIFACT_PASSPHRASE, then commit results_public.pem (./setup.sh creates it).
#
# Run it from CI/CD > Pipelines (Run pipeline) or the play button; set PERSONA to
# another persona of personas.json. Everything readable is encrypted before it is
# kept, because the logs of a public repo are public.
android-testers:
stage: testers
tags:
- kvm
when: manual
timeout: 2h
variables:
APP_DIR: demo-app
FRAMEWORK: auto
APP_ID: com.example.tinytodo
PERSONA: anna
BRIEF: AGENT_BRIEF.md
MODEL: sonnet
BLOCK_HOSTS: app.posthog.com eu.i.posthog.com us.i.posthog.com graph.facebook.com api.mixpanel.com api2.amplitude.com
script:
# Fail closed on the template's shipped key, not only on a missing file: PRIVACY.md
# promises the results are encrypted to a key the user holds the private half of.
- |
test -s results_public.pem || { echo "results_public.pem is missing: run ./setup.sh first"; exit 1; }
TEMPLATE_KEY=3852fd09efc2d4fca26e8154e0595b241b82b850ddcc78bbee2961b03fb3a551
KEY=$(sha256sum results_public.pem | cut -d' ' -f1)
[ "$KEY" != "$TEMPLATE_KEY" ] || [ "$CI_PROJECT_PATH" = pierridotite/mobile-agent-testers ] || { echo "results_public.pem is still the template's key: run ./setup.sh, which creates your key and commits it"; exit 1; }
- bash scripts/build/android.sh "$APP_DIR" "$FRAMEWORK"
# LOCALE, DEVICE and GEO come from personas.json for $PERSONA, through the same
# matrix.py the GitHub plan job uses (run_agent.sh reads all three under set -u).
- |
eval "$(PERSONAS="$PERSONA" PLATFORM=android python3 scripts/matrix.py | python3 -c '
import json, sys, shlex
row = json.loads(sys.stdin.read().split("=", 1)[1])[0]
print("export LOCALE=%s DEVICE=%s GEO=%s" % (shlex.quote(row["locale"]), shlex.quote(row["device"]), shlex.quote(row["geo"])))')"
- bash scripts/android/run_agent.sh
after_script:
# The agent can write to the workspace and this step runs a script by name
# afterwards: put the trusted scripts and the public key back first.
- git checkout -- scripts results_public.pem
- bash scripts/encrypt_results.sh "$PERSONA"
artifacts:
when: always
expire_in: 30 days
paths:
- results.enc/
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ On Android, these are `adb shell settings put` calls (`secure high_text_contrast

The workflow is written for GitHub Actions (job matrix, macOS runners, android-emulator-runner). The build scripts, the persona tools and the encryption ([scripts/encrypt_results.sh](scripts/encrypt_results.sh)) are portable: a GitLab CI, Bitrise or Codemagic version would reuse them.

[.gitlab-ci.yml](.gitlab-ci.yml) runs the offline checks on GitLab, and the Android testers on a runner with KVM that reuses [scripts/build/android.sh](scripts/build/android.sh) and [scripts/android/run_agent.sh](scripts/android/run_agent.sh) unchanged; iOS still needs a macOS runner. Bitrise and Codemagic are still open: one per issue.

### More build systems

Framework detection is in [scripts/build/detect.sh](scripts/build/detect.sh), and each framework is one `case` in [scripts/build/android.sh](scripts/build/android.sh) and [scripts/build/ios.sh](scripts/build/ios.sh). Unity or Godot would each be one more case, tested with a stand-in for the build tool.
Expand Down
36 changes: 36 additions & 0 deletions tests/test_gitlab_ci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""The GitLab CI file (.gitlab-ci.yml) runs the same offline checks as
.github/workflows/tests.yml and reuses this repository's own scripts, so it cannot
drift away from them or point at a file that has been moved or renamed."""
import re
import unittest
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
GITLAB = ROOT / ".gitlab-ci.yml"
GITHUB = ROOT / ".github/workflows/tests.yml"
# A repository path a step runs or reads: scripts/build/android.sh, personas.json,
# demo-app... Ends on a name, so a sentence's trailing dot is not read as part of it.
REFERENCE = re.compile(r"\b(?:scripts|docs|briefs|tests|demo-app)/[\w./-]*\w")


class GitLabCI(unittest.TestCase):
def setUp(self):
self.text = GITLAB.read_text(encoding="utf-8")

def test_every_referenced_file_exists(self):
missing = sorted(r for r in set(REFERENCE.findall(self.text)) if not (ROOT / r).exists())
self.assertEqual(missing, [])

def test_it_runs_the_offline_checks_of_the_github_workflow(self):
github = GITHUB.read_text(encoding="utf-8")
for command in ("python3 -m unittest discover -s tests", "shellcheck -S warning"):
self.assertIn(command, github)
self.assertIn(command, self.text)

def test_the_android_job_reuses_the_repository_scripts(self):
self.assertIn("scripts/build/android.sh", self.text)
self.assertIn("scripts/android/run_agent.sh", self.text)


if __name__ == "__main__":
unittest.main()
Loading