mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 05:23:03 +07:00
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:
parent
6db6ddbab2
commit
b3152daa8d
@ -154,7 +154,7 @@ describe('Extension tests', () => {
|
|||||||
'linux'
|
'linux'
|
||||||
);
|
);
|
||||||
expect(linux).toContain(
|
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'
|
'darwin'
|
||||||
);
|
);
|
||||||
expect(darwin).toContain(
|
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'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -259,4 +259,31 @@ describe('Utils tests', () => {
|
|||||||
await utils.customPackage('pkg8', 'ext', '1.2.3', 'linux')
|
await utils.customPackage('pkg8', 'ext', '1.2.3', 'linux')
|
||||||
).toContain(script_path + '\nadd_pkg 1.2.3');
|
).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
32
dist/index.js
vendored
@ -1805,17 +1805,14 @@ 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):
|
||||||
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
||||||
return;
|
return;
|
||||||
// match extensions from GitHub. Do this before checking for semver as
|
// match extensions for compiling from source.
|
||||||
// the version may match that as well
|
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension);
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
add_script += await utils.joins('\nadd_extension_from_github', ext_name, matches[1], matches[2], matches[3], ext_prefix);
|
|
||||||
return;
|
return;
|
||||||
// match 5.3blackfire...8.0blackfire
|
// match 5.3blackfire...8.0blackfire
|
||||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||||
@ -1958,17 +1955,14 @@ 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):
|
||||||
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
||||||
return;
|
return;
|
||||||
// match extensions from GitHub. Do this before checking for semver as
|
// match extensions for compiling from source.
|
||||||
// the version may match that as well
|
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension);
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
add_script += await utils.joins('\nadd_extension_from_github', ext_name, matches[1], matches[2], matches[3], ext_prefix);
|
|
||||||
return;
|
return;
|
||||||
// match 5.3blackfire...8.0blackfire
|
// match 5.3blackfire...8.0blackfire
|
||||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||||
@ -2644,7 +2638,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
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 fs = __importStar(__nccwpck_require__(747));
|
||||||
const https = __importStar(__nccwpck_require__(211));
|
const https = __importStar(__nccwpck_require__(211));
|
||||||
const path = __importStar(__nccwpck_require__(622));
|
const path = __importStar(__nccwpck_require__(622));
|
||||||
@ -3002,6 +2996,22 @@ async function customPackage(pkg, type, version, os_version) {
|
|||||||
return '\n. ' + script + '\n' + command + version;
|
return '\n. ' + script + '\n' + command + version;
|
||||||
}
|
}
|
||||||
exports.customPackage = customPackage;
|
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;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -17,25 +17,15 @@ 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):
|
||||||
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
||||||
return;
|
return;
|
||||||
// match extensions from GitHub. Do this before checking for semver as
|
// match extensions for compiling from source.
|
||||||
// the version may match that as well
|
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension) as RegExpExecArray;
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
add_script += await utils.joins(
|
|
||||||
'\nadd_extension_from_github',
|
|
||||||
ext_name,
|
|
||||||
matches[1],
|
|
||||||
matches[2],
|
|
||||||
matches[3],
|
|
||||||
ext_prefix
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
// match 5.3blackfire...8.0blackfire
|
// match 5.3blackfire...8.0blackfire
|
||||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||||
@ -236,25 +226,15 @@ 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):
|
||||||
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
remove_script += '\nremove_extension ' + ext_name.slice(1);
|
||||||
return;
|
return;
|
||||||
// match extensions from GitHub. Do this before checking for semver as
|
// match extensions for compiling from source.
|
||||||
// the version may match that as well
|
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
matches = /.+-(.+)\/(.+)@(.+)/.exec(extension) as RegExpExecArray;
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
add_script += await utils.joins(
|
|
||||||
'\nadd_extension_from_github',
|
|
||||||
ext_name,
|
|
||||||
matches[1],
|
|
||||||
matches[2],
|
|
||||||
matches[3],
|
|
||||||
ext_prefix
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
// match 5.3blackfire...8.0blackfire
|
// match 5.3blackfire...8.0blackfire
|
||||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||||
|
@ -312,23 +312,26 @@ add_libs() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install extension from a GitHub repository
|
# Function to install extension from a git repository
|
||||||
add_extension_from_github() {
|
add_extension_from_source() {
|
||||||
extension=$1
|
extension=$1
|
||||||
org=$2
|
domain=$2
|
||||||
repo=$3
|
org=$3
|
||||||
release=$4
|
repo=$4
|
||||||
prefix=$5
|
sub_dir=$5
|
||||||
slug="$extension-$org/$repo@$release"
|
release=$6
|
||||||
|
prefix=$7
|
||||||
|
slug="$extension-$release"
|
||||||
IFS=' ' read -r -a libs <<< "$(parse_args "$extension" LIBS)"
|
IFS=' ' read -r -a libs <<< "$(parse_args "$extension" LIBS)"
|
||||||
IFS=' ' read -r -a opts <<< "$(parse_args "$extension" CONFIGURE_OPTS)"
|
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 prefix_opts <<< "$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
|
||||||
IFS=' ' read -r -a suffix_opts <<< "$(parse_args "$extension" CONFIGURE_SUFFIX_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
|
add_devtools phpize >/dev/null
|
||||||
delete_extension "$extension"
|
delete_extension "$extension"
|
||||||
git clone -q -n https://github.com/"$org"/"$repo" /tmp/"$repo-$release"
|
git clone -q -n "$domain/$org/$repo" /tmp/"$repo-$release"
|
||||||
cd /tmp/"$repo-$release" || exit 1
|
cd /tmp/"$repo-$release/$sub_dir" || exit 1
|
||||||
git checkout -q "$release"
|
git checkout -q "$release"
|
||||||
if [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \;| wc -l)" != "0" ]; then
|
if [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \;| wc -l)" != "0" ]; then
|
||||||
git submodule -q update --init --recursive
|
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
|
sudo make -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu)" && sudo make install
|
||||||
enable_extension "$extension" "$prefix"
|
enable_extension "$extension" "$prefix"
|
||||||
else
|
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
|
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::"
|
echo "::endgroup::"
|
||||||
|
add_extension_log "$slug" "Installed and enabled from $domain/$org/$repo"
|
||||||
}
|
}
|
||||||
|
22
src/utils.ts
22
src/utils.ts
@ -438,3 +438,25 @@ export async function customPackage(
|
|||||||
const command: string = await getCommand(os_version, pkg_name);
|
const command: string = await getCommand(os_version, pkg_name);
|
||||||
return '\n. ' + script + '\n' + command + version;
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user