Merge pull request #399 from alcaeus/allow-github-extension-installs

Allow extensions to be compiled from GitHub sources
This commit is contained in:
Shivam Mathur 2021-02-08 07:49:28 -08:00
commit f66ac5d5a6
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
6 changed files with 130 additions and 22 deletions

View File

@ -117,7 +117,7 @@ On all supported OS/Platforms the following PHP versions are supported as per th
PHP extensions can be setup using the `extensions` input. It accepts a `string` in csv-format. PHP extensions can be setup using the `extensions` input. It accepts a `string` in csv-format.
- On `Ubuntu`, extensions which are available as a package or available on `PECL` can be setup. - On `Ubuntu`, extensions which are available as a package, available on `PECL`, or hosted on GitHub can be setup.
```yaml ```yaml
- name: Setup PHP with PECL extension - name: Setup PHP with PECL extension
@ -129,7 +129,7 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
- On `Windows`, extensions available on `PECL` which have the `DLL` binary can be setup. - On `Windows`, extensions available on `PECL` which have the `DLL` binary can be setup.
- On `macOS`, extensions available on `PECL` can be installed. - On `macOS`, extensions available on `PECL` or hosted on GitHub can be installed.
- Extensions installed along with PHP if specified are enabled. - Extensions installed along with PHP if specified are enabled.
@ -192,6 +192,18 @@ PHP extensions can be setup using the `extensions` input. It accepts a `string`
fail-fast: true fail-fast: true
``` ```
- Extensions can be compiled from source if they are hosted on GitHub. In this case, the version specification contains the repository and branch/tag to clone:
```yaml
- name: Setup PHP and remove shared extension
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extensions: mongodb-mongodb/mongo-php-driver@v1.9
```
The version can be a branch name or tag as supported by `git clone -b <name>`. The clone is performed recursively, i.e. submodules will be cloned as well.
## :wrench: Tools Support ## :wrench: Tools Support
These tools can be setup globally using the `tools` input. It accepts a string in csv-format. These tools can be setup globally using the `tools` input. It accepts a string in csv-format.

View File

@ -58,6 +58,15 @@ describe('Extension tests', () => {
win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32'); win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32');
expect(win32).toContain('Add-Blackfire blackfire-1.31.0'); expect(win32).toContain('Add-Blackfire blackfire-1.31.0');
win32 = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'win32'
);
expect(win32).toContain(
'Add-Log "$cross" "mongodb-mongodb/mongo-php-driver@master" "mongodb-mongodb/mongo-php-driver@master is not supported on PHP 7.3"'
);
}); });
it('checking addExtensionOnLinux', async () => { it('checking addExtensionOnLinux', async () => {
@ -131,6 +140,15 @@ describe('Extension tests', () => {
linux = await extensions.addExtension('intl-68.2', '8.0', 'linux'); linux = await extensions.addExtension('intl-68.2', '8.0', 'linux');
expect(linux).toContain('add_intl intl-68.2'); expect(linux).toContain('add_intl intl-68.2');
linux = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'linux'
);
expect(linux).toContain(
'add_extension_from_github mongodb mongodb mongo-php-driver master'
);
}); });
it('checking addExtensionOnDarwin', async () => { it('checking addExtensionOnDarwin', async () => {
@ -220,5 +238,14 @@ describe('Extension tests', () => {
darwin = await extensions.addExtension('xdebug', '7.2', 'openbsd'); darwin = await extensions.addExtension('xdebug', '7.2', 'openbsd');
expect(darwin).toContain('Platform openbsd is not supported'); expect(darwin).toContain('Platform openbsd is not supported');
darwin = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'darwin'
);
expect(darwin).toContain(
'add_extension_from_github mongodb mongodb mongo-php-driver master'
);
}); });
}); });

29
dist/index.js vendored
View File

