Skip to content

Commit 5a42b4e

Browse files
Add orb setup scripts for Amp sandboxes
Fresh Amp orbs now get PHP 8.4 (sury.org, with ext-ds, mbstring, curl, xml, pcntl, posix), Composer, and both composer installs (root + tests) from .agents/setup. Idempotent: warm runs finish in ~3 s. .agents/resume is a fast sanity check; the repo needs no services or auth. Amp-Thread-ID: https://ampcode.com/threads/T-01a17471-f042-716a-b15e-1ed42f78ae54 Co-authored-by: ondrej@mirtes.cz <ondrej@mirtes.cz>
1 parent ff70090 commit 5a42b4e

3 files changed

Lines changed: 93 additions & 0 deletions

File tree

‎.agents/resume‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Fast resume check: this repo needs no databases, tunnels, or auth.
5+
# Only verify the toolchain and autoloader survived the snapshot.
6+
7+
command -v php >/dev/null 2>&1 || { echo "resume: php missing" >&2; exit 1; }
8+
php -r 'require "vendor/autoload.php";' 2>/dev/null || {
9+
echo "resume: vendor/autoload.php missing, run .agents/setup" >&2;
10+
exit 1;
11+
}

‎.agents/setup‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Orb setup for phpstan/phpstan-src: PHP toolchain + composer dependencies.
5+
# Idempotent: skips whatever the (possibly stale) snapshot already provides.
6+
7+
log() { printf '[setup] %s\n' "$*" >&2; }
8+
9+
# Amp runs setup either as root or as the unprivileged orb user with passwordless sudo.
10+
as_root() {
11+
if [ "$(id -u)" -eq 0 ]; then
12+
"$@"
13+
else
14+
sudo "$@"
15+
fi
16+
}
17+
18+
PHP_VERSION=8.4
19+
20+
# --- base utilities -------------------------------------------------------
21+
missing_pkgs=()
22+
command -v curl >/dev/null 2>&1 || missing_pkgs+=(ca-certificates curl)
23+
command -v unzip >/dev/null 2>&1 || missing_pkgs+=(unzip)
24+
command -v patch >/dev/null 2>&1 || missing_pkgs+=(patch)
25+
if [ "${#missing_pkgs[@]}" -gt 0 ]; then
26+
export DEBIAN_FRONTEND=noninteractive
27+
as_root apt-get update -qq
28+
as_root apt-get install -y -qq "${missing_pkgs[@]}" >/dev/null
29+
fi
30+
31+
# --- PHP -------------------------------------------------------------------
32+
need_php=1
33+
if command -v php >/dev/null 2>&1 \
34+
&& php -r 'exit(version_compare(PHP_VERSION, "8.2", "<") ? 1 : 0);' 2>/dev/null \
35+
&& php -m 2>/dev/null | grep -qix '^ds$' \
36+
&& php -m 2>/dev/null | grep -qix '^mbstring$'; then
37+
need_php=0
38+
log "PHP $(php -r 'echo PHP_VERSION;') already installed"
39+
fi
40+
41+
if [ "$need_php" -eq 1 ]; then
42+
log "Installing PHP ${PHP_VERSION} from deb.sury.org (Debian's own PHP has no ext-ds)"
43+
export DEBIAN_FRONTEND=noninteractive
44+
as_root apt-get update -qq
45+
as_root apt-get install -y -qq ca-certificates curl gnupg >/dev/null
46+
as_root curl -fsSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
47+
printf 'deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ bookworm main\n' | as_root tee /etc/apt/sources.list.d/php.list > /dev/null
48+
as_root apt-get update -qq
49+
as_root apt-get install -y -qq \
50+
"php${PHP_VERSION}-cli" \
51+
"php${PHP_VERSION}-mbstring" \
52+
"php${PHP_VERSION}-ds" \
53+
"php${PHP_VERSION}-curl" \
54+
"php${PHP_VERSION}-xml" \
55+
>/dev/null
56+
as_root update-alternatives --set php "/usr/bin/php${PHP_VERSION}" >/dev/null 2>&1 || true
57+
log "Installed PHP $(php -r 'echo PHP_VERSION;')"
58+
fi
59+
60+
# CI runs with memory_limit=-1; the test runner needs it for big analyses.
61+
if [ -d "/etc/php/${PHP_VERSION}/cli" ]; then
62+
printf 'memory_limit=-1\n' | as_root tee "/etc/php/${PHP_VERSION}/cli/conf.d/99-amp-memory.ini" > /dev/null
63+
fi
64+
65+
# --- Composer ---------------------------------------------------------------
66+
if ! command -v composer >/dev/null 2>&1; then
67+
log "Installing Composer"
68+
as_root curl -fsSS https://getcomposer.org/installer | as_root php -- \
69+
--install-dir=/usr/local/bin --filename=composer --quiet
70+
fi
71+
log "Using $(composer --version 2>/dev/null | head -1)"
72+
73+
# --- Dependencies -----------------------------------------------------------
74+
# composer.json pins config.platform php 8.2.99, so any >= 8.2 runtime installs
75+
# the same lockfile. Patches are applied by cweagans/composer-patches on install.
76+
log "composer install (root)"
77+
composer install --no-interaction --no-progress
78+
log "composer install (tests: paratest, phpbench, phpunit)"
79+
composer install --working-dir tests --no-interaction --no-progress
80+
81+
log "setup complete"

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
tmp/.memory_limit
1616
e2e/bashunit
1717
/.phpbench
18+
/.amp/portals/
1819
/e2e/turbo-arena/tmp
1920
/e2e/fork-unsafe-extension/tmp
2021
/e2e/result-cache-atomic-save/tmp

0 commit comments

Comments
 (0)