This commit is contained in:
Shivam Mathur
2019-09-06 05:17:43 +05:30
commit 8f9786b73f
7058 changed files with 1813932 additions and 0 deletions

9
src/darwin.sh Normal file
View File

@ -0,0 +1,9 @@
echo $1
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew unlink php
brew tap exolnet/homebrew-deprecated
brew install php@$1
brew link --force --overwrite php@$1
brew install composer
php -v
composer -V

13
src/install.py Normal file
View File

@ -0,0 +1,13 @@
import platform
import os
current_os = platform.system()
php_version = os.environ['php-version']
if current_os == 'Linux':
os.system("sudo chmod a+x ./src/linux.sh")
os.system("./src/linux.sh " + php_version)
elif current_os == 'Darwin':
os.system("sudo chmod a+x ./src/darwin.sh")
os.system("sh ./src/darwin.sh " + php_version)
elif current_os == 'Windows':
os.system("powershell .\src\windows.ps1 -version " + php_version)

44
src/install.ts Normal file
View File

@ -0,0 +1,44 @@
import * as core from '@actions/core';
import {exec} from '@actions/exec/lib/exec';
const https = require('https');
const fs = require('fs');
async function get_file(filename: string) {
let github_path: string =
'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/';
const file: any = fs.createWriteStream(filename);
https.get(github_path + filename, function(response: any) {
response.pipe(file);
});
}
async function run() {
try {
let version = process.env['php-version'];
if (!version) {
version = core.getInput('php-version', {required: true});
}
console.log('Input: ' + version);
let os_version = process.platform;
if (os_version == 'darwin') {
await get_file('darwin.sh');
await exec('sudo chmod a+x darwin.sh');
await exec('./darwin.sh ' + version);
} else if (os_version == 'win32') {
await get_file('windows.ps1');
await exec('DIR');
await exec('powershell .\\windows.ps1 -version ' + version);
} else if (os_version == 'linux') {
await get_file('linux.sh');
await exec('sudo chmod a+x linux.sh');
await exec('./linux.sh ' + version);
}
} catch (err) {
core.setFailed(err.message);
}
}
run().then(() => {
console.log('done');
});

8
src/linux.sh Normal file
View File

@ -0,0 +1,8 @@
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update -y
sudo apt install -y php$1 curl
sudo update-alternatives --set php /usr/bin/php$1
sudo curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
php -v
composer -V

39
src/windows.ps1 Normal file
View File

@ -0,0 +1,39 @@
param (
[Parameter(Mandatory=$true)][string]$version = "7.3"
)
echo "Installing NuGet"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
if($version -lt '7.0') {
echo "Installing Visual C++"
Install-Module -Name VcRedist -Force
New-Item -Path C:\Temp\VcRedist -ItemType Directory
Get-VcList | Save-VcRedist -Path C:\Temp\VcRedist
$VcList = Get-VcList
Install-VcRedist -Path C:\Temp\VcRedist -VcList $VcList -Silent
}
echo "Installing PhpManager"
Install-Module -Name PhpManager -Force -Scope CurrentUser
echo "Installing PHP"
Uninstall-Php C:\tools\php
Install-Php -Version $version -Architecture x86 -ThreadSafe $true -Path C:\tools\php$version -TimeZone UTC
echo "Switch PHP"
(Get-PhpSwitcher).targets
Initialize-PhpSwitcher -Alias C:\tools\php -Scope CurrentUser -Force
Add-PhpToSwitcher -Name $version -Path C:\tools\php$version -Force
Switch-Php $version -Force
echo "Housekeeping in PHP.ini, enabling openssl"
Move-item -Path C:\tools\php$version\php.ini-development -Destination C:\tools\php$version\php.ini -Force
Add-Content C:\tools\php$version\php.ini "extension=C:\tools\php$version\ext\php_openssl.dll"
Add-Content C:\tools\php$version\php.ini "date.timezone = 'UTC'"
echo "Installing Composer"
Install-Composer -Scope User
php -v
composer -V