@ -2901,6 +2901,7 @@ async function addExtensionDarwin(extension_csv, version) {
const version_extension = version + extension; const version_extension = version + extension;
const [ext_name, ext_version] = extension.split('-'); const [ext_name, ext_version] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name); const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches;
switch (true) { switch (true) {
// match :extension // match :extension
case /^:/.test(ext_name): case /^:/.test(ext_name):
@ -2923,6 +2924,17 @@ async function addExtensionDarwin(extension_csv, version) {
case /.*-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(version_extension): case /.*-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(version_extension):
add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix); add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix);
return; return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
case /.*-(.*)\/(.*)@(.*)/.test(extension):
matches = /.*-(.*)\/(.*)@(.*)/.exec(extension);
if (matches == null) {
// Shouldn't happen
add_script += await utils.getUnsupportedLog(extension, version, 'darwin');
return;
}
add_script += await utils.joins('\nadd_extension_from_github', ext_name, matches[1], matches[2], matches[3], ext_prefix);
return;
// match semver // match semver
case /.*-\d+\.\d+\.\d+.*/.test(version_extension): case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
add_script += await utils.joins('\nadd_pecl_extension', ext_name, ext_version, ext_prefix); add_script += await utils.joins('\nadd_pecl_extension', ext_name, ext_version, ext_prefix);
@ -2987,6 +2999,11 @@ async function addExtensionWindows(extension_csv, version) {
case /.*-(stable|beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(stable|beta|alpha|devel|snapshot)/.test(version_extension):
add_script += await utils.joins('\nAdd-Extension', ext_name, ext_version.replace('stable', '')); add_script += await utils.joins('\nAdd-Extension', ext_name, ext_version.replace('stable', ''));
break; break;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
case /.*-(.*)\/(.*)@(.*)/.test(extension):
add_script += await utils.getUnsupportedLog(extension, version, 'win32');
break;
// match semver without state // match semver without state
case /.*-\d+\.\d+\.\d+$/.test(version_extension): case /.*-\d+\.\d+\.\d+$/.test(version_extension):
add_script += await utils.joins('\nAdd-Extension', ext_name, 'stable', ext_version); add_script += await utils.joins('\nAdd-Extension', ext_name, 'stable', ext_version);
@ -3044,6 +3061,7 @@ async function addExtensionLinux(extension_csv, version) {
const version_extension = version + extension; const version_extension = version + extension;
const [ext_name, ext_version] = extension.split('-'); const [ext_name, ext_version] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name); const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches;
switch (true) { switch (true) {
// Match :extension // Match :extension
case /^:/.test(ext_name): case /^:/.test(ext_name):
@ -3069,6 +3087,17 @@ async function addExtensionLinux(extension_csv, version) {
case /.*-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(version_extension): case /.*-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(version_extension):
add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix); add_script += await utils.joins('\nadd_unstable_extension', ext_name, ext_version, ext_prefix);
return; return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
case /.*-(.*)\/(.*)@(.*)/.test(extension):
matches = /.*-(.*)\/(.*)@(.*)/.exec(extension);
if (matches == null) {
// Shouldn't happen
add_script += await utils.getUnsupportedLog(extension, version, 'linux');
return;
}
add_script += await utils.joins('\nadd_extension_from_github', ext_name, matches[1], matches[2], matches[3], ext_prefix);
return;
// match semver versions // match semver versions
case /.*-\d+\.\d+\.\d+.*/.test(version_extension): case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
add_script += await utils.joins('\nadd_pecl_extension', ext_name, ext_version, ext_prefix); add_script += await utils.joins('\nadd_pecl_extension', ext_name, ext_version, ext_prefix);

View File

@ -17,6 +17,8 @@ export async function addExtensionDarwin(
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-'); const [ext_name, ext_version]: string[] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name); const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches: RegExpExecArray;
switch (true) { switch (true) {
// match :extension // match :extension
case /^:/.test(ext_name): case /^:/.test(ext_name):
@ -53,6 +55,19 @@ export async function addExtensionDarwin(
ext_prefix ext_prefix
); );
return; return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
case /.*-(.*)\/(.*)@(.*)/.test(extension):
matches = /.*-(.*)\/(.*)@(.*)/.exec(extension) as RegExpExecArray;
add_script += await utils.joins(
'\nadd_extension_from_github',
ext_name,
matches[1],
matches[2],
matches[3],
ext_prefix
);
return;
// match semver // match semver
case /.*-\d+\.\d+\.\d+.*/.test(version_extension): case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
add_script += await utils.joins( add_script += await utils.joins(
@ -142,6 +157,15 @@ export async function addExtensionWindows(
ext_version.replace('stable', '') ext_version.replace('stable', '')
); );
break; break;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
case /.*-(.*)\/(.*)@(.*)/.test(extension):
add_script += await utils.getUnsupportedLog(
extension,
version,
'win32'
);
break;
// match semver without state // match semver without state
case /.*-\d+\.\d+\.\d+$/.test(version_extension): case /.*-\d+\.\d+\.\d+$/.test(version_extension):
add_script += await utils.joins( add_script += await utils.joins(
@ -214,6 +238,8 @@ export async function addExtensionLinux(
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-'); const [ext_name, ext_version]: string[] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name); const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches: RegExpExecArray;
switch (true) { switch (true) {
// Match :extension // Match :extension
case /^:/.test(ext_name): case /^:/.test(ext_name):
@ -255,6 +281,19 @@ export async function addExtensionLinux(
ext_prefix ext_prefix
); );
return; return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
case /.*-(.*)\/(.*)@(.*)/.test(extension):
matches = /.*-(.*)\/(.*)@(.*)/.exec(extension) as RegExpExecArray;
add_script += await utils.joins(
'\nadd_extension_from_github',
ext_name,
matches[1],
matches[2],
matches[3],
ext_prefix
);
return;
// match semver versions // match semver versions
case /.*-\d+\.\d+\.\d+.*/.test(version_extension): case /.*-\d+\.\d+\.\d+.*/.test(version_extension):
add_script += await utils.joins( add_script += await utils.joins(

View File

@ -267,4 +267,24 @@ add_composertool() {
# Function to get PHP version in semver format. # Function to get PHP version in semver format.
php_semver() { php_semver() {
php"$version" -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+" | head -n 1 php"$version" -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+" | head -n 1
} }
# Function to install extension from a GitHub repository
add_extension_from_github() {
extension=$1
org=$2
repo=$3
release=$4
prefix=$5
(
add_devtools phpize
delete_extension "$extension"
git clone -n https://github.com/"$org"/"$repo" /tmp/"$repo-$release" || exit 1
cd /tmp/"$repo-$release" || exit 1
git checkout "$release" || exit 1
git submodule update --init --recursive || exit 1
phpize && ./configure && make -j"$(nproc)" && sudo make install
enable_extension "$extension" "$prefix"
) >/dev/null 2>&1
add_extension_log "$extension-$org/$repo@$release" "Installed and enabled"
}

View File

@ -148,25 +148,6 @@ add_pecl_extension() {
fi fi
} }
# Function to install extension from source
add_extension_from_source() {
extension=$1
repo=$2
release=$3
args=$4
prefix=$5
(
add_devtools phpize
delete_extension "$extension"
get -q -n "/tmp/$extension.tar.gz" "https://github.com/$repo/archive/$release.tar.gz"
tar xf /tmp/"$extension".tar.gz -C /tmp
cd /tmp/"$extension-$release" || exit 1
phpize && ./configure "$args" && make -j"$(nproc)" && sudo make install
enable_extension "$extension" "$prefix"
) >/dev/null 2>&1
add_extension_log "$extension-$release" "Installed and enabled"
}
# Function to setup phpize and php-config. # Function to setup phpize and php-config.
add_devtools() { add_devtools() {
tool=$1 tool=$1