Refactor linux.sh and fetch nightly script

This commit is contained in:
Shivam Mathur 2020-06-08 01:51:09 +05:30
parent da7361cc8f
commit 35c24a7d2f
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
4 changed files with 24 additions and 35 deletions

View File

@ -46,7 +46,7 @@ jest.mock('../src/install', () => ({
case 'darwin': case 'darwin':
case 'linux': case 'linux':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + __dirname; script += 'bash script.sh ' + version + ' ' + __dirname;
break; break;
case 'win32': case 'win32':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
@ -119,7 +119,7 @@ describe('Install', () => {
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 '); expect(script).toContain('bash script.sh 7.3 ');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true'); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true');
// @ts-ignore // @ts-ignore
@ -128,7 +128,7 @@ describe('Install', () => {
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3'); expect(script).toContain('bash script.sh 7.3');
expect(script).toContain('add_tool'); expect(script).toContain('add_tool');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', ''); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', '');
@ -138,7 +138,7 @@ describe('Install', () => {
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3'); expect(script).toContain('bash script.sh 7.3');
expect(script).toContain('add_tool'); expect(script).toContain('add_tool');
}); });
@ -147,7 +147,7 @@ describe('Install', () => {
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); expect(script).toContain('bash script.sh 7.3 ' + __dirname);
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', ''); setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', '');
// @ts-ignore // @ts-ignore
@ -156,7 +156,7 @@ describe('Install', () => {
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); expect(script).toContain('bash script.sh 7.3 ' + __dirname);
}); });
it('Test malformed version inputs', async () => { it('Test malformed version inputs', async () => {
@ -164,18 +164,18 @@ describe('Install', () => {
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.4 ' + __dirname); expect(script).toContain('bash script.sh 7.4 ' + __dirname);
setEnv(8.0, 'darwin', '', '', '', '', ''); setEnv(8.0, 'darwin', '', '', '', '', '');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 8.0 ' + __dirname); expect(script).toContain('bash script.sh 8.0 ' + __dirname);
setEnv(8, 'darwin', '', '', '', '', ''); setEnv(8, 'darwin', '', '', '', '', '');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 8.0 ' + __dirname); expect(script).toContain('bash script.sh 8.0 ' + __dirname);
}); });
}); });

2
dist/index.js vendored
View File

