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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ root of a clean checkout of the branch, with:

| Variable | Value |
|---|---|
| `VT_PLATFORM` | `android` or `ios` |
| `VT_OUTPUT` | where the script must write the app: a `.apk` (Android) or a signed `.ipa` (iOS) |
| `VT_BRANCH` | the branch being built |
| `VT_CASES` | comma-separated case names |
| `VT_REQUEST_ID` | the viewer's build id |
| `MT_PLATFORM` | `android` or `ios` |
| `MT_OUTPUT` | where the script must write the app: a `.apk` (Android) or a signed `.ipa` (iOS) |
| `MT_BRANCH` | the branch being built |
| `MT_CASES` | comma-separated case names |
| `MT_REQUEST_ID` | the viewer's build id |

Exit status `0` with a non-empty file at `VT_OUTPUT` is a successful build;
Exit status `0` with a non-empty file at `MT_OUTPUT` is a successful build;
anything else is a build error, reported with the script's last `error:` lines
and its log.

Expand Down
16 changes: 8 additions & 8 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
(shallow, credentials per command through GIT_CONFIG_* env: never in
.git/config, the remote URL, argv or the log),
2. run each chosen platform's recipe (`bash .monkeytester/build-<p>.sh`) in its
own process group with VT_PLATFORM / VT_OUTPUT / VT_BRANCH / VT_CASES /
VT_REQUEST_ID, under a per-platform timeout,
own process group with MT_PLATFORM / MT_OUTPUT / MT_BRANCH / MT_CASES /
MT_REQUEST_ID, under a per-platform timeout,
3. upload through the viewer's submit.py (`--no-wait`): built apps, and the
error + log of the platforms that failed.

