Compare commits

..

19 Commits

Author SHA1 Message Date
Shivam Mathur d76a76348c Limit Windows extension recovery overhead to DLL replacements 2026-09-19 19:47:44 +05:30
dependabot[bot] 84a5f1c061 Bump the github-actions group with 3 updates (#1122)
Bumps the github-actions group with 3 updates: [github/codeql-action/init](https://github.com/github/codeql-action), [github/codeql-action/autobuild](https://github.com/github/codeql-action) and [github/codeql-action/analyze](https://github.com/github/codeql-action).


Updates `github/codeql-action/init` from 4.37.9 to 4.38.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/cdf488f595d80d6e07e03d4674febd5ab45fa938...b96794f015dfd88f77b49b1c93e0fa7110f94c63)

Updates `github/codeql-action/autobuild` from 4.37.9 to 4.38.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/cdf488f595d80d6e07e03d4674febd5ab45fa938...b96794f015dfd88f77b49b1c93e0fa7110f94c63)

Updates `github/codeql-action/analyze` from 4.37.9 to 4.38.0
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/cdf488f595d80d6e07e03d4674febd5ab45fa938...b96794f015dfd88f77b49b1c93e0fa7110f94c63)

---
updated-dependencies:
- dependency-name: github/codeql-action/init
  dependency-version: 4.38.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
- dependency-name: github/codeql-action/autobuild
  dependency-version: 4.38.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.38.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: github-actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-09-19 19:16:55 +05:30
