Skip to content

Commit 4e50147

Browse files
committed
Add .agents/setup for Amp orbs
Installs PHP 8.4 (Sury), Composer, project dependencies, build-cs, and the phplrt grammar toolchain so lint, cs, tests, and PHPStan run in fresh orbs. Amp-Thread-ID: https://ampcode.com/threads/T-01a1779d-adc0-777b-8b16-ab38bbd22bdc
1 parent cca6272 commit 4e50147

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

‎.agents/setup‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
# Prepares an Amp orb (Debian 12) to build, test, and analyse this repository.
3+
# Idempotent: a warm run skips installs that are already in place.
4+
set -euo pipefail
5+
6+
cd "$(dirname "$0")/.."
7+
8+
step() {
9+
local name="$1"
10+
shift
11+
local start=$SECONDS
12+
echo "==> $name"
13+
"$@"
14+
echo "<== $name ($((SECONDS - start))s)"
15+
}
16+
17+
# PHP 8.4 runs everything: the library itself (platform pinned to 7.4.6 in
18+
# composer.json), and tools/phplrt, whose grammar compiler requires 8.4.
19+
PHP_VERSION=8.4
20+
PHP_PACKAGES=(
21+
"php$PHP_VERSION-cli"
22+
"php$PHP_VERSION-mbstring"
23+
"php$PHP_VERSION-xml"
24+
"php$PHP_VERSION-curl"
25+
"php$PHP_VERSION-zip"
26+
)
27+
28+
install_php() {
29+
local missing=()
30+
for pkg in "${PHP_PACKAGES[@]}"; do
31+
dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q 'install ok installed' || missing+=("$pkg")
32+
done
33+
if [ ${#missing[@]} -eq 0 ]; then
34+
echo "PHP $PHP_VERSION packages already installed"
35+
return
36+
fi
37+
38+
if [ ! -f /etc/apt/sources.list.d/php-sury.list ]; then
39+
sudo install -d -m 0755 /etc/apt/keyrings
40+
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo tee /etc/apt/keyrings/php-sury.gpg >/dev/null
41+
echo "deb [signed-by=/etc/apt/keyrings/php-sury.gpg] https://packages.sury.org/php/ $(. /etc/os-release && echo "$VERSION_CODENAME") main" \
42+
| sudo tee /etc/apt/sources.list.d/php-sury.list >/dev/null
43+
fi
44+
sudo apt-get update -qq
45+
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends "${missing[@]}"
46+
}
47+
48+
install_composer() {
49+
if command -v composer >/dev/null 2>&1; then
50+
echo "Composer already installed: $(composer --version 2>/dev/null)"
51+
return
52+
fi
53+
local tmp
54+
tmp="$(mktemp -d)"
55+
curl -fsSL https://getcomposer.org/installer -o "$tmp/composer-setup.php"
56+
php "$tmp/composer-setup.php" --quiet --install-dir="$tmp" --filename=composer
57+
sudo install -m 0755 "$tmp/composer" /usr/local/bin/composer
58+
rm -rf "$tmp"
59+
}
60+
61+
# composer.lock is git-ignored, so the first run resolves dependencies like CI
62+
# does; later runs reuse the restored lock and vendor directory.
63+
install_dependencies() {
64+
composer install --no-interaction --no-progress
65+
}
66+
67+
# Coding standard used by `make cs` / `make cs-fix`.
68+
install_build_cs() {
69+
if [ ! -d build-cs/.git ]; then
70+
git clone --quiet --branch 2.x https://github.com/phpstan/build-cs.git build-cs
71+
fi
72+
composer install --no-interaction --no-progress --working-dir build-cs
73+
}
74+
75+
# Grammar toolchain used by FuzzyTest and GrammarSyncTest (`make grammars-install`).
76+
install_grammars() {
77+
composer install --no-interaction --no-progress --working-dir tools/phplrt
78+
}
79+
80+
step "Install PHP $PHP_VERSION" install_php
81+
step "Install Composer" install_composer
82+
step "Install dependencies" install_dependencies
83+
step "Install build-cs" install_build_cs
84+
step "Install grammar toolchain" install_grammars

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/vendor
77
/composer.lock
88
.phpunit.result.cache
9+
/.amp/portals/*

0 commit comments

Comments
 (0)