Expand Down Expand Up @@ -445,11 +445,11 @@ def _build(self, ref, rec, out, logf, note):
self._job(ref, p, "in_progress")
app = out / APP_NAMES[p]
plog = out / f"{p}-build.log"
note(f"{JOB_NAMES[p]}: bash {RECIPES[p]} (VT_OUTPUT={app})")
note(f"{JOB_NAMES[p]}: bash {RECIPES[p]} (MT_OUTPUT={app})")
timeout = platform_timeout(p)
env = child_env({"VT_PLATFORM": p, "VT_OUTPUT": str(app), "VT_BRANCH": branch,
"VT_CASES": ",".join(rec.get("cases") or []),
"VT_REQUEST_ID": rec["request_id"]})
env = child_env({"MT_PLATFORM": p, "MT_OUTPUT": str(app), "MT_BRANCH": branch,
"MT_CASES": ",".join(rec.get("cases") or []),
"MT_REQUEST_ID": rec["request_id"]})
with open(plog, "ab") as pf:
rc, outcome = self._run(["bash", RECIPES[p]], checkout, env, [logf, pf], timeout)
if outcome == "timeout":
Expand All @@ -460,7 +460,7 @@ def _build(self, ref, rec, out, logf, note):
msg = build_error_message(plog)
if not msg:
msg = (f"build script exited with status {rc}" if rc != 0
else "build script exited with status 0 but wrote no app at VT_OUTPUT")
else "build script exited with status 0 but wrote no app at MT_OUTPUT")
if msg:
failed[p] = (msg, plog)
note(f"{JOB_NAMES[p]}: failed: {msg}")
Expand Down Expand Up @@ -563,7 +563,7 @@ def _upload(self, rec, checkout, out, built, failed, logf, note):
# starting with "-" (an error line) can't be taken for another option.
for p, (msg, plog) in failed.items():
argv += [f"--{p}-build-error={msg}", f"--{p}-build-log", str(plog)]
argv += ["--tests-dir", "visual-tests", f"--branch={rec['branch']}", f"--repo={rec['repo']}",
argv += ["--tests-dir", "mt-tests", f"--branch={rec['branch']}", f"--repo={rec['repo']}",
f"--cases={','.join(rec.get('cases') or [])}", f"--build-request={rec['request_id']}",
"--timeout", str(SUBMIT_WAIT)]
note("Upload: python3 submit.py " + " ".join(argv[3:]))
Expand Down
4 changes: 2 additions & 2 deletions sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

PLATFORMS = ("android", "ios")
RECIPES = {"android": ".monkeytester/build-android.sh", "ios": ".monkeytester/build-ios.sh"}
CASES_DIR = "visual-tests"
CASES_DIR = "mt-tests"


class SourceError(Exception):
Expand All @@ -45,7 +45,7 @@ def __init__(self, message, code="forge_refused", status=502, forge_status=None)


def cases_from_tree(entries):
"""Case names: visual-tests/<case>/INSTRUCTION.txt blobs in a git tree listing."""
"""Case names: mt-tests/<case>/INSTRUCTION.txt blobs in a git tree listing."""
cases = set()
for entry in entries or []:
if not isinstance(entry, dict):
Expand Down
2 changes: 1 addition & 1 deletion sources/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _branch_commit(cfg, repo, ref):


def _cases_from_contents(cfg, repo, sha):
"""Fallback when the recursive tree is truncated: list visual-tests/ and check
"""Fallback when the recursive tree is truncated: list mt-tests/ and check
each folder for INSTRUCTION.txt through the contents API."""
status, payload = _call(cfg, "GET", f"/repos/{repo}/contents/{CASES_DIR}", params={"ref": sha})
if status == 404:
Expand Down
16 changes: 8 additions & 8 deletions templates/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
# build-local runs it with bash from the root of a clean checkout of the branch
# being built, on the plugin's own host (a Mac, or Linux with the Android SDK):
#
# VT_PLATFORM android
# VT_OUTPUT where this script must write the .apk
# VT_BRANCH the branch being built
# VT_CASES comma-separated test case names (empty: every case)
# VT_REQUEST_ID the viewer's build id
# MT_PLATFORM android
# MT_OUTPUT where this script must write the .apk
# MT_BRANCH the branch being built
# MT_CASES comma-separated test case names (empty: every case)
# MT_REQUEST_ID the viewer's build id
#
# Exit 0 with a non-empty file at $VT_OUTPUT = built. Anything else is a build
# Exit 0 with a non-empty file at $MT_OUTPUT = built. Anything else is a build
# error: the plugin reports the output's last "error:" lines and attaches the
# whole output as the build log, and the Android devices show every test as
# Unavailable.
Expand All @@ -21,7 +21,7 @@
# - the APK path (app/build/outputs/apk/debug/app-debug.apk).
set -euo pipefail

: "${VT_OUTPUT:?VT_OUTPUT is not set (this script is run by build-local)}"
: "${MT_OUTPUT:?MT_OUTPUT is not set (this script is run by build-local)}"

# The Android SDK: $ANDROID_HOME / $ANDROID_SDK_ROOT, else the usual places on
# macOS and Linux. Gradle reads it from local.properties.
Expand All @@ -43,4 +43,4 @@ if [ ! -s "$apk" ]; then
echo "error: Gradle produced no APK at $apk" >&2
exit 1
fi
cp "$apk" "$VT_OUTPUT"
cp "$apk" "$MT_OUTPUT"
18 changes: 9 additions & 9 deletions templates/build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# being built, on the plugin's Mac (Xcode, and the signing identity in the
# login keychain of the user the plugin runs as):
#
# VT_PLATFORM ios
# VT_OUTPUT where this script must write the signed .ipa
# VT_BRANCH the branch being built
# VT_CASES comma-separated test case names (empty: every case)
# VT_REQUEST_ID the viewer's build id
# MT_PLATFORM ios
# MT_OUTPUT where this script must write the signed .ipa
# MT_BRANCH the branch being built
# MT_CASES comma-separated test case names (empty: every case)
# MT_REQUEST_ID the viewer's build id
#
# Exit 0 with a non-empty file at $VT_OUTPUT = built. Anything else is a build
# Exit 0 with a non-empty file at $MT_OUTPUT = built. Anything else is a build
# error: the plugin reports the output's last "error:" lines (xcodebuild's
# "error: ..." lines, e.g. signing) and attaches the whole output as the build
# log, and the iPhones show every test as Unavailable. Android is still built
Expand All @@ -31,9 +31,9 @@
# phone connected) before its first build.
set -euo pipefail

: "${VT_OUTPUT:?VT_OUTPUT is not set (this script is run by build-local)}"
: "${MT_OUTPUT:?MT_OUTPUT is not set (this script is run by build-local)}"

out=build/visual-test
out=build/monkeytester
mkdir -p "$out"

# BUILD: archive, then export a signed .ipa. Replace project, scheme and
Expand All @@ -57,4 +57,4 @@ if [ -z "$ipa" ]; then
echo "error: xcodebuild exported no .ipa" >&2
exit 1
fi
cp "$ipa" "$VT_OUTPUT"
cp "$ipa" "$MT_OUTPUT"
4 changes: 2 additions & 2 deletions tests/fake_gitea.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
READ_ONLY = "read-only-token-9999"
REPO = "blackjackfruit/TemperatureSensor-App"
RECIPES = [".monkeytester/build-android.sh", ".monkeytester/build-ios.sh"]
DEFAULT_FILES = ["README.md", *RECIPES, "visual-tests/onboarding/INSTRUCTION.txt",
"visual-tests/device-setup/INSTRUCTION.txt", "visual-tests/notes.txt"]
DEFAULT_FILES = ["README.md", *RECIPES, "mt-tests/onboarding/INSTRUCTION.txt",
"mt-tests/device-setup/INSTRUCTION.txt", "mt-tests/notes.txt"]


class State:
Expand Down
26 changes: 13 additions & 13 deletions tests/test_build_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

# ─── fixture repo files (branch: {path: content}) ───

ANDROID_OK = '#!/bin/bash\necho "android build: starting"\nprintf fake-apk-bytes > "$VT_OUTPUT"\n'
IOS_OK = '#!/bin/bash\necho "ios build: starting"\nprintf fake-ipa-bytes > "$VT_OUTPUT"\n'
ANDROID_OK = '#!/bin/bash\necho "android build: starting"\nprintf fake-apk-bytes > "$MT_OUTPUT"\n'
IOS_OK = '#!/bin/bash\necho "ios build: starting"\nprintf fake-ipa-bytes > "$MT_OUTPUT"\n'
IOS_FAIL = ('#!/bin/bash\n'
'echo "ios build: starting"\n'
'echo "ios build: error: signing"\n'
Expand All @@ -57,16 +57,16 @@
ANDROID_FAIL = '#!/bin/bash\necho "android build: error: gradle exited 1"\nexit 1\n'
SLOW = ('#!/bin/bash\n'
'echo "slow-build: starting"\n'
'pids="${VT_OUTPUT%/*}/pids.txt"\n'
'pids="${MT_OUTPUT%/*}/pids.txt"\n'
'printf \'%s\\n\' "$$" > "$pids"\n'
'sleep 600 &\n'
'printf \'%s\\n\' "$!" >> "$pids"\n'
'sleep 600\n')

CASE_FILES = {
"visual-tests/onboarding/INSTRUCTION.txt": "follow the onboarding flow",
"visual-tests/device-setup/INSTRUCTION.txt": "set up the device",
"visual-tests/notes.txt": "not a case",
"mt-tests/onboarding/INSTRUCTION.txt": "follow the onboarding flow",
"mt-tests/device-setup/INSTRUCTION.txt": "set up the device",
"mt-tests/notes.txt": "not a case",
}
MASTER_FILES = {"README.md": "app", ANDROID_RECIPE: ANDROID_OK, IOS_RECIPE: IOS_OK, **CASE_FILES}
FIXTURE_BRANCHES = {
Expand All @@ -76,7 +76,7 @@
"feat/slow": {"README.md": "app", ANDROID_RECIPE: SLOW, **CASE_FILES},
"feat/no-ios": {"README.md": "app", ANDROID_RECIPE: ANDROID_OK, **CASE_FILES},
"feat/dash-error": {"README.md": "app", ANDROID_RECIPE: '#!/bin/bash\necho "error: --android-app=/etc/passwd"\nexit 1\n', **CASE_FILES},
"feat/env-dump": {"README.md": "app", ANDROID_RECIPE: '#!/bin/bash\nenv > "$VT_OUTPUT"\n', **CASE_FILES},
"feat/env-dump": {"README.md": "app", ANDROID_RECIPE: '#!/bin/bash\nenv > "$MT_OUTPUT"\n', **CASE_FILES},
}
GHOST_FILES = {"README.md": "app", ANDROID_RECIPE: "exit 0\n", IOS_RECIPE: "exit 0\n"}
API_FILES = {branch: {path: content for path, content in files.items()}
Expand Down Expand Up @@ -578,7 +578,7 @@ def test_truncated_tree_falls_back_to_contents(self):
self.assertEqual(status, 200, body)
self.assertEqual(body["cases"], ["device-setup", "onboarding"])
self.assertEqual(body["recipes"], {"android": True, "ios": True})
self.assertTrue(any("/contents/visual-tests" in r[1] for r in self.gh.calls()))
self.assertTrue(any("/contents/mt-tests" in r[1] for r in self.gh.calls()))

def test_branches_default_first_github(self):
status, body = self.call("GET", f"/repos/{REPO}/branches")
Expand Down Expand Up @@ -882,9 +882,9 @@ def setUp(self):
self.start_plugin()

def test_template_served_as_plain_text(self):
for platform, needles in (("android", ("gradlew assembleDebug", "VT_OUTPUT", "set -euo pipefail",
for platform, needles in (("android", ("gradlew assembleDebug", "MT_OUTPUT", "set -euo pipefail",
"sdk.dir")),
("ios", ("xcodebuild archive", "exportArchive", "VT_OUTPUT",
("ios", ("xcodebuild archive", "exportArchive", "MT_OUTPUT",
"set -euo pipefail", "UDID"))):
status, raw, hdrs = self.call("GET", f"/template?platform={platform}", raw=True)
self.assertEqual(status, 200)
Expand Down Expand Up @@ -994,11 +994,11 @@ def test_write_private_json_mode_and_atomicity(self):
def test_child_env_drops_plugin_secrets(self):
with patch.dict(os.environ, {"PLUGIN_TOKEN": "s3cret-pair", "BUILD_LOCAL_IMPORT": "/x",
"SOMETHING_ELSE": "keep"}):
env = build_runner.child_env({"VT_PLATFORM": "android"})
env = build_runner.child_env({"MT_PLATFORM": "android"})
self.assertNotIn("PLUGIN_TOKEN", env)
self.assertNotIn("BUILD_LOCAL_IMPORT", env)
self.assertEqual(env["SOMETHING_ELSE"], "keep")
self.assertEqual(env["VT_PLATFORM"], "android")
self.assertEqual(env["MT_PLATFORM"], "android")



Expand Down Expand Up @@ -1203,7 +1203,7 @@ def test_build_script_never_sees_the_pairing_token(self):
body = self.wait_state(ref)
self.assertEqual(body["conclusion"], "success", body)
dumped = (self.out_dir(ref) / "app.apk").read_text()
self.assertIn("VT_PLATFORM=android", dumped)
self.assertIn("MT_PLATFORM=android", dumped)
self.assertNotIn("PLUGIN_TOKEN", dumped)
self.assertNotIn("pair-token-in-env-5678", dumped)
self.assertNotIn("BUILD_LOCAL_IMPORT", dumped)
Expand Down
Loading