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
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-24.04, ubuntu-22.04, windows-2025, windows-2022]
php: ['5.4', '5.5', '5.6', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '7.2.11', '7.2.12', '8.1.9', '8.2', '8.3', '8.4']
php: ['5.4', '5.5', '5.6', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '7.2.11', '7.2.12', '8.1.9', '8.2', '8.3', '8.4', '8.5']
exclude:
- os: windows-2022
php: 5.4
Expand Down
101 changes: 91 additions & 10 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## Project Overview

This is a GitHub Action called `setup-php` that sets up PHP environments in GitHub Actions workflows. It supports installing various PHP versions (5.4-8.3) on Ubuntu and Windows platforms using different installation methods (apt, phpenv, chocolatey).
This is a GitHub Action called `setup-php` that sets up PHP environments in GitHub Actions workflows. It supports installing various PHP versions (5.4-8.5) on Ubuntu and Windows platforms using different installation methods (apt, phpenv, chocolatey).

**Supported Versions:**
- PHP 5.4-5.5 (ubuntu-22.04 only)
- PHP 5.6-8.5
- Patch versions supported (e.g., 7.2.11) except PHP 8.4 and 8.5
- Snapshot versions supported (e.g., 8.2snapshot)

**Supported Platforms:**
- ubuntu-latest, ubuntu-24.04, ubuntu-22.04
- windows-latest, windows-2025, windows-2022

## Development Commands

Expand Down Expand Up @@ -32,19 +42,43 @@ The project uses Husky pre-commit hooks that automatically:
- `choco-install-php-windows.ps1` - Chocolatey-based installation for Windows

### Installation Strategy
The installer chooses installation method based on:

The installer (src/installer.ts) chooses installation method based on:

1. **Platform detection** (Linux vs Windows)
2. **Version format** (patch version vs major.minor)
3. **APT availability** for specific PHP versions
2. **Version format** - `hasPatchVersion()` checks if specific patch version requested
3. **APT availability** - `hasAptVersion()` checks if version available via APT

**Linux Installation Logic:**
- APT method: Used for major.minor versions (5.6, 7.0-7.4, 8.0-8.5) without patch version
- Calls `lib/apt-install-php-ubuntu.sh`
- Uses ondrej/php PPA for versions not in default repos
- Installs common extensions (bcmath, curl, gd, mbstring, mysql, etc.)
- OPcache handling:
- PHP < 8.5: Installs php${version}-opcache package separately
- PHP 8.5+: OPcache bundled in core (no separate package)
- Configures OPcache with JIT for PHP 8.1+
- phpenv method: Used for patch versions or unsupported APT versions
- Calls `lib/phpenv-install-php-ubuntu.sh`
- Compiles PHP from source with custom configure options
- Builds OpenSSL 1.0.2 and PostgreSQL 9.6 from source
- Handles snapshot versions (e.g., 8.2snapshot from GitHub)

For Linux:
- Uses APT for major.minor versions (5.6, 7.0-7.4, 8.0-8.3) when no patch version specified
- Falls back to phpenv for patch versions or unsupported APT versions
**Windows Installation:**
- Uses Chocolatey via `lib/choco-install-php-windows.ps1`
- Special handling: PHP 7.3 limited to 7.3.30 on Windows

### Version Handling
- **convertInstallVersion()** fetches latest patch versions from php.net API

**convertInstallVersion()** in src/installer.ts:
- Fetches latest patch versions from php.net API (`PHP_RELEASES_URL`)
- Falls back to hardcoded versions if API fails
- Special handling for Windows chocolatey version limitations
- Returns major versions (5, 7, 8) as-is for flexibility
- Special case: Windows PHP 7.3 → 7.3.30

**Version Detection Functions:**
- `hasPatchVersion()`: Returns true if version is specific patch (e.g., 7.2.11) or snapshot
- `hasAptVersion()`: Returns true if version is 5.6 or 7.0-8.5 (major.minor only)

## Build Output Structure

Expand All @@ -59,4 +93,51 @@ This project follows GitHub Actions conventions:
Tests are in `__tests__/run.test.ts` and cover:
- Version parsing logic (`hasPatchVersion`, `hasAptVersion`)
- Version conversion functionality (`convertInstallVersion`)
- Uses Jest with 10-second timeout for API calls
- Uses Jest with 10-second timeout for API calls

**Note:** Some tests are commented out because they depend on the latest PHP versions available at php.net, which change over time.

## CI/CD Workflow

The project uses GitHub Actions (`workflow.yml`) to test:
- **Matrix testing** across OS versions (ubuntu-24.04, ubuntu-22.04, windows-2025, windows-2022)
- **PHP versions** from 5.4 to 8.5, including specific patch versions (7.2.11, 7.2.12, 8.1.9)
- **Exclusions** for unsupported combinations (e.g., PHP 5.4 on Windows, PHP 5.4/5.5 on ubuntu-24.04)

Workflow steps:
1. Checkout code
2. Run `npm install` and `npm test` (Ubuntu only)
3. Remove node_modules (to test action in clean state)
4. Run the action itself with matrix PHP version
5. Verify installation with `php -i` and `php -m`

## Important Implementation Details

### Husky Pre-commit Hook
The project commits production dependencies to git:
- Pre-commit: Runs `npm run build` and `npm run format`
- Post-commit: Runs `npm prune --production` and commits pruned node_modules

This is standard for GitHub Actions to avoid requiring npm install during action execution.

### Shell Script Conventions
- All shell scripts use `set -eo pipefail` for strict error handling
- Use `apt-fast` wrapper (links to apt-get if not available) for faster package installation
- Use `update-alternatives` to set PHP version as default

### Key Files to Modify
- **src/installer.ts** - When adding new version logic or installation methods
- **lib/*.sh** or **lib/*.ps1** - When modifying installation scripts
- **action.yml** - When changing action inputs or metadata
- **__tests__/run.test.ts** - When adding new test cases

### Version Support Updates
When adding support for new PHP versions:
1. Update `hasAptVersion()` in src/installer.ts if APT supports the version
2. Add fallback version in `convertInstallVersion()` catch block
3. Update README.md to list the new version
4. Update workflow.yml matrix to test the new version
5. Check if the new version bundles extensions (like opcache in PHP 8.5+)
- Update `lib/apt-install-php-ubuntu.sh` to exclude bundled extensions
6. Run `npm run build && npm run package` to update dist/index.js
7. Test both APT and phpenv installation methods
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ This action sets up a PHP environment for use in actions by:
- 8.2
- 8.3
- 8.4
- 8.5

*Patch version can also be set. e.g. 7.2.11*

*Note: PHP 8.4 does not support patch versions yet.*
*Note: PHP 8.4 and 8.5 do not support patch versions yet.*

## OS/Platform support

Expand Down
1 change: 1 addition & 0 deletions __tests__/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('example tests', () => {
expect(installer.hasAptVersion('8.2')).toBe(true);
expect(installer.hasAptVersion('8.3')).toBe(true);
expect(installer.hasAptVersion('8.4')).toBe(true);
expect(installer.hasAptVersion('8.5')).toBe(true);
});
it('convertInstallVersion tests', async () => {
expect(await installer.convertInstallVersion('5')).toBe('5');
Expand Down
Loading