Add support for any git repository to compile extension from source

Add support for extensions in a subdirectory to compile from source
This commit is contained in:
Shivam Mathur 2021-03-17 04:48:19 +05:30
parent 6db6ddbab2
commit b3152daa8d
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
6 changed files with 91 additions and 51 deletions

View File

@ -154,7 +154,7 @@ describe('Extension tests', () => {
'linux'
);
expect(linux).toContain(
'add_extension_from_github mongodb mongodb mongo-php-driver master'
'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver . master extension'
);
});
@ -254,7 +254,7 @@ describe('Extension tests', () => {
'darwin'
);
expect(darwin).toContain(
'add_extension_from_github mongodb mongodb mongo-php-driver master'
'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver . master extension'
);
});
});

View File

@ -259,4 +259,31 @@ describe('Utils tests', () => {
await utils.customPackage('pkg8', 'ext', '1.2.3', 'linux')
).toContain(script_path + '\nadd_pkg 1.2.3');
});
it('checking parseExtensionSource', async () => {
expect(
await utils.parseExtensionSource(
'ext-org-name/repo-name@release',
'extension'
)
).toContain(
'\nadd_extension_from_source ext https://github.com org-name repo-name . release extension'
);
expect(
await utils.parseExtensionSource(
'ext-https://sub.domain.tld/org/repo@release',
'extension'
)
).toContain(
'\nadd_extension_from_source ext https://sub.domain.tld org repo . release extension'
);
expect(
await utils.parseExtensionSource(
'ext-https://sub.domain.XN--tld/org/repo/sub/dir@release',
'extension'
)
).toContain(
'\nadd_extension_from_source ext https://sub.domain.XN--tld org repo sub/dir release extension'
);
});
});

32
dist/index.js vendored
View File

@ -1805,17 +1805,14 @@ async function addExtensionDarwin(extension_csv, version) {
const version_extension = version + extension;
const [ext_name, ext_version] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches;
switch (true) {
// match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
// match extensions for compiling from source.
case /.+-.+\/.+@.+/.test(extension):
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension);
add_script += await utils.joins('\nadd_extension_from_github', ext_name, matches[1], matches[2], matches[3], ext_prefix);
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
@ -1958,17 +1955,14 @@ async function addExtensionLinux(extension_csv, version) {
const version_extension = version + extension;
const [ext_name, ext_version] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches;
switch (true) {
// Match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
// match extensions for compiling from source.
case /.+-.+\/.+@.+/.test(extension):
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension);
add_script += await utils.joins('\nadd_extension_from_github', ext_name, matches[1], matches[2], matches[3], ext_prefix);
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
@ -2644,7 +2638,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.fetch = exports.getInput = exports.readEnv = void 0;
exports.parseExtensionSource = exports.customPackage = exports.scriptTool = exports.scriptExtension = exports.joins = exports.getCommand = exports.getUnsupportedLog = exports.suppressOutput = exports.getExtensionPrefix = exports.CSVArray = exports.extensionArray = exports.writeScript = exports.readScript = exports.addLog = exports.stepLog = exports.log = exports.color = exports.asyncForEach = exports.parseVersion = exports.fetch = exports.getInput = exports.readEnv = void 0;
const fs = __importStar(__nccwpck_require__(747));
const https = __importStar(__nccwpck_require__(211));
const path = __importStar(__nccwpck_require__(622));
@ -3002,6 +2996,22 @@ async function customPackage(pkg, type, version, os_version) {
return '\n. ' + script + '\n' + command + version;
}
exports.customPackage = customPackage;
/**
* Function to extension input for installation from source.
*
* @param extension
*/
async function parseExtensionSource(extension, prefix) {
var _a, _b;
// Groups: extension, domain url, org, repo, subdirectory, release
// https://regex101.com/r/P3rJiy/1
const regex = /(\w+)-(.+:\/\/.+(?:[.:][^/]+)+)?(?:\/)?([^/]+)\/([^/]+)(?:\/)?(.+)*@(.+)/;
const matches = regex.exec(extension);
matches[2] = (_a = matches[2]) !== null && _a !== void 0 ? _a : 'https://github.com';
matches[5] = (_b = matches[5]) !== null && _b !== void 0 ? _b : '.';
return await joins('\nadd_extension_from_source', ...matches.splice(1, matches.length), prefix);
}
exports.parseExtensionSource = parseExtensionSource;
/***/ }),

