Skip to content

Commit

Permalink
Merge pull request #71 from nanasess/fix-convert-version
Browse files Browse the repository at this point in the history
Fallback for failed requests to php.net
  • Loading branch information
nanasess authored Mar 14, 2022
2 parents 745d519 + bd160ff commit 104406c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
34 changes: 31 additions & 3 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,37 @@ function convertInstallVersion(version) {
if (process.platform === 'win32' && version === '7.3') {
return '7.3.30';
}
const json = yield (0, node_fetch_1.default)(`${PHP_RELEASES_URL}&version=${version}`)
.then(response => response.json());
return json.version;
try {
const json = yield (0, node_fetch_1.default)(`${PHP_RELEASES_URL}&version=${version}`)
.then(response => response.json());
return json.version;
}
catch (error) {
switch (version) {
case '5.4':
return '5.4.45';
case '5.5':
return '5.5.38';
case '5.6':
return '5.6.40';
case '7.0':
return '7.0.33';
case '7.1':
return '7.1.33';
case '7.2':
return '7.2.34';
case '7.3':
return '7.3.33';
case '7.4':
return '7.4.28';
case '8.0':
return '8.0.16';
case '8.1':
return '8.1.3';
default:
return version;
}
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "3.1.0",
"version": "3.1.1",
"private": true,
"description": "setup php action",
"main": "lib/setup-php.js",
Expand Down
40 changes: 34 additions & 6 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export async function installPhp(version: string): Promise<number> {
} else if (process.platform === 'win32') {
return await exec.exec(
'powershell -File ' +
path.join(
__dirname,
'choco-install-php-windows.ps1 -version ' + installVersion
)
path.join(
__dirname,
'choco-install-php-windows.ps1 -version ' + installVersion
)
);
}

Expand Down Expand Up @@ -65,8 +65,36 @@ export async function convertInstallVersion(version: string): Promise<string> {
if (process.platform === 'win32' && version === '7.3') {
return '7.3.30';
}
const json = await fetch(`${PHP_RELEASES_URL}&version=${version}`)
try {
const json = await fetch(`${PHP_RELEASES_URL}&version=${version}`)
.then(response => response.json()) as PHPReleaseJson;
return json.version;

return json.version;
} catch (error) {
switch (version) {
case '5.4':
return '5.4.45';
case '5.5':
return '5.5.38';
case '5.6':
return '5.6.40';
case '7.0':
return '7.0.33';
case '7.1':
return '7.1.33';
case '7.2':
return '7.2.34';
case '7.3':
return '7.3.33';
case '7.4':
return '7.4.28';
case '8.0':
return '8.0.16';
case '8.1':
return '8.1.3';
default:
return version;
}
}
}
}

0 comments on commit 104406c

Please sign in to comment.