Shivam Mathur 72c642301a Preserve active Windows extensions before probing cached DLLs 2026-09-18 12:01:55 +05:30
Shivam Mathur ed2b57d93d Preserve startup error settings during Windows extension changes 2026-09-18 12:00:30 +05:30
Shivam Mathur 75fa893d48 Improve parsing .php-version and tests 2026-09-17 20:53:52 +05:30
Sviatoslav Abakumov 0bbee91078 Support all valid PHP version file values (#1121)
* Support all valid PHP version file values

Allow version files to use partial versions and aliases accepted by the
php-version input while preserving support for both plain .php-version
files and asdf-style php entries.

* Regenerate bundled action

---------

Co-authored-by: Shivam Mathur <shivam_jpr@hotmail.com>
2026-09-17 20:17:54 +05:30
Shivam Mathur e3f88f3ca7 Enable fileinfo for Laravel Cloud CLI 2026-09-16 18:18:36 +05:30
Shivam Mathur 870fe79ecc Verify cached Windows extensions load before reusing them 2026-09-16 18:18:09 +05:30
Shivam Mathur 25618cc48e Cache replaced Windows extensions by their installed version 2026-09-16 11:25:07 +05:30
Shivam Mathur 5eaed2e30b Validate restored versioned extensions before reporting success 2026-09-16 09:16:04 +05:30
Shivam Mathur 85dc78fbb0 Preserve Composer checksum pins for full version suffixes 2026-09-16 05:37:39 +05:30
Shivam Mathur 83c9e52793 docs: deprecate macOS 14 arm64 runners in support note 2026-09-16 04:14:38 +05:30
Shivam Mathur 9af3b52286 Document deprecated Intel macOS runner support 2026-09-12 00:33:02 +05:30
Shivam Mathur 0e80ac5270 Restore explicit TypeScript checking in CI 2026-09-12 00:33:02 +05:30
Shivam Mathur ea331059db Try the expected extension version before unpinned PECL fallback 2026-09-12 00:33:02 +05:30
Shivam Mathur 3ad6232c89 Preserve PowerShell return values in verbose mode 2026-09-12 00:32:55 +05:30
Shivam Mathur 2ec764e0ab Compare complete Windows extension versions 2026-09-12 00:32:42 +05:30
Shivam Mathur e6ee35895b Require full tool versions for checksum pinning 2026-09-11 20:49:43 +05:30
Shivam Mathur 0c6410c670 Fix Homebrew timeout cleanup and retry propagation 2026-09-11 14:20:07 +05:30
16 changed files with 249 additions and 530 deletions
+3 -3
View File
@@ -26,13 +26,13 @@ jobs:
persist-credentials: false persist-credentials: false
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4 uses: github/codeql-action/init@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
with: with:
config-file: ./.github/codeql/codeql-configuration.yml config-file: ./.github/codeql/codeql-configuration.yml
languages: javascript languages: javascript
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4 uses: github/codeql-action/autobuild@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4 uses: github/codeql-action/analyze@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
+3
View File
@@ -52,6 +52,9 @@ jobs:
- name: ESLint Check - name: ESLint Check
run: npm run lint run: npm run lint
- name: TypeScript Check
run: npm run typecheck
- name: Run tests - name: Run tests
run: npm test run: npm test
+6 -1
View File
@@ -81,6 +81,11 @@ Both `GitHub-hosted` and `self-hosted` runners are supported by `setup-php` on t
| macOS Tahoe 26.x | arm64 | `macos-26` | - | | macOS Tahoe 26.x | arm64 | `macos-26` | - |
| macOS Sequoia 15.x | arm64 | `macos-latest` or `macos-15` | - | | macOS Sequoia 15.x | arm64 | `macos-latest` or `macos-15` | - |
| macOS Sonoma 14.x | arm64 | `macos-14` | - | | macOS Sonoma 14.x | arm64 | `macos-14` | - |
| macOS Tahoe 26.x | x86_64 | `macos-26-intel` | `PHP 8.5` |
| macOS Sequoia 15.x | x86_64 | `macos-15-intel` | `PHP 8.5` |
> [!NOTE]
> Support for Intel (`x86_64`) macOS runners and macOS Sonoma 14.x (`macos-14`) arm64 runners is deprecated and will be removed completely in a future release of `setup-php`. We recommend migrating to arm64-based macOS runners running macOS 15 or newer, such as `macos-26` or `macos-15`.
### Self-Hosted Runners ### Self-Hosted Runners
@@ -272,7 +277,7 @@ These tools can be set up globally using the `tools` input. It accepts a string
tools: composer:2.9.8@sha256:59b2c50e10cafa0d8efc19ede9a326d782f096c674a26baf98cf042ce23de890 tools: composer:2.9.8@sha256:59b2c50e10cafa0d8efc19ede9a326d782f096c674a26baf98cf042ce23de890
``` ```
Checksum verification is supported for tools which are downloaded as phar archives. It is not supported for tools set up using `composer` packages or custom package scripts, specifying a checksum for these tools will result in an error. For checksum pinning to be effective, pin the tool to an exact version, as mutable versions like `latest` or `major.minor` can resolve to a different release with a different checksum. Checksum verification is supported only for tools downloaded as phar archives with a full version, such as `tool:1.2.3` or `tool:1.2.3-beta1`. Specifying a checksum with an omitted version, a variable tag such as `latest`, `stable`, `preview` or `snapshot`, or a partial version such as `2`, `2.x`, `2.9` or `2.9.x` results in an error. These versions can resolve to different releases with different checksums. Checksum verification is not supported for tools set up using `composer` packages or custom package scripts; specifying a checksum for these tools also results in an error.
- The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying the major version `v1` or `v2`, or the version in `major.minor` or `semver` format. Additionally, for composer `snapshot` and `preview` can also be specified to set up the respective releases. - The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying the major version `v1` or `v2`, or the version in `major.minor` or `semver` format. Additionally, for composer `snapshot` and `preview` can also be specified to set up the respective releases.
-317
View File
@@ -1,317 +0,0 @@
import {spawn, spawnSync} from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
const brew = fs.readFileSync(
path.join(__dirname, '../src/scripts/tools/brew.sh'),
'utf8'
);
const describeUnix = process.platform === 'win32' ? describe.skip : describe;
describeUnix('Homebrew inactivity watchdog', () => {
let root: string;
let fixture: string;
let buildScript: string;
const pids = () =>
fs.existsSync(path.join(root, 'pids'))
? fs
.readFileSync(path.join(root, 'pids'), 'utf8')
.trim()
.split('\n')
.map(Number)
: [];
const running = (pid: number) => {
const result = spawnSync('ps', ['-p', String(pid), '-o', 'stat='], {
encoding: 'utf8'
});
return result.status === 0 && !result.stdout.trim().startsWith('Z');
};
const cleanup = () => {
for (const pid of pids().reverse()) {
try {
process.kill(pid, 'SIGKILL');
} catch {
// The watchdog may have already terminated this process.
}
}
};
beforeEach(() => {
root = fs.mkdtempSync(path.join(os.tmpdir(), 'setup-php-brew-test-'));
fixture = path.join(root, 'source.cjs');
buildScript = path.join(root, 'Homebrew', 'build.rb');
fs.mkdirSync(path.dirname(buildScript));
fs.symlinkSync(fixture, buildScript);
fs.writeFileSync(
fixture,
`const fs = require('fs');
const {spawn, spawnSync} = require('child_process');
const role = process.argv[2] || 'brew';
const pidFile = process.env.TEST_ROOT + '/pids';
if (role === 'brew') {
if (fs.existsSync(pidFile)) {
for (const pid of fs.readFileSync(pidFile, 'utf8').trim().split('\\n')) {
const state = spawnSync('ps', ['-p', pid, '-o', 'stat='], {encoding: 'utf8'});
if (state.status === 0 && !state.stdout.trim().startsWith('Z')) {
fs.appendFileSync(process.env.TEST_ROOT + '/overlap', pid + '\\n');
}
}
}
fs.appendFileSync(process.env.TEST_ROOT + '/attempts', 'attempt\\n');
process.stdout.write('==> make\\n');
}
fs.appendFileSync(pidFile, process.pid + '\\n');
if (role === 'compiler') {
process.on('SIGTERM', () => {});
if (process.env.TEST_BUILD_DURATION) {
setTimeout(() => process.exit(0), Number(process.env.TEST_BUILD_DURATION));
}
} else {
const script = role === 'brew' ? process.env.TEST_BUILD_SCRIPT : __filename;
const child = spawn(process.execPath, [script, role === 'brew' ? 'builder' : 'compiler'], {
detached: true,
stdio: process.env.TEST_BUILD_STDIO
});
child.on('exit', status => {
if (process.env.TEST_BUILD_DURATION) {
if (role === 'brew') fs.writeFileSync(process.env.TEST_ROOT + '/built', 'done');
const delay = role === 'brew' ? Number(process.env.TEST_AFTER_BUILD_DELAY || 0) : 0;
setTimeout(() => process.exit(status || 0), delay);
}
});
child.unref();
}
setInterval(() => {}, 1000);
`
);
});
afterEach(() => {
cleanup();
fs.rmSync(root, {recursive: true, force: true});
});
const run = (script: string, env: NodeJS.ProcessEnv = {}) =>
new Promise<{status: number | null; stdout: string; stderr: string}>(
(resolve, reject) => {
const child = spawn('bash', ['-c', brew + '\n' + script], {
detached: true,
env: {
...process.env,
TEST_NODE: process.execPath,
TEST_ROOT: root,
TEST_FIXTURE: fixture,
TEST_BUILD_SCRIPT: buildScript,
TEST_BUILD_STDIO: 'ignore',
SETUP_PHP_BREW_WATCHDOG: 'true',
SETUP_PHP_BREW_INACTIVITY_TIMEOUT: '1',
SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT: '1',
SETUP_PHP_BREW_WATCHDOG_POLL: '0.05',
SETUP_PHP_BREW_RETRY_ATTEMPTS: '3',
...env
}
});
let stdout = '';
let stderr = '';
child.stdout.on('data', data => (stdout += data));
child.stderr.on('data', data => (stderr += data));
const timer = setTimeout(() => {
cleanup();
if (child.pid) {
try {
process.kill(-child.pid, 'SIGKILL');
} catch {
// The shell may have just exited.
}
}
reject(new Error('Watchdog did not finish: ' + stderr));
}, 20000);
child.on('error', error => {
clearTimeout(timer);
reject(error);
});
child.on('close', status => {
clearTimeout(timer);
resolve({status, stdout, stderr});
});
}
);
it.each(['ignore', 'inherit'])(
'kills the complete source-build tree with %s stdio before returning',
async stdio => {
const result = await run(
'run_with_inactivity_watchdog "$TEST_NODE" "$TEST_FIXTURE"',
{TEST_BUILD_STDIO: stdio}
);
expect(result.status).toBe(124);
expect(pids()).toHaveLength(3);
expect(pids().filter(running)).toEqual([]);
expect(result.stderr).toContain('brew produced no output');
expect(result.stderr).not.toContain('retrying');
},
25000
);
it('cleans up each timed-out build before retrying, then stops at the limit', async () => {
const result = await run(`
brew() { "$TEST_NODE" "$TEST_FIXTURE"; }
sleep() { case "$1" in 5|10) return 0;; *) command sleep "$@";; esac; }
safe_brew install php@8.4
`);
expect(result.status).toBe(124);
expect(fs.readFileSync(path.join(root, 'attempts'), 'utf8')).toBe(
'attempt\nattempt\nattempt\n'
);
expect(fs.existsSync(path.join(root, 'overlap'))).toBe(false);
expect(pids().filter(running)).toEqual([]);
expect(result.stderr.match(/retrying brew command/g)).toHaveLength(2);
expect(result.stderr).not.toContain('attempt 4');
}, 25000);
it('recovers on the next attempt after cleaning up a timed-out source build', async () => {
const result = await run(`
brew() {
if [ ! -e "$TEST_ROOT/attempts" ]; then
"$TEST_NODE" "$TEST_FIXTURE"
else
echo recovered
fi
}
sleep() { case "$1" in 5) return 0;; *) command sleep "$@";; esac; }
safe_brew install php@8.4
`);
expect(result.status).toBe(0);
expect(result.stdout).toContain('recovered\n');
expect(result.stderr.match(/retrying brew command/g)).toHaveLength(1);
expect(result.stderr).toContain('attempt 2/3, exit 124');
expect(pids().filter(running)).toEqual([]);
}, 10000);
it('retries an ordinary failure and stops after success', async () => {
const result = await run(`
brew() {
if [ ! -e "$TEST_ROOT/failed" ]; then
touch "$TEST_ROOT/failed"
return 37
fi
printf recovered
}
sleep() { case "$1" in 5) return 0;; *) command sleep "$@";; esac; }
safe_brew install php@8.4
`);
expect(result.status).toBe(0);
expect(result.stdout).toBe('recovered');
expect(result.stderr.match(/retrying brew command/g)).toHaveLength(1);
expect(result.stderr).toContain('attempt 2/3, exit 37');
});
it('preserves the opt-out from the watchdog and retries', async () => {
const result = await run(
'brew() { printf disabled; return 37; }; safe_brew install php@8.4',
{SETUP_PHP_BREW_WATCHDOG: 'false'}
);
expect(result).toEqual({status: 37, stdout: 'disabled', stderr: ''});
});
it.each([0, 37])('preserves output and exit status %s', async status => {
const result = await run(
`run_with_inactivity_watchdog bash -c 'printf out; printf err >&2; exit ${status}'`
);
expect(result).toEqual({status, stdout: 'out', stderr: 'err'});
});
it('keeps the bottle timeout when no source build is running', async () => {
const result = await run(
'run_with_inactivity_watchdog "$TEST_NODE" -e "setTimeout(() => {}, 6000)"',
{SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT: '4'}
);
expect(result.status).toBe(124);
expect(result.stderr).toContain('no output for 1s; terminating');
}, 10000);
it('ignores source builds outside the watched process tree', async () => {
const otherBuild = spawn(
process.execPath,
['-e', 'setTimeout(() => {}, 10000)', buildScript],
{stdio: 'ignore'}
);
try {
const result = await run(
'run_with_inactivity_watchdog "$TEST_NODE" -e "setTimeout(() => {}, 6000)"',
{SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT: '4'}
);
expect(result.status).toBe(124);
expect(result.stderr).toContain('no output for 1s; terminating');
} finally {
otherBuild.kill('SIGKILL');
}
}, 10000);
it.each(['', '4'])(
'allows quiet source builds past the bottle timeout with source timeout=%s',
async sourceTimeout => {
const result = await run(
'run_with_inactivity_watchdog "$TEST_NODE" "$TEST_FIXTURE"',
{
SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT: sourceTimeout,
TEST_BUILD_DURATION: '2500'
}
);
expect(result.status).toBe(0);
expect(fs.existsSync(path.join(root, 'built'))).toBe(true);
expect(pids().filter(running)).toEqual([]);
expect(result.stderr).not.toContain('terminating');
},
10000
);
it('terminates a stalled source build at its longer timeout', async () => {
const result = await run(
'run_with_inactivity_watchdog "$TEST_NODE" "$TEST_FIXTURE"',
{SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT: '3'}
);
expect(result.status).toBe(124);
expect(result.stderr).toContain('no output for 3s; terminating');
expect(pids().filter(running)).toEqual([]);
}, 10000);
it('restores the bottle timeout after the source build finishes', async () => {
const result = await run(
'run_with_inactivity_watchdog "$TEST_NODE" "$TEST_FIXTURE"',
{
SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT: '4',
TEST_BUILD_DURATION: '2500',
TEST_AFTER_BUILD_DELAY: '6000'
}
);
expect(result.status).toBe(124);
expect(fs.existsSync(path.join(root, 'built'))).toBe(true);
expect(result.stderr).toContain('no output for 1s; terminating');
expect(pids().filter(running)).toEqual([]);
}, 10000);
it.each(['stdout', 'stderr'] as const)(
'counts partial output on %s as activity',
async stream => {
const result = await run(
`run_with_inactivity_watchdog "$TEST_NODE" -e '
let count = 0;
const timer = setInterval(() => {
process.${stream}.write(".");
if (++count === 25) clearInterval(timer);
}, 100);
'`,
{SETUP_PHP_BREW_INACTIVITY_TIMEOUT: '2'}
);
expect(result.status).toBe(0);
expect(result[stream]).toBe('.'.repeat(25));
expect(result.stderr).not.toContain('terminating');
},
10000
);
});
-151
View File
@@ -1,151 +0,0 @@
import {spawnSync} from 'child_process';
import fs from 'fs';
import path from 'path';
const darwin = fs
.readFileSync(path.join(__dirname, '../src/scripts/darwin.sh'), 'utf8')
.split('\n# Variables\n')[0];
const describeUnix = process.platform === 'win32' ? describe.skip : describe;
describeUnix('macOS PHP installation', () => {
const run = (env: NodeJS.ProcessEnv) =>
spawnSync(
'bash',
[
'-c',
`${darwin}
uname() { echo "$TEST_ARCH"; }
setup_cached_versions() { echo cache; return "$TEST_CACHE_STATUS"; }
update_dependencies() { echo update; }
add_brew_tap() { echo tap; }
safe_brew() {
echo "brew $*"
case "$*" in
*--only-dependencies*) return "$TEST_DEPENDENCY_STATUS";;
install*) return "$TEST_INSTALL_STATUS";;
upgrade*) return "$TEST_UPGRADE_STATUS";;
esac
}
brew() { echo "brew $*"; }
add_php "$TEST_ACTION" "$TEST_EXISTING_VERSION"
`
],
{
encoding: 'utf8',
timeout: 5000,
env: {
...process.env,
TEST_ARCH: 'arm64',
TEST_ACTION: 'install',
TEST_EXISTING_VERSION: 'false',
TEST_CACHE_STATUS: '0',
TEST_DEPENDENCY_STATUS: '0',
TEST_INSTALL_STATUS: '0',
TEST_UPGRADE_STATUS: '0',
version: '8.4',
debug: 'none',
ts: 'nts',
runner: 'github',
use_package_cache: 'true',
php_tap: 'shivammathur/homebrew-php',
...env
}
}
);
it.each([
['arm64', '0', false, 0],
['arm64', '37', true, 0],
['x86_64', '0', false, 0],
['x86_64', '37', false, 1]
])(
'preserves the cache fallback on %s with cache status %s',
(arch, cacheStatus, fallback, status) => {
const result = run({TEST_ARCH: arch, TEST_CACHE_STATUS: cacheStatus});
expect(result.error).toBeUndefined();
expect(result.stderr).toBe('');
expect(result.status).toBe(status);
expect(result.stdout).toContain('cache\n');
expect(result.stdout.includes('brew install')).toBe(fallback);
}
);
it.each([
['install', '124', '0', '0', 124, 1],
['install', '37', '0', '0', 37, 1],
['install', '0', '124', '0', 124, 2],
['install', '0', '37', '124', 124, 3],
['install', '0', '37', '37', 37, 3],
['upgrade', '124', '0', '0', 124, 1],
['upgrade', '0', '0', '124', 124, 2],
['upgrade', '0', '0', '37', 37, 2]
])(
'stops %s after failures (dependencies=%s, install=%s, upgrade=%s)',
(action, dependencyStatus, installStatus, upgradeStatus, status, calls) => {
const result = run({
TEST_ACTION: action,
TEST_EXISTING_VERSION: action === 'upgrade' ? '8.4.10' : 'false',
TEST_CACHE_STATUS: '37',
TEST_DEPENDENCY_STATUS: dependencyStatus,
TEST_INSTALL_STATUS: installStatus,
TEST_UPGRADE_STATUS: upgradeStatus
});
expect(result.error).toBeUndefined();
expect(result.stderr).toBe('');
expect(result.status).toBe(status);
expect(result.stdout.match(/^brew /gm)).toHaveLength(calls);
expect(result.stdout).not.toContain('brew link');
}
);
it('retains the upgrade fallback for an install failure other than a timeout', () => {
const result = run({TEST_CACHE_STATUS: '37', TEST_INSTALL_STATUS: '1'});
expect(result.error).toBeUndefined();
expect(result.status).toBe(0);
expect(result.stdout).toContain(
'brew upgrade -f --overwrite shivammathur/php/php@8.4\n'
);
expect(result.stdout).toContain('brew link --force --overwrite php@8.4\n');
});
it('reuses an existing installation without invoking the cache or Homebrew install', () => {
const result = run({TEST_EXISTING_VERSION: '8.4.10'});
expect(result.status).toBe(0);
expect(result.stdout).toBe(
'brew unlink php@8.4\nbrew link --force --overwrite php@8.4\n'
);
});
it.each([
['debug', 'nts', '-debug'],
['none', 'zts', '-zts'],
['debug', 'zts', '-debug-zts']
])('keeps cache fallback for debug=%s, ts=%s', (debug, ts, suffix) => {
const result = run({
TEST_EXISTING_VERSION: '8.4.10',
TEST_CACHE_STATUS: '37',
debug,
ts
});
expect(result.status).toBe(0);
expect(result.stdout).toContain('cache\n');
expect(result.stdout).toContain(
`brew install --skip-link -f --overwrite shivammathur/php/php@8.4${suffix}\n`
);
});
it.each([
['self-hosted', 'true'],
['github', 'false']
])('uses Homebrew for runner=%s, cache=%s', (runner, use_package_cache) => {
const result = run({runner, use_package_cache, TEST_CACHE_STATUS: '37'});
expect(result.error).toBeUndefined();
expect(result.stderr).toBe('');
expect(result.status).toBe(0);
expect(result.stdout).not.toContain('cache\n');
expect(result.stdout).toContain(
'brew install --skip-link -f --overwrite shivammathur/php/php@8.4\n'
);
expect(result.stdout).toContain('brew link --force --overwrite php@8.4\n');
});
});
+59 -1
View File
@@ -228,6 +228,7 @@ describe('Tools tests', () => {
${'tool:1.2.3@sha256:' + 'A'.repeat(64)} | ${'tool:1.2.3'} | ${'sha256:' + 'a'.repeat(64)} | ${undefined} ${'tool:1.2.3@sha256:' + 'A'.repeat(64)} | ${'tool:1.2.3'} | ${'sha256:' + 'a'.repeat(64)} | ${undefined}
${'tool:1.2.3@SHA256:' + 'a'.repeat(64)} | ${'tool:1.2.3'} | ${'sha256:' + 'a'.repeat(64)} | ${undefined} ${'tool:1.2.3@SHA256:' + 'a'.repeat(64)} | ${'tool:1.2.3'} | ${'sha256:' + 'a'.repeat(64)} | ${undefined}
${'tool:1.2.3@sha512:' + 'b'.repeat(128)} | ${'tool:1.2.3'} | ${'sha512:' + 'b'.repeat(128)} | ${undefined} ${'tool:1.2.3@sha512:' + 'b'.repeat(128)} | ${'tool:1.2.3'} | ${'sha512:' + 'b'.repeat(128)} | ${undefined}
${'tool:v1.2.3-beta.1+build.2@sha256:' + 'a'.repeat(64)} | ${'tool:v1.2.3-beta.1+build.2'} | ${'sha256:' + 'a'.repeat(64)} | ${undefined}
${'composer:2.9.8@sha256:' + 'c'.repeat(64)} | ${'composer:2.9.8'} | ${'sha256:' + 'c'.repeat(64)} | ${undefined} ${'composer:2.9.8@sha256:' + 'c'.repeat(64)} | ${'composer:2.9.8'} | ${'sha256:' + 'c'.repeat(64)} | ${undefined}
${'tool:1.2.3@sha256:xyz'} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 hexadecimal characters'} ${'tool:1.2.3@sha256:xyz'} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 hexadecimal characters'}
${'tool:1.2.3@sha256:' + 'a'.repeat(63)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 hexadecimal characters'} ${'tool:1.2.3@sha256:' + 'a'.repeat(63)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 hexadecimal characters'}
@@ -836,7 +837,7 @@ describe('Tools tests', () => {
${'cs2pr:1.2.3@sha256:' + 'd'.repeat(64)} | ${'linux'} | ${'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V" sha256:' + 'd'.repeat(64)} ${'cs2pr:1.2.3@sha256:' + 'd'.repeat(64)} | ${'linux'} | ${'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V" sha256:' + 'd'.repeat(64)}
${'phive:0.15.3@sha512:' + 'c'.repeat(128)} | ${'darwin'} | ${'add_tool https://github.com/phar-io/phive/releases/download/0.15.3/phive-0.15.3.phar phive "status" sha512:' + 'c'.repeat(128)} ${'phive:0.15.3@sha512:' + 'c'.repeat(128)} | ${'darwin'} | ${'add_tool https://github.com/phar-io/phive/releases/download/0.15.3/phive-0.15.3.phar phive "status" sha512:' + 'c'.repeat(128)}
${'phinx:1.2.3@sha256:' + 'a'.repeat(64)} | ${'linux'} | ${'add_log "$cross" "phinx" "Checksum verification is not supported for phinx"'} ${'phinx:1.2.3@sha256:' + 'a'.repeat(64)} | ${'linux'} | ${'add_log "$cross" "phinx" "Checksum verification is not supported for phinx"'}
${'pecl@sha256:' + 'a'.repeat(64)} | ${'linux'} | ${'add_log "$cross" "pecl" "Checksum verification is not supported for pecl"'} ${'pecl:1.2.3@sha256:' + 'a'.repeat(64)} | ${'linux'} | ${'add_log "$cross" "pecl" "Checksum verification is not supported for pecl"'}
${'phpunit:9.5.0@sha256:invalid'} | ${'linux'} | ${'add_log "$cross" "phpunit" "Invalid sha256 checksum, expected 64 hexadecimal characters"'} ${'phpunit:9.5.0@sha256:invalid'} | ${'linux'} | ${'add_log "$cross" "phpunit" "Invalid sha256 checksum, expected 64 hexadecimal characters"'}
${'composer:2.9.8@SHA256:' + 'b'.repeat(64)} | ${'linux'} | ${'composer 2.9.8 sha256:' + 'b'.repeat(64)} ${'composer:2.9.8@SHA256:' + 'b'.repeat(64)} | ${'linux'} | ${'composer 2.9.8 sha256:' + 'b'.repeat(64)}
${'composer:2.9.8@sha384:' + 'b'.repeat(96)} | ${'linux'} | ${'add_log "$cross" "composer" "Unsupported checksum algorithm sha384, expected sha256 or sha512"'} ${'composer:2.9.8@sha384:' + 'b'.repeat(96)} | ${'linux'} | ${'add_log "$cross" "composer" "Unsupported checksum algorithm sha384, expected sha256 or sha512"'}
@@ -849,6 +850,63 @@ describe('Tools tests', () => {
} }
); );
describe.each(['linux', 'darwin', 'win32'])(
'Checksum version requirements on %s',
os => {
it.each(['2.9.8+build.1', '2.9.8-rc.1', '2.9.8-rc.1+build.2'])(
'preserves the exact Composer version and checksum for %s',
async version => {
const checksum = 'sha256:' + 'a'.repeat(64);
const release = `composer:${version}@${checksum}`;
expect(await tools.filterList([release])).toEqual([release]);
const script = await tools.addTools(release, '8.4', os);
expect(script).toContain(
`https://github.com/composer/composer/releases/download/${version}/composer.phar`
);
expect(script).toContain(
`https://getcomposer.org/download/${version}/composer.phar`
);
expect(script).toContain(`composer ${version} ${checksum}`);
expect(script).not.toContain('latest');
expect(script).not.toContain('composer-stable.phar');
}
);
it.each([
'',
':latest',
':stable',
':preview',
':snapshot',
':2',
':2.x',
':2.9',
':2.9.x',
':^2.9.8'
])(
'rejects a checksum on a non-full version %s without an unpinned install',
async version => {
for (const tool of ['composer', 'phpunit']) {
const release = `${tool}${version}@sha256:${'a'.repeat(64)}`;
const data = await tools.getData(release, '8.4', os);
expect(data.error).toBe(
'Checksum pinning requires a full version, for example tool:1.2.3'
);
expect(data.url).toBe('');
const script = await tools.addTools(release, '8.4', os);
expect(script).toContain(data.error);
const installations = script
.split('\n')
.filter(line => /^add[-_]tool /i.test(line));
expect(
installations.some(line => new RegExp(` ${tool}( |$)`).test(line))
).toBe(false);
}
}
);
}
);
it.each` it.each`
type | tool_function | supported type | tool_function | supported
${'phar'} | ${undefined} | ${true} ${'phar'} | ${undefined} | ${true}
+60 -10
View File
@@ -56,11 +56,16 @@ describe('Utils tests', () => {
await expect(utils.parseVersion('foo')).rejects.toThrow( await expect(utils.parseVersion('foo')).rejects.toThrow(
'Invalid PHP version:' 'Invalid PHP version:'
); );
await expect(utils.parseVersion('8.4\n$(id)')).rejects.toThrow(
'Invalid PHP version:'
);
fetchSpy.mockResolvedValue({data: '{ "latest": "8.1.0" }'}); for (const latest of ['8.1.0', 'pre', 8.4, ['8.4']]) {
fetchSpy.mockResolvedValue({data: JSON.stringify({latest})});
await expect(utils.parseVersion('latest')).rejects.toThrow( await expect(utils.parseVersion('latest')).rejects.toThrow(
'Invalid PHP version in manifest:' 'Invalid PHP version in manifest:'
); );
}
fetchSpy.mockReset(); fetchSpy.mockReset();
fetchSpy.mockResolvedValueOnce({}).mockResolvedValueOnce({}); fetchSpy.mockResolvedValueOnce({}).mockResolvedValueOnce({});
@@ -334,8 +339,30 @@ describe('Utils tests', () => {
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.2'); readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.2');
expect(await utils.readPHPVersion()).toBe('8.4.2'); expect(await utils.readPHPVersion()).toBe('8.4.2');
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4\nnode 20.1.2');
expect(await utils.readPHPVersion()).toBe('8.4');
readFileSync.mockReturnValue('ruby 1.2.3\nphp latest\nnode 20.1.2');
expect(await utils.readPHPVersion()).toBe('latest');
readFileSync.mockReturnValue(' \t8.4 \t\n');
expect(await utils.readPHPVersion()).toBe('8.4');
readFileSync.mockReturnValue(
'#PHP\r\n\r\nruby 1.2.3\r\n \tphp \t latest \t# version\r\nnode 20.1.2'
);
expect(await utils.readPHPVersion()).toBe('latest');
readFileSync.mockReturnValue('php\n8.4');
await expect(utils.readPHPVersion()).rejects.toThrow('Invalid PHP version');
process.env['php-version-file'] = '.tool-versions';
readFileSync.mockReturnValue("ruby 1.2.3\nphp 8.4';id;#\nnode 20.1.2");
await expect(utils.readPHPVersion()).rejects.toThrow('.tool-versions');
delete process.env['php-version-file'];
existsSync.mockReturnValue(true); existsSync.mockReturnValue(true);
readFileSync.mockReturnValue('setup-php'); readFileSync.mockReturnValue('php 8.4 8.5');
await expect(utils.readPHPVersion()).rejects.toThrow('Invalid PHP version'); await expect(utils.readPHPVersion()).rejects.toThrow('Invalid PHP version');
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true); existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
@@ -361,29 +388,44 @@ describe('Utils tests', () => {
const existsSync = jest.spyOn(fs, 'existsSync').mockImplementation(); const existsSync = jest.spyOn(fs, 'existsSync').mockImplementation();
const readFileSync = jest.spyOn(fs, 'readFileSync').mockImplementation(); const readFileSync = jest.spyOn(fs, 'readFileSync').mockImplementation();
process.env['php-version'] = 'bogus'; process.env['php-version'] = '$0';
await expect(utils.readPHPVersion()).rejects.toThrow('php-version input'); await expect(utils.readPHPVersion()).rejects.toThrow('php-version input');
delete process.env['php-version']; delete process.env['php-version'];
existsSync.mockReturnValue(true); existsSync.mockReturnValue(true);
readFileSync.mockReturnValue('bogus'); readFileSync.mockReturnValue(';id');
await expect(utils.readPHPVersion()).rejects.toThrow('.php-version'); await expect(utils.readPHPVersion()).rejects.toThrow('.php-version');
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true); existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
readFileSync.mockReturnValue('{"platform-overrides":{"php":"bogus"}}'); readFileSync.mockReturnValue('{"platform-overrides":{"php":"`w`"}}');
await expect(utils.readPHPVersion()).rejects.toThrow( await expect(utils.readPHPVersion()).rejects.toThrow(
'composer.lock platform-overrides.php' 'composer.lock platform-overrides.php'
); );
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
readFileSync.mockReturnValue('{"platform-overrides":{"php":8.4}}');
await expect(utils.readPHPVersion()).rejects.toThrow(
'composer.lock platform-overrides.php: number'
);
existsSync existsSync
.mockReturnValueOnce(false) .mockReturnValueOnce(false)
.mockReturnValueOnce(false) .mockReturnValueOnce(false)
.mockReturnValueOnce(true); .mockReturnValueOnce(true);
readFileSync.mockReturnValue('{"config":{"platform":{"php":"bogus"}}}'); readFileSync.mockReturnValue('{"config":{"platform":{"php":"8.4$(id)"}}}');
await expect(utils.readPHPVersion()).rejects.toThrow( await expect(utils.readPHPVersion()).rejects.toThrow(
'composer.json config.platform.php' 'composer.json config.platform.php'
); );
existsSync
.mockReturnValueOnce(false)
.mockReturnValueOnce(false)
.mockReturnValueOnce(true);
readFileSync.mockReturnValue('{"config":{"platform":{"php":["8.4"]}}}');
await expect(utils.readPHPVersion()).rejects.toThrow(
'composer.json config.platform.php: object'
);
existsSync.mockClear(); existsSync.mockClear();
readFileSync.mockClear(); readFileSync.mockClear();
}); });
@@ -458,7 +500,9 @@ describe.each(['linux', 'darwin', 'win32'])(
const prepared = await utils.addVerbose(run, platform); const prepared = await utils.addVerbose(run, platform);
const script = fs.readFileSync(prepared, 'utf8'); const script = fs.readFileSync(prepared, 'utf8');
expect(prepared !== run).toBe(enabled); expect(prepared !== run).toBe(enabled);
expect(script.includes('2>&1')).toBe(!enabled); expect(
script.includes(platform === 'win32' ? '>$null' : '>/dev/null')
).toBe(!enabled);
expect(script.includes('src-verbose')).toBe(enabled); expect(script.includes('src-verbose')).toBe(enabled);
expect(script.startsWith('. ')).toBe(true); expect(script.startsWith('. ')).toBe(true);
expect(process.env.SETUP_PHP_TRACE).toBe( expect(process.env.SETUP_PHP_TRACE).toBe(
@@ -501,7 +545,9 @@ describe.each(['linux', 'darwin', 'win32'])(
path.join(path.dirname(prepared), 'tools', path.basename(helper)), path.join(path.dirname(prepared), 'tools', path.basename(helper)),
'utf8' 'utf8'
) )
).toBe(`echo nested-output \n${probe}\n`); ).toBe(
`echo nested-output ${platform === 'win32' ? '2>&1 | Out-Host' : ''}\n${probe}\n`
);
expect(fs.readFileSync(helper, 'utf8')).toContain(pipe); expect(fs.readFileSync(helper, 'utf8')).toContain(pipe);
const shell = platform === 'win32' ? 'pwsh' : 'bash'; const shell = platform === 'win32' ? 'pwsh' : 'bash';
if (platform === 'win32' ? hasPwsh : process.platform !== 'win32') { if (platform === 'win32' ? hasPwsh : process.platform !== 'win32') {
@@ -529,7 +575,9 @@ describe.each(['linux', 'darwin', 'win32'])(
if (verbose !== undefined) process.env.verbose = verbose; if (verbose !== undefined) process.env.verbose = verbose;
const prepared = await utils.addVerbose(run, platform); const prepared = await utils.addVerbose(run, platform);
expect(prepared).not.toBe(run); expect(prepared).not.toBe(run);
expect(fs.readFileSync(prepared, 'utf8')).not.toContain('2>&1'); expect(fs.readFileSync(prepared, 'utf8')).not.toMatch(
/>\s*(?:\/dev\/null|\$null)\s+2>&1/
);
expect(process.env.SETUP_PHP_TRACE).toBe( expect(process.env.SETUP_PHP_TRACE).toBe(
/^v{2,3}$/.test(verbose || '') ? String(verbose!.length - 1) : '0' /^v{2,3}$/.test(verbose || '') ? String(verbose!.length - 1) : '0'
); );
@@ -826,7 +874,9 @@ echo should-not-run
path.join(path.dirname(first), 'tools', path.basename(helper)), path.join(path.dirname(first), 'tools', path.basename(helper)),
'utf8' 'utf8'
) )
).toBe('echo original \n'); ).toBe(
`echo original ${platform === 'win32' ? '2>&1 | Out-Host' : ''}\n`
);
} }
); );
} }
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -20,6 +20,7 @@
"format": "prettier --write **/src/*.ts **/__tests__/*.ts && git add -f __tests__/ ", "format": "prettier --write **/src/*.ts **/__tests__/*.ts && git add -f __tests__/ ",
"format-check": "prettier --check **/src/*.ts **/__tests__/*.ts", "format-check": "prettier --check **/src/*.ts **/__tests__/*.ts",
"release": "ncc build -m -o dist && git add -f dist/", "release": "ncc build -m -o dist && git add -f dist/",
"typecheck": "tsc --project tsconfig.test.json --noEmit",
"test": "jest" "test": "jest"
}, },
"repository": { "repository": {
+8 -1
View File
@@ -90,7 +90,13 @@ add_brew_extension() {
safe_brew install --skip-link "${brew_opts[@]}" "$ext_tap/$formula@$version" >/dev/null 2>&1 && safe_brew install --skip-link "${brew_opts[@]}" "$ext_tap/$formula@$version" >/dev/null 2>&1 &&
brew link --overwrite --force "$formula@$version" >/dev/null 2>&1 && brew link --overwrite --force "$formula@$version" >/dev/null 2>&1 &&
copy_brew_extensions "$formula" copy_brew_extensions "$formula"
) || pecl_install "$extension" >/dev/null 2>&1 ) || {
if [ -n "$expected_version" ]; then
pecl_install "$extension-$expected_version" || pecl_install "$extension"
else
pecl_install "$extension"
fi
} >/dev/null 2>&1
add_extension_log "$extension" "Installed and enabled" add_extension_log "$extension" "Installed and enabled"
fi fi
} }
@@ -208,6 +214,7 @@ add_php() {
safe_brew install --only-dependencies "$php_formula" || return $? safe_brew install --only-dependencies "$php_formula" || return $?
safe_brew install --skip-link -f --overwrite "$php_formula" 2>/dev/null || { safe_brew install --skip-link -f --overwrite "$php_formula" 2>/dev/null || {
exit_code=$? exit_code=$?
# A timeout has exhausted its retries; do not start another build via upgrade.
[ "$exit_code" -ne 124 ] || return "$exit_code" [ "$exit_code" -ne 124 ] || return "$exit_code"
safe_brew upgrade -f --overwrite "$php_formula" || return $? safe_brew upgrade -f --overwrite "$php_formula" || return $?
} }
+53 -5
View File
@@ -104,16 +104,50 @@ Function Add-Extension {
[string] [string]
$extension_version = '' $extension_version = ''
) )
$extension_backup = ''
$restore_startup_errors = $false
try { try {
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch" $deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
New-Item $deps_dir -Type Directory -Force > $null 2>&1 New-Item $deps_dir -Type Directory -Force > $null 2>&1
if($extension_version -ne '' -and (Test-Path "$ext_dir\$extension-$extension_version")) { $cached = $extension_version -ne '' -and (Test-Path "$ext_dir\$extension-$extension_version")
$extension_info = $null
if(-not $cached) {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
}
# Only suppress startup errors while probing a cached DLL or replacing an installed DLL.
if($cached -or ($extension_version -ne '' -and $extension_info.Version -ne $extension_version -and (Test-Path "$ext_dir\php_$extension.dll"))) {
$startup_errors = Get-PhpIniKey -Key display_startup_errors -Path "$php_dir\php.ini"
if($startup_errors -notmatch '^(0|off|false|no)$') {
$restore_startup_errors = $true
Set-PhpIniKey -Key display_startup_errors -Value Off -Path "$php_dir\php.ini"
}
}
if($cached) {
# Preserve the active DLL before probing a cache entry for another PHP build.
if(Test-Path "$ext_dir\php_$extension.dll") {
$extension_info = Get-PhpExtension -Path "$ext_dir\php_$extension.dll"
$backup_name = if($extension_info.Version) { "$extension-$($extension_info.Version)" } else { "$extension.bak" }
Copy-Item "$ext_dir\php_$extension.dll" "$ext_dir\$backup_name" -Force -ErrorAction Stop
$extension_backup = "$ext_dir\$backup_name"
}
Copy-Item "$ext_dir\$extension-$extension_version" "$ext_dir\php_$extension.dll" -Force Copy-Item "$ext_dir\$extension-$extension_version" "$ext_dir\php_$extension.dll" -Force
Enable-Extension $extension try {
Enable-ExtensionDependencies $extension
Enable-PhpExtension -Extension $extension -Path $php_dir
Set-ExtensionPrerequisites $extension
$cached_extension = Get-PhpExtension -Path $php_dir | Where-Object { ($_.Name -eq $extension -or $_.Handle -eq $extension) -and $_.State -eq 'Enabled' }
if($null -ne $cached_extension) {
Add-Log $tick $extension "Enabled"
return return
} }
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension } } catch {
if ($null -ne $extension_info -and ($extension_version -eq '' -or $extension_info.Version[0] -eq $extension_version)) { Write-Verbose "Could not enable cached ${extension}: $_"
}
# A cached DLL may target another PHP build; install it again if it did not load.
Remove-Item "$ext_dir\php_$extension.dll" -Force
$extension_info = $null
}
if ($null -ne $extension_info -and ($extension_version -eq '' -or $extension_info.Version -eq $extension_version)) {
switch ($extension_info.State) { switch ($extension_info.State) {
'Builtin' { 'Builtin' {
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
@@ -143,7 +177,10 @@ Function Add-Extension {
} }
# If extension for a different version exists # If extension for a different version exists
if(Test-Path $ext_dir\php_$extension.dll) { if(Test-Path $ext_dir\php_$extension.dll) {
Move-Item $ext_dir\php_$extension.dll $ext_dir\php_$extension.bak.dll -Force # Keep backups outside PhpManager's DLL scan and reuse known versions as cache entries.
$backup_name = if($extension_info.Version) { "$extension-$($extension_info.Version)" } else { "$extension.bak" }
Move-Item $ext_dir\php_$extension.dll "$ext_dir\$backup_name" -Force -ErrorAction Stop
$extension_backup = "$ext_dir\$backup_name"
} }
Install-PhpExtension @params Install-PhpExtension @params
Set-ExtensionPrerequisites $extension Set-ExtensionPrerequisites $extension
@@ -154,7 +191,18 @@ Function Add-Extension {
Copy-Item "$ext_dir\php_$extension.dll" "$ext_dir\$extension-$extension_version" -Force Copy-Item "$ext_dir\php_$extension.dll" "$ext_dir\$extension-$extension_version" -Force
} }
} catch { } catch {
if($extension_backup -ne '') {
Copy-Item $extension_backup "$ext_dir\php_$extension.dll" -Force
}
Add-Log $cross $extension "Could not install $extension on PHP $( $installed.FullVersion )" Add-Log $cross $extension "Could not install $extension on PHP $( $installed.FullVersion )"
} finally {
if($restore_startup_errors) {
if($null -eq $startup_errors) {
Set-PhpIniKey -Key display_startup_errors -Delete -Path "$php_dir\php.ini"
} else {
Set-PhpIniKey -Key display_startup_errors -Value $startup_errors -Path "$php_dir\php.ini"
}
}
} }
} }
+3 -4
View File
@@ -222,16 +222,15 @@ add_pecl_extension() {
# Cache versioned extensions using suffixless copies in extension_dir. # Cache versioned extensions using suffixless copies in extension_dir.
if [ -n "$pecl_version" ] && [ -e "${ext_dir:?}/$extension-$pecl_version" ]; then if [ -n "$pecl_version" ] && [ -e "${ext_dir:?}/$extension-$pecl_version" ]; then
sudo cp "${ext_dir:?}/$extension-$pecl_version" "${ext_dir:?}/$extension.so" sudo cp "${ext_dir:?}/$extension-$pecl_version" "${ext_dir:?}/$extension.so"
enable_extension "$extension" "$prefix" sudo rm -f /tmp/php"${version:?}"_extensions
add_log "${tick:?}" "$extension" "Enabled"
return
fi fi
enable_extension "$extension" "$prefix" enable_extension "$extension" "$prefix"
ext_version=$(php -r "echo phpversion('$extension');") ext_version=$(php -d display_errors=0 -r "echo phpversion('$extension');" 2>/dev/null)
if check_extension "$extension" && [[ -z "$pecl_version" || (-n "$pecl_version" && "${ext_version/-/}" == "$pecl_version") ]]; then if check_extension "$extension" && [[ -z "$pecl_version" || (-n "$pecl_version" && "${ext_version/-/}" == "$pecl_version") ]]; then
[ -n "$pecl_version" ] && sudo cp "${ext_dir:?}/$extension.so" "${ext_dir:?}/$extension-$pecl_version" 2>/dev/null || true [ -n "$pecl_version" ] && sudo cp "${ext_dir:?}/$extension.so" "${ext_dir:?}/$extension-$pecl_version" 2>/dev/null || true
add_log "${tick:?}" "$extension" "Enabled" add_log "${tick:?}" "$extension" "Enabled"
else else
[ -n "$pecl_version" ] && sudo rm -f "${ext_dir:?}/$extension-$pecl_version"
[ -n "$pecl_version" ] && pecl_version="-$pecl_version" [ -n "$pecl_version" ] && pecl_version="-$pecl_version"
pecl_install "$extension$pecl_version" || ( [ "${fail_fast:?}" = "false" ] && add_extension "$extension" "$(get_extension_prefix "$extension")" >/dev/null 2>&1) pecl_install "$extension$pecl_version" || ( [ "${fail_fast:?}" = "false" ] && add_extension "$extension" "$(get_extension_prefix "$extension")" >/dev/null 2>&1)
extension_version="$(php -r "echo phpversion('$extension');")" extension_version="$(php -r "echo phpversion('$extension');")"
+1 -1
View File
@@ -224,7 +224,7 @@ Function Add-ToolsHelper() {
} elseif($tool -eq "phpunit-bridge") { } elseif($tool -eq "phpunit-bridge") {
$extensions += @('dom', 'pdo', 'tokenizer', 'xmlwriter') $extensions += @('dom', 'pdo', 'tokenizer', 'xmlwriter')
} elseif($tool -eq "cloud-cli") { } elseif($tool -eq "cloud-cli") {
$extensions += @('sockets') $extensions += @('fileinfo', 'sockets')
Copy-Item $env:cloud_cli_bin\cloud.bat -Destination $env:cloud_cli_bin\cloud-cli.bat Copy-Item $env:cloud_cli_bin\cloud.bat -Destination $env:cloud_cli_bin\cloud-cli.bat
} elseif($tool -eq "vapor-cli") { } elseif($tool -eq "vapor-cli") {
$extensions += @('fileinfo', 'json', 'mbstring', 'zip', 'simplexml') $extensions += @('fileinfo', 'json', 'mbstring', 'zip', 'simplexml')
+1 -1
View File
@@ -190,7 +190,7 @@ add_tools_helper() {
sudo cp "$tool_path_dir"/phpunit "$composer_bin" sudo cp "$tool_path_dir"/phpunit "$composer_bin"
fi fi
elif [ "$tool" = "cloud-cli" ]; then elif [ "$tool" = "cloud-cli" ]; then
extensions+=(dom iconv sockets tokenizer) extensions+=(dom fileinfo iconv sockets tokenizer)
sudo ln -s "$scoped_dir"/vendor/bin/cloud "$scoped_dir"/vendor/bin/cloud-cli 2>/dev/null || true sudo ln -s "$scoped_dir"/vendor/bin/cloud "$scoped_dir"/vendor/bin/cloud-cli 2>/dev/null || true
elif [ "$tool" = "vapor-cli" ]; then elif [ "$tool" = "vapor-cli" ]; then
extensions+=(fileinfo json mbstring zip simplexml) extensions+=(fileinfo json mbstring zip simplexml)
+15 -3
View File
@@ -118,6 +118,12 @@ export function extractChecksum(release: string): {
error: `Invalid ${algo} checksum, expected ${hash_length} hexadecimal characters` error: `Invalid ${algo} checksum, expected ${hash_length} hexadecimal characters`
}; };
} }
if (!/^[^:]+:v?\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(release)) {
return {
release,
error: 'Checksum pinning requires a full version, for example tool:1.2.3'
};
}
return {release, checksum: `${algo}:${hash}`}; return {release, checksum: `${algo}:${hash}`};
} }
@@ -308,9 +314,14 @@ export async function filterList(tools_list: string[]): Promise<string[]> {
const regex_any = /^composer($|:.*)/; const regex_any = /^composer($|:.*)/;
const regex_valid = const regex_valid =
/^composer:?($|preview$|snapshot$|v?\d+(\.\d+)?$|v?\d+\.\d+\.\d+[\w-]*$)/; /^composer:?($|preview$|snapshot$|v?\d+(\.\d+)?$|v?\d+\.\d+\.\d+[\w-]*$)/;
const matches: string[] = tools_list.filter(tool => const matches: string[] = tools_list.filter(tool => {
regex_valid.test(extractChecksum(tool).release) const parsed = extractChecksum(tool);
return (
regex_valid.test(parsed.release) ||
(regex_any.test(parsed.release) &&
(parsed.checksum !== undefined || parsed.error !== undefined))
); );
});
let composer = 'composer'; let composer = 'composer';
tools_list = tools_list.filter( tools_list = tools_list.filter(
tool => !regex_any.test(extractChecksum(tool).release) tool => !regex_any.test(extractChecksum(tool).release)
@@ -480,7 +491,7 @@ export async function addComposer(data: ToolData): Promise<string> {
case /^1$/.test(channel): case /^1$/.test(channel):
source_url = channel_source_url; source_url = channel_source_url;
break; break;
case /^\d+\.\d+\.\d+(?:-[\w-]+)?$/.test(data.version): case /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(data.version):
if (skipGitHubAuthForComposerVersion(data.version)) { if (skipGitHubAuthForComposerVersion(data.version)) {
cleanComposerAuthJson(); cleanComposerAuthJson();
skip_composer_github_auth = ' true'; skip_composer_github_auth = ' true';
@@ -721,6 +732,7 @@ export async function getData(
data.checksum = checksum_data.checksum; data.checksum = checksum_data.checksum;
data.error = checksum_data.error; data.error = checksum_data.error;
data.release = await getRelease(release, data); data.release = await getRelease(release, data);
if (data.error !== undefined) return data;
data.version = version data.version = version
? await getVersion(version, data) ? await getVersion(version, data)
: await getLatestVersion(data); : await getLatestVersion(data);
+14 -10
View File
@@ -71,15 +71,13 @@ export async function parseVersion(version: string): Promise<string> {
for (const manifestURL of await getManifestURLS()) { for (const manifestURL of await getManifestURLS()) {
const fetchResult = await fetch.fetch(manifestURL); const fetchResult = await fetch.fetch(manifestURL);
if (fetchResult['data'] ?? false) { if (fetchResult['data'] ?? false) {
const resolved: string | undefined = JSON.parse(fetchResult['data'])[ const resolved: unknown = JSON.parse(fetchResult['data'])[version];
version
];
if (resolved === undefined) { if (resolved === undefined) {
throw new Error(`Invalid PHP version: ${version.slice(0, 20)}`); throw new Error(`Invalid PHP version: ${version.slice(0, 20)}`);
} }
if (!/^\d+\.\d+$/.test(resolved)) { if (typeof resolved !== 'string' || !/^\d+\.\d+$/.test(resolved)) {
throw new Error( throw new Error(
`Invalid PHP version in manifest: ${resolved.slice(0, 10)}` `Invalid PHP version in manifest: ${typeof resolved === 'string' ? resolved.slice(0, 10) : typeof resolved}`
); );
} }
return resolved; return resolved;
@@ -360,7 +358,11 @@ export async function addVerbose(
if (!file.endsWith(extension)) continue; if (!file.endsWith(extension)) continue;
const filename = path.join(scripts, file); const filename = path.join(scripts, file);
const original = fs.readFileSync(filename, 'utf8'); const original = fs.readFileSync(filename, 'utf8');
let script = original.replace(pipe, ''); // PowerShell's success stream also carries function return values.
let script = original.replace(
pipe,
os === 'win32' ? '2>&1 | Out-Host' : ''
);
if (filename === verbose_run) { if (filename === verbose_run) {
script = script.replaceAll(src, dest); script = script.replaceAll(src, dest);
} }
@@ -510,10 +512,10 @@ export async function parseExtensionSource(
const VERSION_INPUT_REGEX = const VERSION_INPUT_REGEX =
/^(latest|lowest|highest|nightly|master|pre|pre-installed|\d+\.x|\d+(\.\d+){0,2})$/; /^(latest|lowest|highest|nightly|master|pre|pre-installed|\d+\.x|\d+(\.\d+){0,2})$/;
function validatePHPVersionInput(version: string, source: string): string { function validatePHPVersionInput(version: unknown, source: string): string {
if (!VERSION_INPUT_REGEX.test(version)) { if (typeof version !== 'string' || !VERSION_INPUT_REGEX.test(version)) {
throw new Error( throw new Error(
`Invalid PHP version in ${source}: ${version.slice(0, 20)}` `Invalid PHP version in ${source}: ${typeof version === 'string' ? version.slice(0, 20) : typeof version}`
); );
} }
return version; return version;
@@ -531,7 +533,9 @@ export async function readPHPVersion(): Promise<string> {
(await getInput('php-version-file', false)) || '.php-version'; (await getInput('php-version-file', false)) || '.php-version';
if (fs.existsSync(versionFile)) { if (fs.existsSync(versionFile)) {
const contents: string = fs.readFileSync(versionFile, 'utf8'); const contents: string = fs.readFileSync(versionFile, 'utf8');
const match = contents.match(/^(?:php\s)?(\d+\.\d+\.\d+)$/m); const match = contents.match(
/^[ \t]*(?:php[ \t]+)?([^\s#]+)[ \t]*(?:#.*)?$/m
);
return validatePHPVersionInput( return validatePHPVersionInput(
match ? match[1] : contents.trim(), match ? match[1] : contents.trim(),
versionFile versionFile