View File

@ -17,25 +17,15 @@ export async function addExtensionDarwin(
const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches: RegExpExecArray;
switch (true) {
// match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
// match extensions for compiling from source.
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
);
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
@ -236,25 +226,15 @@ export async function addExtensionLinux(
const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name);
let matches: RegExpExecArray;
switch (true) {
// Match :extension
case /^:/.test(ext_name):
remove_script += '\nremove_extension ' + ext_name.slice(1);
return;
// match extensions from GitHub. Do this before checking for semver as
// the version may match that as well
// match extensions for compiling from source.
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
);
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)

View File

@ -312,23 +312,26 @@ add_libs() {
fi
}
# Function to install extension from a GitHub repository
add_extension_from_github() {
# Function to install extension from a git repository
add_extension_from_source() {
extension=$1
org=$2
repo=$3
release=$4
prefix=$5
slug="$extension-$org/$repo@$release"
domain=$2
org=$3
repo=$4
sub_dir=$5
release=$6
prefix=$7
slug="$extension-$release"
IFS=' ' read -r -a libs <<< "$(parse_args "$extension" LIBS)"
IFS=' ' read -r -a opts <<< "$(parse_args "$extension" CONFIGURE_OPTS)"
IFS=' ' read -r -a prefix_opts <<< "$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
IFS=' ' read -r -a suffix_opts <<< "$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$slug" "Click for $extension installation logs"
(
add_devtools phpize >/dev/null
delete_extension "$extension"
git clone -q -n https://github.com/"$org"/"$repo" /tmp/"$repo-$release"
cd /tmp/"$repo-$release" || exit 1
git clone -q -n "$domain/$org/$repo" /tmp/"$repo-$release"
cd /tmp/"$repo-$release/$sub_dir" || exit 1
git checkout -q "$release"
if [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \;| wc -l)" != "0" ]; then
git submodule -q update --init --recursive
@ -337,11 +340,9 @@ add_extension_from_github() {
sudo make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" && sudo make install
enable_extension "$extension" "$prefix"
else
add_log "$cross" "$slug" "Provided repository does not contain a PHP extension"
add_log "$cross" "$domain/$org/$repo" "Provided repository does not contain a PHP extension"
fi
) | sudo tee "/tmp/$extension@$release.log" >/dev/null
add_extension_log "$slug" "Installed and enabled"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$slug" "Click to get the logs of compiling $extension"
cat "/tmp/$extension@$release.log"
)
echo "::endgroup::"
add_extension_log "$slug" "Installed and enabled from $domain/$org/$repo"
}

View File

@ -438,3 +438,25 @@ export async function customPackage(
const command: string = await getCommand(os_version, pkg_name);
return '\n. ' + script + '\n' + command + version;
}
/**
* Function to extension input for installation from source.
*
* @param extension
*/
export async function parseExtensionSource(
extension: string,
prefix: string
): Promise<string> {
// Groups: extension, domain url, org, repo, subdirectory, release
// https://regex101.com/r/P3rJiy/1
const regex = /(\w+)-(.+:\/\/.+(?:[.:][^/]+)+)?(?:\/)?([^/]+)\/([^/]+)(?:\/)?(.+)*@(.+)/;
const matches = regex.exec(extension) as RegExpExecArray;
matches[2] = matches[2] ?? 'https://github.com';
matches[5] = matches[5] ?? '.';
return await joins(
'\nadd_extension_from_source',
...matches.splice(1, matches.length),
prefix
);
}