mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-09-20 09:59:06 +07:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 68a5222a8d |
@@ -26,13 +26,13 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
|
||||
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
|
||||
with:
|
||||
config-file: ./.github/codeql/codeql-configuration.yml
|
||||
languages: javascript
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
|
||||
uses: github/codeql-action/autobuild@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@b96794f015dfd88f77b49b1c93e0fa7110f94c63 # v4
|
||||
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
|
||||
|
||||
@@ -52,9 +52,6 @@ jobs:
|
||||
- name: ESLint Check
|
||||
run: npm run lint
|
||||
|
||||
- name: TypeScript Check
|
||||
run: npm run typecheck
|
||||
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
|
||||
|
||||
@@ -81,11 +81,6 @@ Both `GitHub-hosted` and `self-hosted` runners are supported by `setup-php` on t
|
||||
| macOS Tahoe 26.x | arm64 | `macos-26` | - |
|
||||
| macOS Sequoia 15.x | arm64 | `macos-latest` or `macos-15` | - |
|
||||
| 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
|
||||
|
||||
@@ -277,7 +272,7 @@ These tools can be set up globally using the `tools` input. It accepts a string
|
||||
tools: composer:2.9.8@sha256:59b2c50e10cafa0d8efc19ede9a326d782f096c674a26baf98cf042ce23de890
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
- 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.
|
||||
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
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
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
+15
-73
@@ -222,21 +222,20 @@ describe('Tools tests', () => {
|
||||
});
|
||||
|
||||
it.each`
|
||||
release | expected_release | checksum | error
|
||||
${'tool:1.2.3'} | ${'tool:1.2.3'} | ${undefined} | ${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: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}
|
||||
${'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@sha512:' + 'b'.repeat(64)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha512 checksum, expected 128 hexadecimal characters'}
|
||||
${'tool:1.2.3@sha384:' + 'b'.repeat(96)} | ${'tool:1.2.3'} | ${undefined} | ${'Unsupported checksum algorithm sha384, expected sha256 or sha512'}
|
||||
${'tool:1.2.3@md5:' + 'b'.repeat(32)} | ${'tool:1.2.3'} | ${undefined} | ${'Unsupported checksum algorithm md5, expected sha256 or sha512'}
|
||||
${'tool:1.2.3@sha256' + 'a'.repeat(64)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid checksum syntax, expected @sha256:<hash> or @sha512:<hash>'}
|
||||
${'tool:1.0@dev'} | ${'tool:1.0@dev'} | ${undefined} | ${undefined}
|
||||
release | expected_release | checksum | error
|
||||
${'tool:1.2.3'} | ${'tool:1.2.3'} | ${undefined} | ${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}
|
||||
${'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:' + 'a'.repeat(63)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 hexadecimal characters'}
|
||||
${'tool:1.2.3@sha512:' + 'b'.repeat(64)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha512 checksum, expected 128 hexadecimal characters'}
|
||||
${'tool:1.2.3@sha384:' + 'b'.repeat(96)} | ${'tool:1.2.3'} | ${undefined} | ${'Unsupported checksum algorithm sha384, expected sha256 or sha512'}
|
||||
${'tool:1.2.3@md5:' + 'b'.repeat(32)} | ${'tool:1.2.3'} | ${undefined} | ${'Unsupported checksum algorithm md5, expected sha256 or sha512'}
|
||||
${'tool:1.2.3@sha256' + 'a'.repeat(64)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid checksum syntax, expected @sha256:<hash> or @sha512:<hash>'}
|
||||
${'tool:1.0@dev'} | ${'tool:1.0@dev'} | ${undefined} | ${undefined}
|
||||
`(
|
||||
'checking extractChecksum: $release',
|
||||
({release, expected_release, checksum, error}) => {
|
||||
@@ -837,7 +836,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)}
|
||||
${'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"'}
|
||||
${'pecl:1.2.3@sha256:' + 'a'.repeat(64)} | ${'linux'} | ${'add_log "$cross" "pecl" "Checksum verification is not supported for pecl"'}
|
||||
${'pecl@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"'}
|
||||
${'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"'}
|
||||
@@ -850,63 +849,6 @@ 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`
|
||||
type | tool_function | supported
|
||||
${'phar'} | ${undefined} | ${true}
|
||||
|
||||
+13
-63
@@ -56,16 +56,11 @@ describe('Utils tests', () => {
|
||||
await expect(utils.parseVersion('foo')).rejects.toThrow(
|
||||
'Invalid PHP version:'
|
||||
);
|
||||
await expect(utils.parseVersion('8.4\n$(id)')).rejects.toThrow(
|
||||
'Invalid PHP version:'
|
||||
);
|
||||
|
||||
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(
|
||||
'Invalid PHP version in manifest:'
|
||||
);
|
||||
}
|
||||
fetchSpy.mockResolvedValue({data: '{ "latest": "8.1.0" }'});
|
||||
await expect(utils.parseVersion('latest')).rejects.toThrow(
|
||||
'Invalid PHP version in manifest:'
|
||||
);
|
||||
|
||||
fetchSpy.mockReset();
|
||||
fetchSpy.mockResolvedValueOnce({}).mockResolvedValueOnce({});
|
||||
@@ -339,30 +334,8 @@ describe('Utils tests', () => {
|
||||
readFileSync.mockReturnValue('ruby 1.2.3\nphp 8.4.2\nnode 20.1.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);
|
||||
readFileSync.mockReturnValue('php 8.4 8.5');
|
||||
readFileSync.mockReturnValue('setup-php');
|
||||
await expect(utils.readPHPVersion()).rejects.toThrow('Invalid PHP version');
|
||||
|
||||
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
|
||||
@@ -388,44 +361,29 @@ describe('Utils tests', () => {
|
||||
const existsSync = jest.spyOn(fs, 'existsSync').mockImplementation();
|
||||
const readFileSync = jest.spyOn(fs, 'readFileSync').mockImplementation();
|
||||
|
||||
process.env['php-version'] = '$0';
|
||||
process.env['php-version'] = 'bogus';
|
||||
await expect(utils.readPHPVersion()).rejects.toThrow('php-version input');
|
||||
delete process.env['php-version'];
|
||||
|
||||
existsSync.mockReturnValue(true);
|
||||
readFileSync.mockReturnValue(';id');
|
||||
readFileSync.mockReturnValue('bogus');
|
||||
await expect(utils.readPHPVersion()).rejects.toThrow('.php-version');
|
||||
|
||||
existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
|
||||
readFileSync.mockReturnValue('{"platform-overrides":{"php":"`w`"}}');
|
||||
readFileSync.mockReturnValue('{"platform-overrides":{"php":"bogus"}}');
|
||||
await expect(utils.readPHPVersion()).rejects.toThrow(
|
||||
'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
|
||||
.mockReturnValueOnce(false)
|
||||
.mockReturnValueOnce(false)
|
||||
.mockReturnValueOnce(true);
|
||||
readFileSync.mockReturnValue('{"config":{"platform":{"php":"8.4$(id)"}}}');
|
||||
readFileSync.mockReturnValue('{"config":{"platform":{"php":"bogus"}}}');
|
||||
await expect(utils.readPHPVersion()).rejects.toThrow(
|
||||
'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();
|
||||
readFileSync.mockClear();
|
||||
});
|
||||
@@ -500,9 +458,7 @@ describe.each(['linux', 'darwin', 'win32'])(
|
||||
const prepared = await utils.addVerbose(run, platform);
|
||||
const script = fs.readFileSync(prepared, 'utf8');
|
||||
expect(prepared !== run).toBe(enabled);
|
||||
expect(
|
||||
script.includes(platform === 'win32' ? '>$null' : '>/dev/null')
|
||||
).toBe(!enabled);
|
||||
expect(script.includes('2>&1')).toBe(!enabled);
|
||||
expect(script.includes('src-verbose')).toBe(enabled);
|
||||
expect(script.startsWith('. ')).toBe(true);
|
||||
expect(process.env.SETUP_PHP_TRACE).toBe(
|
||||
@@ -545,9 +501,7 @@ describe.each(['linux', 'darwin', 'win32'])(
|
||||
path.join(path.dirname(prepared), 'tools', path.basename(helper)),
|
||||
'utf8'
|
||||
)
|
||||
).toBe(
|
||||
`echo nested-output ${platform === 'win32' ? '2>&1 | Out-Host' : ''}\n${probe}\n`
|
||||
);
|
||||
).toBe(`echo nested-output \n${probe}\n`);
|
||||
expect(fs.readFileSync(helper, 'utf8')).toContain(pipe);
|
||||
const shell = platform === 'win32' ? 'pwsh' : 'bash';
|
||||
if (platform === 'win32' ? hasPwsh : process.platform !== 'win32') {
|
||||
@@ -575,9 +529,7 @@ describe.each(['linux', 'darwin', 'win32'])(
|
||||
if (verbose !== undefined) process.env.verbose = verbose;
|
||||
const prepared = await utils.addVerbose(run, platform);
|
||||
expect(prepared).not.toBe(run);
|
||||
expect(fs.readFileSync(prepared, 'utf8')).not.toMatch(
|
||||
/>\s*(?:\/dev\/null|\$null)\s+2>&1/
|
||||
);
|
||||
expect(fs.readFileSync(prepared, 'utf8')).not.toContain('2>&1');
|
||||
expect(process.env.SETUP_PHP_TRACE).toBe(
|
||||
/^v{2,3}$/.test(verbose || '') ? String(verbose!.length - 1) : '0'
|
||||
);
|
||||
@@ -874,9 +826,7 @@ echo should-not-run
|
||||
path.join(path.dirname(first), 'tools', path.basename(helper)),
|
||||
'utf8'
|
||||
)
|
||||
).toBe(
|
||||
`echo original ${platform === 'win32' ? '2>&1 | Out-Host' : ''}\n`
|
||||
);
|
||||
).toBe('echo original \n');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -20,7 +20,6 @@
|
||||
"format": "prettier --write **/src/*.ts **/__tests__/*.ts && git add -f __tests__/ ",
|
||||
"format-check": "prettier --check **/src/*.ts **/__tests__/*.ts",
|
||||
"release": "ncc build -m -o dist && git add -f dist/",
|
||||
"typecheck": "tsc --project tsconfig.test.json --noEmit",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
@@ -90,13 +90,7 @@ add_brew_extension() {
|
||||
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 &&
|
||||
copy_brew_extensions "$formula"
|
||||
) || {
|
||||
if [ -n "$expected_version" ]; then
|
||||
pecl_install "$extension-$expected_version" || pecl_install "$extension"
|
||||
else
|
||||
pecl_install "$extension"
|
||||
fi
|
||||
} >/dev/null 2>&1
|
||||
) || pecl_install "$extension" >/dev/null 2>&1
|
||||
add_extension_log "$extension" "Installed and enabled"
|
||||
fi
|
||||
}
|
||||
@@ -214,7 +208,6 @@ add_php() {
|
||||
safe_brew install --only-dependencies "$php_formula" || return $?
|
||||
safe_brew install --skip-link -f --overwrite "$php_formula" 2>/dev/null || {
|
||||
exit_code=$?
|
||||
# A timeout has exhausted its retries; do not start another build via upgrade.
|
||||
[ "$exit_code" -ne 124 ] || return "$exit_code"
|
||||
safe_brew upgrade -f --overwrite "$php_formula" || return $?
|
||||
}
|
||||
|
||||
@@ -104,50 +104,16 @@ Function Add-Extension {
|
||||
[string]
|
||||
$extension_version = ''
|
||||
)
|
||||
$extension_backup = ''
|
||||
$restore_startup_errors = $false
|
||||
try {
|
||||
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
|
||||
New-Item $deps_dir -Type Directory -Force > $null 2>&1
|
||||
$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"
|
||||
}
|
||||
if($extension_version -ne '' -and (Test-Path "$ext_dir\$extension-$extension_version")) {
|
||||
Copy-Item "$ext_dir\$extension-$extension_version" "$ext_dir\php_$extension.dll" -Force
|
||||
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
|
||||
}
|
||||
} catch {
|
||||
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
|
||||
Enable-Extension $extension
|
||||
return
|
||||
}
|
||||
if ($null -ne $extension_info -and ($extension_version -eq '' -or $extension_info.Version -eq $extension_version)) {
|
||||
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
|
||||
if ($null -ne $extension_info -and ($extension_version -eq '' -or $extension_info.Version[0] -eq $extension_version)) {
|
||||
switch ($extension_info.State) {
|
||||
'Builtin' {
|
||||
Add-Log $tick $extension "Enabled"
|
||||
@@ -177,10 +143,7 @@ Function Add-Extension {
|
||||
}
|
||||
# If extension for a different version exists
|
||||
if(Test-Path $ext_dir\php_$extension.dll) {
|
||||
# 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"
|
||||
Move-Item $ext_dir\php_$extension.dll $ext_dir\php_$extension.bak.dll -Force
|
||||
}
|
||||
Install-PhpExtension @params
|
||||
Set-ExtensionPrerequisites $extension
|
||||
@@ -191,18 +154,7 @@ Function Add-Extension {
|
||||
Copy-Item "$ext_dir\php_$extension.dll" "$ext_dir\$extension-$extension_version" -Force
|
||||
}
|
||||
} 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 )"
|
||||
} 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -222,15 +222,16 @@ add_pecl_extension() {
|
||||
# Cache versioned extensions using suffixless copies in extension_dir.
|
||||
if [ -n "$pecl_version" ] && [ -e "${ext_dir:?}/$extension-$pecl_version" ]; then
|
||||
sudo cp "${ext_dir:?}/$extension-$pecl_version" "${ext_dir:?}/$extension.so"
|
||||
sudo rm -f /tmp/php"${version:?}"_extensions
|
||||
enable_extension "$extension" "$prefix"
|
||||
add_log "${tick:?}" "$extension" "Enabled"
|
||||
return
|
||||
fi
|
||||
enable_extension "$extension" "$prefix"
|
||||
ext_version=$(php -d display_errors=0 -r "echo phpversion('$extension');" 2>/dev/null)
|
||||
ext_version=$(php -r "echo phpversion('$extension');")
|
||||
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
|
||||
add_log "${tick:?}" "$extension" "Enabled"
|
||||
else
|
||||
[ -n "$pecl_version" ] && sudo rm -f "${ext_dir:?}/$extension-$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)
|
||||
extension_version="$(php -r "echo phpversion('$extension');")"
|
||||
|
||||
@@ -224,7 +224,7 @@ Function Add-ToolsHelper() {
|
||||
} elseif($tool -eq "phpunit-bridge") {
|
||||
$extensions += @('dom', 'pdo', 'tokenizer', 'xmlwriter')
|
||||
} elseif($tool -eq "cloud-cli") {
|
||||
$extensions += @('fileinfo', 'sockets')
|
||||
$extensions += @('sockets')
|
||||
Copy-Item $env:cloud_cli_bin\cloud.bat -Destination $env:cloud_cli_bin\cloud-cli.bat
|
||||
} elseif($tool -eq "vapor-cli") {
|
||||
$extensions += @('fileinfo', 'json', 'mbstring', 'zip', 'simplexml')
|
||||
|
||||
@@ -190,7 +190,7 @@ add_tools_helper() {
|
||||
sudo cp "$tool_path_dir"/phpunit "$composer_bin"
|
||||
fi
|
||||
elif [ "$tool" = "cloud-cli" ]; then
|
||||
extensions+=(dom fileinfo iconv sockets tokenizer)
|
||||
extensions+=(dom iconv sockets tokenizer)
|
||||
sudo ln -s "$scoped_dir"/vendor/bin/cloud "$scoped_dir"/vendor/bin/cloud-cli 2>/dev/null || true
|
||||
elif [ "$tool" = "vapor-cli" ]; then
|
||||
extensions+=(fileinfo json mbstring zip simplexml)
|
||||
|
||||
+4
-16
@@ -118,12 +118,6 @@ export function extractChecksum(release: string): {
|
||||
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}`};
|
||||
}
|
||||
|
||||
@@ -314,14 +308,9 @@ export async function filterList(tools_list: string[]): Promise<string[]> {
|
||||
const regex_any = /^composer($|:.*)/;
|
||||
const regex_valid =
|
||||
/^composer:?($|preview$|snapshot$|v?\d+(\.\d+)?$|v?\d+\.\d+\.\d+[\w-]*$)/;
|
||||
const matches: string[] = tools_list.filter(tool => {
|
||||
const parsed = extractChecksum(tool);
|
||||
return (
|
||||
regex_valid.test(parsed.release) ||
|
||||
(regex_any.test(parsed.release) &&
|
||||
(parsed.checksum !== undefined || parsed.error !== undefined))
|
||||
);
|
||||
});
|
||||
const matches: string[] = tools_list.filter(tool =>
|
||||
regex_valid.test(extractChecksum(tool).release)
|
||||
);
|
||||
let composer = 'composer';
|
||||
tools_list = tools_list.filter(
|
||||
tool => !regex_any.test(extractChecksum(tool).release)
|
||||
@@ -491,7 +480,7 @@ export async function addComposer(data: ToolData): Promise<string> {
|
||||
case /^1$/.test(channel):
|
||||
source_url = channel_source_url;
|
||||
break;
|
||||
case /^\d+\.\d+\.\d+(?:-[\w.-]+)?(?:\+[\w.-]+)?$/.test(data.version):
|
||||
case /^\d+\.\d+\.\d+(?:-[\w-]+)?$/.test(data.version):
|
||||
if (skipGitHubAuthForComposerVersion(data.version)) {
|
||||
cleanComposerAuthJson();
|
||||
skip_composer_github_auth = ' true';
|
||||
@@ -732,7 +721,6 @@ export async function getData(
|
||||
data.checksum = checksum_data.checksum;
|
||||
data.error = checksum_data.error;
|
||||
data.release = await getRelease(release, data);
|
||||
if (data.error !== undefined) return data;
|
||||
data.version = version
|
||||
? await getVersion(version, data)
|
||||
: await getLatestVersion(data);
|
||||
|
||||
+10
-14
@@ -71,13 +71,15 @@ export async function parseVersion(version: string): Promise<string> {
|
||||
for (const manifestURL of await getManifestURLS()) {
|
||||
const fetchResult = await fetch.fetch(manifestURL);
|
||||
if (fetchResult['data'] ?? false) {
|
||||
const resolved: unknown = JSON.parse(fetchResult['data'])[version];
|
||||
const resolved: string | undefined = JSON.parse(fetchResult['data'])[
|
||||
version
|
||||
];
|
||||
if (resolved === undefined) {
|
||||
throw new Error(`Invalid PHP version: ${version.slice(0, 20)}`);
|
||||
}
|
||||
if (typeof resolved !== 'string' || !/^\d+\.\d+$/.test(resolved)) {
|
||||
if (!/^\d+\.\d+$/.test(resolved)) {
|
||||
throw new Error(
|
||||
`Invalid PHP version in manifest: ${typeof resolved === 'string' ? resolved.slice(0, 10) : typeof resolved}`
|
||||
`Invalid PHP version in manifest: ${resolved.slice(0, 10)}`
|
||||
);
|
||||
}
|
||||
return resolved;
|
||||
@@ -358,11 +360,7 @@ export async function addVerbose(
|
||||
if (!file.endsWith(extension)) continue;
|
||||
const filename = path.join(scripts, file);
|
||||
const original = fs.readFileSync(filename, 'utf8');
|
||||
// PowerShell's success stream also carries function return values.
|
||||
let script = original.replace(
|
||||
pipe,
|
||||
os === 'win32' ? '2>&1 | Out-Host' : ''
|
||||
);
|
||||
let script = original.replace(pipe, '');
|
||||
if (filename === verbose_run) {
|
||||
script = script.replaceAll(src, dest);
|
||||
}
|
||||
@@ -512,10 +510,10 @@ export async function parseExtensionSource(
|
||||
const VERSION_INPUT_REGEX =
|
||||
/^(latest|lowest|highest|nightly|master|pre|pre-installed|\d+\.x|\d+(\.\d+){0,2})$/;
|
||||
|
||||
function validatePHPVersionInput(version: unknown, source: string): string {
|
||||
if (typeof version !== 'string' || !VERSION_INPUT_REGEX.test(version)) {
|
||||
function validatePHPVersionInput(version: string, source: string): string {
|
||||
if (!VERSION_INPUT_REGEX.test(version)) {
|
||||
throw new Error(
|
||||
`Invalid PHP version in ${source}: ${typeof version === 'string' ? version.slice(0, 20) : typeof version}`
|
||||
`Invalid PHP version in ${source}: ${version.slice(0, 20)}`
|
||||
);
|
||||
}
|
||||
return version;
|
||||
@@ -533,9 +531,7 @@ export async function readPHPVersion(): Promise<string> {
|
||||
(await getInput('php-version-file', false)) || '.php-version';
|
||||
if (fs.existsSync(versionFile)) {
|
||||
const contents: string = fs.readFileSync(versionFile, 'utf8');
|
||||
const match = contents.match(
|
||||
/^[ \t]*(?:php[ \t]+)?([^\s#]+)[ \t]*(?:#.*)?$/m
|
||||
);
|
||||
const match = contents.match(/^(?:php\s)?(\d+\.\d+\.\d+)$/m);
|
||||
return validatePHPVersionInput(
|
||||
match ? match[1] : contents.trim(),
|
||||
versionFile
|
||||
|
||||
Reference in New Issue
Block a user