mirror of
https://github.com/shivammathur/setup-php.git
synced 2026-09-20 18:07:26 +07:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d76a76348c | |||
| 84a5f1c061 | |||
| 72c642301a | |||
| ed2b57d93d | |||
| 75fa893d48 | |||
| 0bbee91078 | |||
| e3f88f3ca7 | |||
| 870fe79ecc | |||
| 25618cc48e | |||
| 5eaed2e30b | |||
| 85dc78fbb0 | |||
| 83c9e52793 | |||
| 9af3b52286 | |||
| 0e80ac5270 | |||
| ea331059db | |||
| 3ad6232c89 | |||
| 2ec764e0ab | |||
| e6ee35895b | |||
| 0c6410c670 |
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
|
|||||||
+73
-15
@@ -222,20 +222,21 @@ describe('Tools tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it.each`
|
it.each`
|
||||||
release | expected_release | checksum | error
|
release | expected_release | checksum | error
|
||||||
${'tool:1.2.3'} | ${'tool:1.2.3'} | ${undefined} | ${undefined}
|
${'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@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}
|
||||||
${'composer:2.9.8@sha256:' + 'c'.repeat(64)} | ${'composer:2.9.8'} | ${'sha256:' + 'c'.repeat(64)} | ${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}
|
||||||
${'tool:1.2.3@sha256:xyz'} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 hexadecimal characters'}
|
${'composer:2.9.8@sha256:' + 'c'.repeat(64)} | ${'composer:2.9.8'} | ${'sha256:' + 'c'.repeat(64)} | ${undefined}
|
||||||
${'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:xyz'} | ${'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@sha256:' + 'a'.repeat(63)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha256 checksum, expected 64 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@sha512:' + 'b'.repeat(64)} | ${'tool:1.2.3'} | ${undefined} | ${'Invalid sha512 checksum, expected 128 hexadecimal characters'}
|
||||||
${'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@sha384:' + 'b'.repeat(96)} | ${'tool:1.2.3'} | ${undefined} | ${'Unsupported checksum algorithm sha384, 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.2.3@md5:' + 'b'.repeat(32)} | ${'tool:1.2.3'} | ${undefined} | ${'Unsupported checksum algorithm md5, expected sha256 or sha512'}
|
||||||
${'tool:1.0@dev'} | ${'tool:1.0@dev'} | ${undefined} | ${undefined}
|
${'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',
|
'checking extractChecksum: $release',
|
||||||
({release, expected_release, checksum, error}) => {
|
({release, expected_release, checksum, error}) => {
|
||||||
@@ -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}
|
||||||
|
|||||||
+63
-13
@@ -56,12 +56,17 @@ 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(
|
||||||
fetchSpy.mockResolvedValue({data: '{ "latest": "8.1.0" }'});
|
'Invalid PHP version:'
|
||||||
await expect(utils.parseVersion('latest')).rejects.toThrow(
|
|
||||||
'Invalid PHP version in manifest:'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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.mockReset();
|
fetchSpy.mockReset();
|
||||||
fetchSpy.mockResolvedValueOnce({}).mockResolvedValueOnce({});
|
fetchSpy.mockResolvedValueOnce({}).mockResolvedValueOnce({});
|
||||||
await expect(utils.parseVersion('latest')).rejects.toThrow(
|
await expect(utils.parseVersion('latest')).rejects.toThrow(
|
||||||
@@ -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`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -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": {
|
||||||
|
|||||||
+17
-5
@@ -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
|
||||||
}
|
}
|
||||||
@@ -183,6 +189,7 @@ setup_cached_versions() {
|
|||||||
|
|
||||||
# Function to setup PHP 5.6 and newer using Homebrew.
|
# Function to setup PHP 5.6 and newer using Homebrew.
|
||||||
add_php() {
|
add_php() {
|
||||||
|
local exit_code
|
||||||
action=$1
|
action=$1
|
||||||
existing_version=$2
|
existing_version=$2
|
||||||
suffix="$(get_php_formula_suffix)"
|
suffix="$(get_php_formula_suffix)"
|
||||||
@@ -198,14 +205,19 @@ add_php() {
|
|||||||
fi
|
fi
|
||||||
if [[ "$existing_version" != "false" && -z "$suffix" ]]; then
|
if [[ "$existing_version" != "false" && -z "$suffix" ]]; then
|
||||||
if [ "$action" = "upgrade" ]; then
|
if [ "$action" = "upgrade" ]; then
|
||||||
safe_brew install --only-dependencies "$php_formula"
|
safe_brew install --only-dependencies "$php_formula" || return $?
|
||||||
safe_brew upgrade -f --overwrite "$php_formula"
|
safe_brew upgrade -f --overwrite "$php_formula" || return $?
|
||||||
else
|
else
|
||||||
brew unlink "$php_keg"
|
brew unlink "$php_keg"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
safe_brew install --only-dependencies "$php_formula"
|
safe_brew install --only-dependencies "$php_formula" || return $?
|
||||||
safe_brew install --skip-link -f --overwrite "$php_formula" 2>/dev/null || safe_brew upgrade -f --overwrite "$php_formula"
|
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 $?
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
brew link --force --overwrite "$php_keg" || (sudo chown -R "$(id -un)":"$(id -gn)" "$brew_prefix" && brew link --force --overwrite "$php_keg")
|
brew link --force --overwrite "$php_keg" || (sudo chown -R "$(id -un)":"$(id -gn)" "$brew_prefix" && brew link --force --overwrite "$php_keg")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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")
|
||||||
Copy-Item "$ext_dir\$extension-$extension_version" "$ext_dir\php_$extension.dll" -Force
|
$extension_info = $null
|
||||||
Enable-Extension $extension
|
if(-not $cached) {
|
||||||
return
|
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
|
||||||
}
|
}
|
||||||
$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 ($null -ne $extension_info -and ($extension_version -eq '' -or $extension_info.Version[0] -eq $extension_version)) {
|
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
|
||||||
|
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
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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');")"
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
+51
-25
@@ -55,25 +55,45 @@ get_file_mtime() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to terminate a process and its direct children.
|
# Function to list descendants before their parents, including separate sessions.
|
||||||
terminate_process_tree() {
|
get_process_tree() {
|
||||||
local pid=$1
|
local pid=$1
|
||||||
local children child
|
local children child
|
||||||
children=$(pgrep -P "$pid" 2>/dev/null || true)
|
children=$(pgrep -P "$pid" 2>/dev/null || true)
|
||||||
kill -TERM "$pid" >/dev/null 2>&1 || true
|
|
||||||
for child in $children; do
|
for child in $children; do
|
||||||
terminate_process_tree "$child"
|
get_process_tree "$child"
|
||||||
|
done
|
||||||
|
echo "$pid"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to detect Homebrew's source-build worker, even with buffered output.
|
||||||
|
is_brew_building_from_source() {
|
||||||
|
local pid
|
||||||
|
for pid in $(get_process_tree "$1"); do
|
||||||
|
if ps -ww -p "$pid" -o command= 2>/dev/null | grep -qE '/Homebrew/build[.]rb([[:space:]]|$)'; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to terminate the entire tree captured before any parents can exit.
|
||||||
|
terminate_process_tree() {
|
||||||
|
local pids pid
|
||||||
|
pids=$(get_process_tree "$1")
|
||||||
|
for pid in $pids; do
|
||||||
|
kill -TERM "$pid" >/dev/null 2>&1 || true
|
||||||
done
|
done
|
||||||
sleep 2
|
sleep 2
|
||||||
kill -KILL "$pid" >/dev/null 2>&1 || true
|
for pid in $pids; do
|
||||||
for child in $children; do
|
kill -KILL "$pid" >/dev/null 2>&1 || true
|
||||||
terminate_process_tree "$child"
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to run a command with an inactivity watchdog.
|
# Function to run a command with an inactivity watchdog.
|
||||||
run_with_inactivity_watchdog() {
|
run_with_inactivity_watchdog() {
|
||||||
local timeout_secs="${SETUP_PHP_BREW_INACTIVITY_TIMEOUT:-180}"
|
local timeout_secs="${SETUP_PHP_BREW_INACTIVITY_TIMEOUT:-180}"
|
||||||
|
local source_timeout_secs="${SETUP_PHP_BREW_SOURCE_INACTIVITY_TIMEOUT:-1800}"
|
||||||
local poll_secs="${SETUP_PHP_BREW_WATCHDOG_POLL:-5}"
|
local poll_secs="${SETUP_PHP_BREW_WATCHDOG_POLL:-5}"
|
||||||
local tmp_dir stdout_fifo stderr_fifo stdout_log stderr_log timeout_file
|
local tmp_dir stdout_fifo stderr_fifo stdout_log stderr_log timeout_file
|
||||||
local command_pid stdout_reader_pid stderr_reader_pid monitor_pid exit_code
|
local command_pid stdout_reader_pid stderr_reader_pid monitor_pid exit_code
|
||||||
@@ -93,36 +113,39 @@ run_with_inactivity_watchdog() {
|
|||||||
("$@" >"$stdout_fifo" 2>"$stderr_fifo") &
|
("$@" >"$stdout_fifo" 2>"$stderr_fifo") &
|
||||||
command_pid=$!
|
command_pid=$!
|
||||||
|
|
||||||
(
|
tee "$stdout_log" <"$stdout_fifo" &
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
|
||||||
printf '%s\n' "$line"
|
|
||||||
printf '%s\n' "$line" >>"$stdout_log"
|
|
||||||
done <"$stdout_fifo"
|
|
||||||
) &
|
|
||||||
stdout_reader_pid=$!
|
stdout_reader_pid=$!
|
||||||
|
|
||||||
(
|
tee "$stderr_log" <"$stderr_fifo" >&2 &
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
|
||||||
printf '%s\n' "$line" >&2
|
|
||||||
printf '%s\n' "$line" >>"$stderr_log"
|
|
||||||
done <"$stderr_fifo"
|
|
||||||
) &
|
|
||||||
stderr_reader_pid=$!
|
stderr_reader_pid=$!
|
||||||
|
|
||||||
(
|
(
|
||||||
local last_activity current_activity current_err_activity now
|
local last_activity current_activity current_err_activity now
|
||||||
|
local building_from_source=false was_building_from_source=false active_timeout_secs
|
||||||
last_activity=$(get_file_mtime "$stdout_log")
|
last_activity=$(get_file_mtime "$stdout_log")
|
||||||
current_err_activity=$(get_file_mtime "$stderr_log")
|
current_err_activity=$(get_file_mtime "$stderr_log")
|
||||||
[ "$current_err_activity" -gt "$last_activity" ] && last_activity="$current_err_activity"
|
[ "$current_err_activity" -gt "$last_activity" ] && last_activity="$current_err_activity"
|
||||||
while kill -0 "$command_pid" >/dev/null 2>&1; do
|
while kill -0 "$command_pid" >/dev/null 2>&1; do
|
||||||
sleep "$poll_secs"
|
sleep "$poll_secs"
|
||||||
|
kill -0 "$command_pid" >/dev/null 2>&1 || break
|
||||||
|
now=$(date +%s)
|
||||||
|
active_timeout_secs="$timeout_secs"
|
||||||
|
building_from_source=false
|
||||||
|
if is_brew_building_from_source "$command_pid"; then
|
||||||
|
building_from_source=true
|
||||||
|
active_timeout_secs="$source_timeout_secs"
|
||||||
|
fi
|
||||||
|
if [ "$building_from_source" != "$was_building_from_source" ]; then
|
||||||
|
last_activity="$now"
|
||||||
|
was_building_from_source="$building_from_source"
|
||||||
|
fi
|
||||||
current_activity=$(get_file_mtime "$stdout_log")
|
current_activity=$(get_file_mtime "$stdout_log")
|
||||||
[ "$current_activity" -gt "$last_activity" ] && last_activity="$current_activity"
|
[ "$current_activity" -gt "$last_activity" ] && last_activity="$current_activity"
|
||||||
current_err_activity=$(get_file_mtime "$stderr_log")
|
current_err_activity=$(get_file_mtime "$stderr_log")
|
||||||
[ "$current_err_activity" -gt "$last_activity" ] && last_activity="$current_err_activity"
|
[ "$current_err_activity" -gt "$last_activity" ] && last_activity="$current_err_activity"
|
||||||
now=$(date +%s)
|
now=$(date +%s)
|
||||||
if [ $((now - last_activity)) -ge "$timeout_secs" ]; then
|
if [ $((now - last_activity)) -ge "$active_timeout_secs" ]; then
|
||||||
printf "\nsetup-php: brew produced no output for %ss; terminating and retrying...\n" "$timeout_secs" >&2
|
printf "\nsetup-php: brew produced no output for %ss; terminating...\n" "$active_timeout_secs" >&2
|
||||||
: >"$timeout_file"
|
: >"$timeout_file"
|
||||||
terminate_process_tree "$command_pid"
|
terminate_process_tree "$command_pid"
|
||||||
break
|
break
|
||||||
@@ -131,12 +154,15 @@ run_with_inactivity_watchdog() {
|
|||||||
) &
|
) &
|
||||||
monitor_pid=$!
|
monitor_pid=$!
|
||||||
|
|
||||||
wait "$command_pid"
|
exit_code=0
|
||||||
exit_code=$?
|
wait "$command_pid" || exit_code=$?
|
||||||
|
# Let timeout cleanup finish killing source-build descendants before retrying.
|
||||||
|
if [ ! -e "$timeout_file" ]; then
|
||||||
|
kill "$monitor_pid" >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
wait "$monitor_pid" 2>/dev/null || true
|
||||||
wait "$stdout_reader_pid" 2>/dev/null || true
|
wait "$stdout_reader_pid" 2>/dev/null || true
|
||||||
wait "$stderr_reader_pid" 2>/dev/null || true
|
wait "$stderr_reader_pid" 2>/dev/null || true
|
||||||
kill "$monitor_pid" >/dev/null 2>&1 || true
|
|
||||||
wait "$monitor_pid" 2>/dev/null || true
|
|
||||||
|
|
||||||
if [ -e "$timeout_file" ]; then
|
if [ -e "$timeout_file" ]; then
|
||||||
rm -rf "$tmp_dir"
|
rm -rf "$tmp_dir"
|
||||||
|
|||||||
+16
-4
@@ -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
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user