@ -2358,7 +2358,7 @@ async function run() {
case 'darwin': case 'darwin':
case 'linux': case 'linux':
script_path = await build(os_version + '.sh', version, os_version); script_path = await build(os_version + '.sh', version, os_version);
await exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname); await exec_1.exec('bash ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'win32': case 'win32':
script_path = await build('win32.ps1', version, os_version); script_path = await build('win32.ps1', version, os_version);

View File

@ -67,7 +67,7 @@ export async function run(): Promise<void> {
case 'darwin': case 'darwin':
case 'linux': case 'linux':
script_path = await build(os_version + '.sh', version, os_version); script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + __dirname); await exec('bash ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'win32': case 'win32':
script_path = await build('win32.ps1', version, os_version); script_path = await build('win32.ps1', version, os_version);

View File

@ -17,8 +17,8 @@ add_log() {
} }
# Function to update php ppa # Function to update php ppa
update_ppa() { update_lists() {
if [ "$ppa_updated" = "false" ]; then if [ "$lists_updated" = "false" ]; then
sudo "$debconf_fix" apt-get update >/dev/null 2>&1 sudo "$debconf_fix" apt-get update >/dev/null 2>&1
fi fi
} }
@ -87,7 +87,7 @@ add_extension() {
add_log "$tick" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! check_extension "$extension"; then elif ! check_extension "$extension"; then
eval "$install_command" >/dev/null 2>&1 || eval "$install_command" >/dev/null 2>&1 ||
(update_ppa && eval "$install_command" >/dev/null 2>&1) || (update_lists && eval "$install_command" >/dev/null 2>&1) ||
sudo pecl install -f "$extension" >/dev/null 2>&1 sudo pecl install -f "$extension" >/dev/null 2>&1
(check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") || (check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver" add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
@ -134,7 +134,7 @@ update_extension() {
if [ "$final_version" != "$current_version" ]; then if [ "$final_version" != "$current_version" ]; then
version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version") version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version")
if [ -z "$version_exists" ]; then if [ -z "$version_exists" ]; then
update_ppa update_lists
fi fi
$apt_install php"$version"-"$extension" $apt_install php"$version"-"$extension"
fi fi
@ -184,7 +184,7 @@ add_composertool() {
# Function to setup phpize and php-config # Function to setup phpize and php-config
add_devtools() { add_devtools() {
if ! [ -e "/usr/bin/phpize$version" ] || ! [ -e "/usr/bin/php-config$version" ]; then if ! [ -e "/usr/bin/phpize$version" ] || ! [ -e "/usr/bin/php-config$version" ]; then
update_ppa && $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1 update_lists && $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1
fi fi
sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1 sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1
sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1 sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1
@ -193,19 +193,7 @@ add_devtools() {
# Function to setup the nightly build from master branch # Function to setup the nightly build from master branch
setup_master() { setup_master() {
update_ppa && $apt_install libzip-dev libwebp-dev >/dev/null 2>&1 curl -sSL https://github.com/shivammathur/php-builder/releases/latest/download/install.sh | bash -s "github"
tar_file=php_"$version"%2Bubuntu"$(lsb_release -r -s)".tar.xz
install_dir=~/php/"$version"
bintray_url=https://dl.bintray.com/shivammathur/php/"$tar_file"
sudo mkdir -m 777 -p ~/php
curl -o /tmp/"$tar_file" -sSL "$bintray_url"
sudo tar xf /tmp/"$tar_file" -C ~/php
for tool_path in "$install_dir"/bin/*; do
tool=$(basename "$tool_path")
sudo cp "$tool_path" /usr/bin/"$tool$version"
sudo update-alternatives --install /usr/bin/"$tool" "$tool" /usr/bin/"$tool$version" 50 >/dev/null 2>&1
done
sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini
} }
# Function to setup PECL # Function to setup PECL
@ -222,7 +210,7 @@ add_pecl() {
switch_version() { switch_version() {
for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do
if [ -e "/usr/bin/$tool$version" ]; then if [ -e "/usr/bin/$tool$version" ]; then
sudo update-alternatives --set $tool /usr/bin/"$tool$version" >/dev/null 2>&1 sudo update-alternatives --set $tool /usr/bin/"$tool$version"
fi fi
done done
} }
@ -239,7 +227,7 @@ php_semver() {
# Variables # Variables
tick="✓" tick="✓"
cross="✗" cross="✗"
ppa_updated="false" lists_updated="false"
pecl_config="false" pecl_config="false"
version=$1 version=$1
debconf_fix="DEBIAN_FRONTEND=noninteractive" debconf_fix="DEBIAN_FRONTEND=noninteractive"
@ -254,17 +242,18 @@ sudo mkdir -p /var/run /run/php
if [ "$existing_version" != "$version" ]; then if [ "$existing_version" != "$version" ]; then
if [ ! -e "/usr/bin/php$version" ]; then if [ ! -e "/usr/bin/php$version" ]; then
if [ "$version" = "8.0" ]; then if [ "$version" = "8.0" ]; then
setup_master setup_master >/dev/null 2>&1
else else
update_ppa update_lists
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1 IFS=' ' read -r -a packages <<< "$(echo "curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
$apt_install php"$version" "${packages[@]}" >/dev/null 2>&1
fi fi
status="Installed" status="Installed"
else else
status="Switched to" status="Switched to"
fi fi
switch_version switch_version >/dev/null 2>&1
else else
status="Found" status="Found"
fi fi