Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96afc02cad | ||
|
|
024a2e796f | ||
|
|
65ea75914e | ||
|
|
b9734e30e3 | ||
|
|
a91eaeae66 | ||
|
|
5fd9e31957 | ||
|
|
3a9c03a639 | ||
|
|
7c356bdccc | ||
|
|
dc78eb217c | ||
|
|
b98cea8adc | ||
|
|
470b94d722 | ||
|
|
acce7e61bc | ||
|
|
c2ce0737e9 | ||
|
|
a6cb9851d8 | ||
|
|
9d87cbc9e2 | ||
|
|
dfaa2c7ea5 | ||
|
|
a0bace7fd6 | ||
|
|
3da1e049db |
@@ -12,12 +12,5 @@
|
||||
"plugin:prettier/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"plugins": ["@typescript-eslint", "jest"],
|
||||
"rules": {
|
||||
"camelcase": "off",
|
||||
"require-atomic-updates": "off",
|
||||
"@typescript-eslint/ban-ts-ignore": "off",
|
||||
"@typescript-eslint/camelcase": "off",
|
||||
"@typescript-eslint/no-unused-vars": "off"
|
||||
}
|
||||
"plugins": ["@typescript-eslint", "jest"]
|
||||
}
|
||||
10
README.md
10
README.md
@@ -7,7 +7,7 @@
|
||||
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.3%20to%208.1-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a>
|
||||
</p>
|
||||
|
||||
Cache PHP extensions in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action has to be used along with [shivammathur/setup-php](https://github.com/shivammathur/setup-php "Setup PHP") and [actions/cache](https://github.com/actions/cache "Cache in GitHub Actions") GitHub Actions. It configures the environment required to cache PHP extensions. Refer to [Usage](#memo-usage "How to use this") section to see how to use this.
|
||||
Cache PHP extensions in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action has to be used along with [shivammathur/setup-php](https://github.com/shivammathur/setup-php "Setup PHP") and [actions/cache](https://github.com/actions/cache "Cache in GitHub Actions") GitHub Actions. It configures the environment required to cache PHP extensions. Refer to [Usage](#memo-usage "How to use this") section for details and example workflow.
|
||||
|
||||
## Contents
|
||||
|
||||
@@ -47,7 +47,7 @@ Cache PHP extensions in [GitHub Actions](https://github.com/features/actions "Gi
|
||||
|Ubuntu 18.04|`ubuntu-18.04`|
|
||||
|Ubuntu 16.04|`ubuntu-16.04`|
|
||||
|macOS Catalina 10.15|`macos-latest` or `macOS-10.15`|
|
||||
|macOS Big Sur 11.0|`macOS-11.0`|
|
||||
|macOS Big Sur 11.x|`macOS-11.0`|
|
||||
|
||||
## :memo: Usage
|
||||
|
||||
@@ -57,14 +57,14 @@ Use this GitHub Action when the extensions you are adding in [setup-php](https:/
|
||||
|
||||
#### `php-version` (required)
|
||||
|
||||
- Specify the PHP version you want to set up.
|
||||
- Specify the PHP version you want to set-up.
|
||||
- Accepts a `string`. For example `'7.4'`.
|
||||
- See [PHP support](#tada-php-support) for supported PHP versions.
|
||||
|
||||
#### `extensions` (required)
|
||||
|
||||
- Specify the extensions you want to add or remove.
|
||||
- Accepts a `string` in csv-format. For example `mbstring, , xdebug, :opcache`.
|
||||
- Specify the extensions you want to setup.
|
||||
- Accepts a `string` in csv-format. For example `mbstring, xdebug, :opcache`.
|
||||
- Extensions prefixed with `:` are ignored.
|
||||
|
||||
#### `key` (required)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import path from 'path';
|
||||
import * as cache from '../src/cache';
|
||||
import * as utils from '../src/utils';
|
||||
|
||||
@@ -5,21 +6,16 @@ import * as utils from '../src/utils';
|
||||
* Mock cache.ts
|
||||
*/
|
||||
jest.mock('../src/cache', () => ({
|
||||
run: jest.fn().mockImplementation(
|
||||
async (): Promise<string> => {
|
||||
let version: string = process.env['php-version'] || '';
|
||||
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
|
||||
const extensions = await utils.filterExtensions(
|
||||
process.env['extensions'] || ''
|
||||
);
|
||||
const key: string = process.env['key'] || '';
|
||||
const script_path = 'extensions.sh';
|
||||
|
||||
return (
|
||||
'bash ' + script_path + ' "' + extensions + '" ' + key + ' ' + version
|
||||
);
|
||||
}
|
||||
)
|
||||
run: jest.fn().mockImplementation(async (): Promise<string> => {
|
||||
const version: string = await utils.parseVersion(
|
||||
process.env['php-version'] || ''
|
||||
);
|
||||
const extensions = await utils.filterExtensions(
|
||||
process.env['extensions'] || ''
|
||||
);
|
||||
const key: string = process.env['key'] || '';
|
||||
return await utils.scriptCall('test', extensions, key, version);
|
||||
})
|
||||
}));
|
||||
|
||||
/**
|
||||
@@ -40,21 +36,22 @@ function setEnv(
|
||||
}
|
||||
|
||||
describe('Install', () => {
|
||||
const spath: string = path.join(__dirname, '../src/scripts/cache.sh');
|
||||
it('Test Run', async () => {
|
||||
setEnv('7.0', 'xdebug, pcov', 'cache-v1');
|
||||
const script: string = '' + (await cache.run());
|
||||
expect(script).toContain('bash extensions.sh "xdebug, pcov" cache-v1 7.0');
|
||||
expect(script).toContain(`bash ${spath} test "xdebug, pcov" cache-v1 7.0`);
|
||||
});
|
||||
|
||||
it('Test Run', async () => {
|
||||
setEnv('7.4', 'xdebug, zip', 'cache-v2');
|
||||
const script: string = '' + (await cache.run());
|
||||
expect(script).toContain('bash extensions.sh "xdebug, zip" cache-v2 7.4');
|
||||
expect(script).toContain(`bash ${spath} test "xdebug, zip" cache-v2 7.4`);
|
||||
});
|
||||
|
||||
it('Test Run', async () => {
|
||||
setEnv('7.4', 'xdebug, :zip', 'cache-v2');
|
||||
const script: string = '' + (await cache.run());
|
||||
expect(script).toContain('bash extensions.sh "xdebug" cache-v2 7.4');
|
||||
expect(script).toContain(`bash ${spath} test "xdebug" cache-v2 7.4`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as utils from '../src/utils';
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
@@ -6,6 +8,14 @@ jest.mock('@actions/core', () => ({
|
||||
})
|
||||
}));
|
||||
|
||||
async function cleanup(path: string): Promise<void> {
|
||||
fs.unlink(path, error => {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe('Utils tests', () => {
|
||||
it('checking readEnv', async () => {
|
||||
process.env['test'] = 'setup-php';
|
||||
@@ -20,11 +30,19 @@ describe('Utils tests', () => {
|
||||
'cache-extensions'
|
||||
);
|
||||
expect(await utils.getInput('DoesNotExist', false)).toBe('');
|
||||
expect(async () => {
|
||||
await expect(async () => {
|
||||
await utils.getInput('DoesNotExist', true);
|
||||
}).rejects.toThrow('Input required and not supplied: DoesNotExist');
|
||||
});
|
||||
|
||||
it('checking getOutput', async () => {
|
||||
const temp_dir: string = process.env['RUNNER_TEMP'] || '';
|
||||
const file_path: string = path.join(temp_dir, 'test');
|
||||
fs.writeFileSync(file_path, 'test', {mode: 0o755});
|
||||
expect(await utils.getOutput('test')).toBe('test');
|
||||
await cleanup(file_path);
|
||||
});
|
||||
|
||||
it('checking parseVersion', async () => {
|
||||
expect(await utils.parseVersion('7')).toBe('7.0');
|
||||
expect(await utils.parseVersion('7.4')).toBe('7.4');
|
||||
@@ -32,7 +50,7 @@ describe('Utils tests', () => {
|
||||
});
|
||||
|
||||
it('checking filterExtensions', async () => {
|
||||
expect(await utils.filterExtensions('a,:b,c')).toBe('a,c');
|
||||
expect(await utils.filterExtensions('a, :b, c')).toBe('a, c');
|
||||
expect(await utils.filterExtensions('a,:b,c')).toBe('"a,c"');
|
||||
expect(await utils.filterExtensions('a, :b, c')).toBe('"a, c"');
|
||||
});
|
||||
});
|
||||
|
||||
59432
dist/index.js
vendored
59432
dist/index.js
vendored
File diff suppressed because one or more lines are too long
10627
package-lock.json
generated
10627
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
46
package.json
46
package.json
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"name": "cache-extensions",
|
||||
"version": "1.5.1",
|
||||
"version": "1.6.0",
|
||||
"private": false,
|
||||
"description": "Cache extensions in GitHub Actions",
|
||||
"main": "dist/index.js",
|
||||
"description": "Cache PHP extensions in GitHub Actions",
|
||||
"main": "lib/cache.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "eslint **/*.ts --cache",
|
||||
"format": "prettier --write **/*.ts && git add .",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"release": "ncc build src/cache.ts -o dist && git add -f dist/",
|
||||
"release": "ncc build -o dist && git add -f dist/",
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
@@ -19,31 +19,33 @@
|
||||
"keywords": [
|
||||
"actions",
|
||||
"php",
|
||||
"setup"
|
||||
"extension",
|
||||
"cache"
|
||||
],
|
||||
"author": "shivammathur",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.4"
|
||||
"@actions/cache": "^1.0.7",
|
||||
"@actions/core": "^1.4.0",
|
||||
"@actions/exec": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.20",
|
||||
"@types/node": "^14.14.34",
|
||||
"@typescript-eslint/eslint-plugin": "^4.17.0",
|
||||
"@typescript-eslint/parser": "^4.17.0",
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"eslint": "^7.21.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-jest": "^24.2.1",
|
||||
"eslint-plugin-prettier": "^3.3.1",
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/node": "^15.14.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.1",
|
||||
"@typescript-eslint/parser": "^4.28.1",
|
||||
"@vercel/ncc": "^0.28.6",
|
||||
"eslint": "^7.29.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.23.4",
|
||||
"eslint-plugin-jest": "^24.3.6",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"husky": "^4.3.8",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"prettier": "^2.2.1",
|
||||
"ts-jest": "^26.5.3",
|
||||
"typescript": "^4.2.3"
|
||||
"jest": "^27.0.6",
|
||||
"jest-circus": "^27.0.6",
|
||||
"prettier": "^2.3.2",
|
||||
"ts-jest": "^27.0.3",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"husky": {
|
||||
"skipCI": true,
|
||||
|
||||
41
src/cache.ts
41
src/cache.ts
@@ -1,8 +1,37 @@
|
||||
import {exec} from '@actions/exec';
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as path from 'path';
|
||||
import * as utils from './utils';
|
||||
|
||||
/**
|
||||
* Handle dependencies
|
||||
*
|
||||
* @param extensions
|
||||
* @param version
|
||||
*/
|
||||
export async function handleDependencies(
|
||||
extensions: string,
|
||||
version: string
|
||||
): Promise<void> {
|
||||
if (!/^5.[3-5]$/.test(version) && /linux|darwin/.test(process.platform)) {
|
||||
const cache_key: string = (await utils.getOutput('key')) + '-deps';
|
||||
const cache_dir: string = path.join(
|
||||
await utils.readEnv('RUNNER_TOOL_CACHE'),
|
||||
'deps'
|
||||
);
|
||||
const cache_hit: string | undefined = await cache.restoreCache(
|
||||
[cache_dir],
|
||||
cache_key,
|
||||
[cache_key]
|
||||
);
|
||||
await exec(await utils.scriptCall('dependencies', extensions, version));
|
||||
if (!cache_hit) {
|
||||
await cache.saveCache([cache_dir], cache_key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the script
|
||||
*/
|
||||
@@ -15,14 +44,16 @@ export async function run(): Promise<void> {
|
||||
await utils.getInput('extensions', true)
|
||||
);
|
||||
const key: string = await utils.getInput('key', true);
|
||||
const script_path: string = path.join(__dirname, '../src/extensions.sh');
|
||||
await exec(
|
||||
'bash ' + script_path + ' "' + extensions + '" ' + key + ' ' + version
|
||||
);
|
||||
await exec(await utils.scriptCall('data', extensions, version, key));
|
||||
await handleDependencies(extensions, version);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// call the run function
|
||||
run();
|
||||
(async () => {
|
||||
await run();
|
||||
})().catch(error => {
|
||||
core.setFailed(error.message);
|
||||
});
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
step_log() {
|
||||
message=$1
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||
}
|
||||
|
||||
add_log() {
|
||||
mark=$1
|
||||
shift
|
||||
subjects=("$@")
|
||||
for subject in "${subjects[@]}"; do
|
||||
if [ "$mark" = "$tick" ]; then
|
||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "Added $subject"
|
||||
else
|
||||
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "Failed to setup $subject"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
fix_ownership() {
|
||||
dir=$1
|
||||
sudo chown -R "$USER":"$(id -g -n)" "$(dirname "$dir")"
|
||||
}
|
||||
|
||||
link_apt_fast() {
|
||||
if ! command -v apt-fast >/dev/null; then
|
||||
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
|
||||
fi
|
||||
}
|
||||
|
||||
fetch_package() {
|
||||
if ! [ -e /tmp/Packages ]; then
|
||||
deb_build_arch=$(dpkg-architecture -q DEB_BUILD_ARCH)
|
||||
curl -o /tmp/Packages.gz -sL "http://ppa.launchpad.net/ondrej/php/ubuntu/dists/$DISTRIB_CODENAME/main/binary-$deb_build_arch/Packages.gz"
|
||||
gzip -df /tmp/Packages.gz
|
||||
fi
|
||||
}
|
||||
|
||||
get_dependencies() {
|
||||
package=$1
|
||||
prefix=$2
|
||||
sed -e '/Package:\s'"$package$"'/,/^\s*$/!d' /tmp/Packages | grep -Eo "^Depends.*" | tr ',' '\n' | awk -v ORS='' '/^\s'"$prefix"'/{print$0}' | sed -e 's/([^()]*)//g' | sort | uniq | xargs echo -n
|
||||
}
|
||||
|
||||
get_package_link() {
|
||||
package=$1
|
||||
trunk="http://ppa.launchpad.net/ondrej/php/ubuntu"
|
||||
file=$(sed -e '/Package:\s'"$package$"'/,/^\s*$/!d' /tmp/Packages | grep -Eo "^Filename.*" | cut -d' ' -f 2 | tr -d '\r')
|
||||
echo "$trunk/$file"
|
||||
}
|
||||
|
||||
linux_extension_dir() {
|
||||
api_version=$1
|
||||
if [[ "$version" =~ $old_versions ]]; then
|
||||
echo "/usr/lib/php5/$api_version"
|
||||
elif [[ "$version" =~ 5.3|$nightly_versions ]]; then
|
||||
echo "/usr/local/php/$version/lib/php/extensions/no-debug-non-zts-$api_version"
|
||||
else
|
||||
echo "/usr/lib/php/$api_version"
|
||||
fi
|
||||
}
|
||||
|
||||
darwin_extension_dir() {
|
||||
api_version=$1
|
||||
old_versions_darwin="5.[3-5]"
|
||||
if [[ "$version" =~ $old_versions_darwin ]]; then
|
||||
echo "/opt/local/lib/php${version/./}/extensions/no-debug-non-zts-$api_version"
|
||||
else
|
||||
if [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]]; then
|
||||
echo "/opt/homebrew/lib/php/pecl/$api_version"
|
||||
else
|
||||
echo "/usr/local/lib/php/pecl/$api_version"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
get_api_version() {
|
||||
case $version in
|
||||
5.3) echo "20090626" ;;
|
||||
5.4) echo "20100525" ;;
|
||||
5.5) echo "20121212" ;;
|
||||
5.6) echo "20131226" ;;
|
||||
7.0) echo "20151012" ;;
|
||||
7.1) echo "20160303" ;;
|
||||
7.2) echo "20170718" ;;
|
||||
7.3) echo "20180731" ;;
|
||||
7.4) echo "20190902" ;;
|
||||
8.0) echo "20200930" ;;
|
||||
*)
|
||||
php_header="https://raw.githubusercontent.com/php/php-src/master/main/php.h"
|
||||
curl -sSL --retry 5 "$php_header" | grep "PHP_API_VERSION" | cut -d' ' -f 3
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
add_config() {
|
||||
dependent_extension=$1
|
||||
dependency_extension=$2
|
||||
echo "$dependency_extension" | sudo tee "$cache_directory/$dependent_extension/$dependency_extension" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
setup_extension() {
|
||||
dependent_extension=$1
|
||||
dependency_extension=$2
|
||||
extension_dir=$3
|
||||
if ! [ -e "$extension_dir/$dependency_extension.so" ]; then
|
||||
extension_package_link="$(get_package_link "php$version-$dependency_extension")"
|
||||
sudo curl -H "User-Agent: Debian APT-HTTP/GHA(ce)" -o "$dependency_extension".deb -sL "$extension_package_link"
|
||||
sudo dpkg-deb -x "$dependency_extension".deb /
|
||||
fix_ownership "$dir"
|
||||
fi
|
||||
if [ -e "$extension_dir/$dependency_extension.so" ]; then
|
||||
add_config "$dependent_extension" "$dependency_extension"
|
||||
add_log "$tick" "$dependency_extension"
|
||||
else
|
||||
add_log "$cross" "$dependency_extension"
|
||||
fi
|
||||
}
|
||||
|
||||
filter_dependencies_libs() {
|
||||
libraries="$(echo "$1" | xargs -n1 | uniq | xargs)"
|
||||
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
|
||||
for library in $libraries; do
|
||||
if grep -i -q -w "$library" "$script_dir"/lists/"$DISTRIB_CODENAME"-libs; then
|
||||
libraries=${libraries//$library/}
|
||||
fi
|
||||
done
|
||||
echo "$libraries"
|
||||
}
|
||||
|
||||
setup_dependencies_libs() {
|
||||
libraries=$1
|
||||
if [[ -n "${libraries// }" ]]; then
|
||||
libraries=$(filter_dependencies_libs "$libraries")
|
||||
if [[ -n "${libraries// }" ]]; then
|
||||
step_log "Setup libraries"
|
||||
IFS=' ' read -r -a libraries_array <<<"$libraries"
|
||||
link_apt_fast
|
||||
(
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-fast install --no-install-recommends --no-upgrade -y "${libraries_array[@]}" >/dev/null 2>&1 &&
|
||||
add_log "$tick" "${libraries_array[@]}"
|
||||
) || add_log "$cross" "${libraries_array[@]}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
setup_dependencies_extensions() {
|
||||
extension_dir=$1
|
||||
shift
|
||||
extensions_array=("$@")
|
||||
. /etc/lsb-release
|
||||
cache_directory=/tmp/extcache
|
||||
sudo rm -rf "$cache_directory" || true
|
||||
libraries=""
|
||||
for extension_package in "${extensions_array[@]}"; do
|
||||
fetch_package
|
||||
libraries="$libraries $(get_dependencies "$extension_package" "lib")"
|
||||
extension="${extension_package/php$version-/}"
|
||||
if ! [ -d "$cache_directory"/"$extension" ]; then
|
||||
extension_dependencies=$(get_dependencies "$extension_package" "php$version-")
|
||||
extension_dependencies="${extension_dependencies//php$version-common/}"
|
||||
if [[ -n "${extension_dependencies// }" ]]; then
|
||||
step_log "Setup extensions for $extension"
|
||||
extension_dependencies_array=()
|
||||
IFS=' ' read -r -a extension_dependencies_array <<<"$extension_dependencies"
|
||||
sudo mkdir -p "$cache_directory"/"$extension"
|
||||
(
|
||||
cd "$cache_directory" || exit 1
|
||||
to_wait=()
|
||||
for extension_dependeny_package in "${extension_dependencies_array[@]}"; do
|
||||
if [[ -n "${extension_dependeny_package// }" ]]; then
|
||||
extension_dependency=${extension_dependeny_package/php$version-/}
|
||||
setup_extension "$extension" "$extension_dependency" "$extension_dir" &
|
||||
to_wait+=($!)
|
||||
fi
|
||||
done
|
||||
wait "${to_wait[@]}"
|
||||
)
|
||||
fi
|
||||
fi
|
||||
done
|
||||
setup_dependencies_libs "$libraries"
|
||||
}
|
||||
|
||||
setup_dependencies() {
|
||||
extensions=$1
|
||||
extension_dir=$2
|
||||
if [[ -n "${extensions// }" ]]; then
|
||||
IFS=' ' read -r -a extensions_array <<<"$(echo "$extensions" | sed -e "s/pdo[_-]//g" -Ee "s/^|,\s*/ php$version-/g")"
|
||||
setup_dependencies_extensions "$extension_dir" "${extensions_array[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
extensions=$1
|
||||
key=$2
|
||||
version=$3
|
||||
tick="✓"
|
||||
cross="✗"
|
||||
os=$(uname -s)
|
||||
old_versions="5.[4-5]"
|
||||
nightly_versions="8.[1-9]"
|
||||
if [ "$os" = "Linux" ]; then
|
||||
. /etc/lsb-release
|
||||
os=$os-$DISTRIB_CODENAME
|
||||
api_version=$(get_api_version)
|
||||
dir=$(linux_extension_dir "$api_version")
|
||||
sudo mkdir -p "$dir" && fix_ownership "$dir"
|
||||
setup_dependencies "$extensions" "$dir"
|
||||
elif [ "$os" = "Darwin" ]; then
|
||||
api_version=$(get_api_version)
|
||||
dir=$(darwin_extension_dir "$api_version")
|
||||
sudo mkdir -p "$dir" && fix_ownership "$dir"
|
||||
else
|
||||
os="Windows"
|
||||
dir='C:\\tools\\php\\ext'
|
||||
fi
|
||||
key="$os"-ext-"$version"-$(echo -n "$extensions-$key" | openssl dgst -sha256 | cut -d ' ' -f 2)
|
||||
key="$key-20210313"
|
||||
echo "::set-output name=dir::$dir"
|
||||
echo "::set-output name=key::$key"
|
||||
@@ -70,15 +70,12 @@ libcgi-fast-perl
|
||||
libcgi-pm-perl
|
||||
libcgroup1
|
||||
libcilkrts5
|
||||
libclang-common-6.0-dev
|
||||
libclang-common-8-dev
|
||||
libclang-common-9-dev
|
||||
libclang-cpp9
|
||||
libclang1-6.0
|
||||
libclang1-8
|
||||
libclang1-9
|
||||
libcolord2
|
||||
libcom-err2
|
||||
libcommon-sense-perl
|
||||
libcroco3
|
||||
libcryptsetup12
|
||||
libcups2
|
||||
@@ -153,7 +150,6 @@ libgbm1
|
||||
libgc1c2
|
||||
libgcc-10-dev
|
||||
libgcc-7-dev
|
||||
libgcc-8-dev
|
||||
libgcc-9-dev
|
||||
libgcc-s1
|
||||
libgcc1
|
||||
@@ -170,7 +166,6 @@ libgeoip1
|
||||
libgflags2.2
|
||||
libgfortran-10-dev
|
||||
libgfortran-7-dev
|
||||
libgfortran-8-dev
|
||||
libgfortran-9-dev
|
||||
libgfortran4
|
||||
libgfortran5
|
||||
@@ -274,7 +269,8 @@ libjs-jquery
|
||||
libjson-c3
|
||||
libjson-glib-1.0-0
|
||||
libjson-glib-1.0-common
|
||||
libjsoncpp1
|
||||
libjson-perl
|
||||
libjson-xs-perl
|
||||
libjte1
|
||||
libk5crypto3
|
||||
libkeyutils1
|
||||
@@ -291,12 +287,9 @@ liblcms2-dev
|
||||
libldap-2.4-2
|
||||
libldap-common
|
||||
libldb1
|
||||
liblldb-6.0
|
||||
liblldb-8
|
||||
liblldb-9
|
||||
libllvm10
|
||||
libllvm6.0
|
||||
libllvm8
|
||||
libllvm9
|
||||
liblmdb0
|
||||
liblocale-gettext-perl
|
||||
@@ -639,7 +632,6 @@ libssl1.0.0
|
||||
libssl1.1
|
||||
libstdc++-10-dev
|
||||
libstdc++-7-dev
|
||||
libstdc++-8-dev
|
||||
libstdc++-9-dev
|
||||
libstdc++6
|
||||
libstemmer0d
|
||||
@@ -673,6 +665,7 @@ libtommath1
|
||||
libtool
|
||||
libtry-tiny-perl
|
||||
libtsan0
|
||||
libtypes-serialiser-perl
|
||||
libu2f-udev
|
||||
libubsan0
|
||||
libubsan1
|
||||
|
||||
12
src/lists/darwin-extensions
Normal file
12
src/lists/darwin-extensions
Normal file
@@ -0,0 +1,12 @@
|
||||
amqp
|
||||
grpc
|
||||
imagick
|
||||
imap
|
||||
memcached
|
||||
pecl_http
|
||||
phalcon3
|
||||
phalcon4
|
||||
psr
|
||||
rdkafka
|
||||
redis
|
||||
zmq
|
||||
@@ -14,7 +14,6 @@ libapt-pkg6.0
|
||||
libarchive13
|
||||
libargon2-1
|
||||
libaria2-0
|
||||
libasan4
|
||||
libasan5
|
||||
libasan6
|
||||
libasn1-8-heimdal
|
||||
@@ -75,16 +74,18 @@ libcc1-0
|
||||
libcgi-fast-perl
|
||||
libcgi-pm-perl
|
||||
libcgroup1
|
||||
libcilkrts5
|
||||
libclang-common-10-dev
|
||||
libclang-common-8-dev
|
||||
libclang-common-9-dev
|
||||
libclang-common-11-dev
|
||||
libclang-common-12-dev
|
||||
libclang-cpp10
|
||||
libclang-cpp9
|
||||
libclang-cpp11
|
||||
libclang-cpp12
|
||||
libclang1-10
|
||||
libclang1-8
|
||||
libclang1-11
|
||||
libclang1-12
|
||||
libcolord2
|
||||
libcom-err2
|
||||
libcommon-sense-perl
|
||||
libcrypt-dev
|
||||
libcrypt1
|
||||
libcryptsetup12
|
||||
@@ -166,8 +167,6 @@ libgbm1
|
||||
libgc1c2
|
||||
libgcab-1.0-0
|
||||
libgcc-10-dev
|
||||
libgcc-7-dev
|
||||
libgcc-8-dev
|
||||
libgcc-9-dev
|
||||
libgcc-s1
|
||||
libgconf-2-4
|
||||
@@ -182,7 +181,6 @@ libgdk-pixbuf2.0-common
|
||||
libgdk-pixbuf2.0-dev
|
||||
libgflags2.2
|
||||
libgfortran-10-dev
|
||||
libgfortran-8-dev
|
||||
libgfortran-9-dev
|
||||
libgfortran5
|
||||
libgif7
|
||||
@@ -272,6 +270,8 @@ libjs-xmlextras
|
||||
libjson-c4
|
||||
libjson-glib-1.0-0
|
||||
libjson-glib-1.0-common
|
||||
libjson-perl
|
||||
libjson-xs-perl
|
||||
libjte2
|
||||
libk5crypto3
|
||||
libkeyutils1
|
||||
@@ -288,11 +288,11 @@ liblcms2-dev
|
||||
libldap-2.4-2
|
||||
libldap-common
|
||||
liblldb-10
|
||||
liblldb-8
|
||||
liblldb-9
|
||||
liblldb-11
|
||||
liblldb-12
|
||||
libllvm10
|
||||
libllvm11
|
||||
libllvm8
|
||||
libllvm12
|
||||
libllvm9
|
||||
liblmdb0
|
||||
liblocale-gettext-perl
|
||||
@@ -481,7 +481,6 @@ libmount1
|
||||
libmpc3
|
||||
libmpdec2
|
||||
libmpfr6
|
||||
libmpx2
|
||||
libmspack0
|
||||
libmysqlclient-dev
|
||||
libmysqlclient21
|
||||
@@ -515,13 +514,12 @@ libnss-systemd
|
||||
libnss3
|
||||
libntfs-3g883
|
||||
libnuma1
|
||||
libobjc-8-dev
|
||||
libobjc-9-dev
|
||||
libobjc4
|
||||
libodbc1
|
||||
libogg0
|
||||
libomp-10-dev
|
||||
libomp5-10
|
||||
libomp-11-dev
|
||||
libomp5-11
|
||||
libonig5
|
||||
libopenexr-dev
|
||||
libopenexr24
|
||||
@@ -636,8 +634,6 @@ libssh2-1
|
||||
libssl-dev
|
||||
libssl1.1
|
||||
libstdc++-10-dev
|
||||
libstdc++-7-dev
|
||||
libstdc++-8-dev
|
||||
libstdc++-9-dev
|
||||
libstdc++6
|
||||
libstemmer0d
|
||||
@@ -672,8 +668,8 @@ libtool
|
||||
libtry-tiny-perl
|
||||
libtsan0
|
||||
libtss2-esys0
|
||||
libtypes-serialiser-perl
|
||||
libu2f-udev
|
||||
libubsan0
|
||||
libubsan1
|
||||
libuchardet0
|
||||
libucl1
|
||||
|
||||
@@ -15,7 +15,6 @@ libapt-pkg5.0
|
||||
libarchive13
|
||||
libargon2-1
|
||||
libasan2
|
||||
libasan4
|
||||
libasan5
|
||||
libasn1-8-heimdal
|
||||
libasound2
|
||||
@@ -76,14 +75,11 @@ libcgi-pm-perl
|
||||
libcgraph6
|
||||
libcgroup1
|
||||
libcilkrts5
|
||||
libclang-common-6.0-dev
|
||||
libclang-common-8-dev
|
||||
libclang-common-9-dev
|
||||
libclang-cpp9
|
||||
libclang1-6.0
|
||||
libclang1-8
|
||||
libcolord2
|
||||
libcomerr2
|
||||
libcommon-sense-perl
|
||||
libcroco3
|
||||
libcryptsetup4
|
||||
libcups2
|
||||
@@ -154,8 +150,6 @@ libgbm-dev
|
||||
libgbm1
|
||||
libgc1c2
|
||||
libgcc-5-dev
|
||||
libgcc-7-dev
|
||||
libgcc-8-dev
|
||||
libgcc-9-dev
|
||||
libgcc1
|
||||
libgconf-2-4
|
||||
@@ -169,7 +163,6 @@ libgdk-pixbuf2.0-dev
|
||||
libgeoip1
|
||||
libgflags2v5
|
||||
libgfortran-5-dev
|
||||
libgfortran-8-dev
|
||||
libgfortran-9-dev
|
||||
libgfortran3
|
||||
libgfortran5
|
||||
@@ -260,7 +253,8 @@ libjs-jquery
|
||||
libjson-c2
|
||||
libjson-glib-1.0-0
|
||||
libjson-glib-1.0-common
|
||||
libjsoncpp1
|
||||
libjson-perl
|
||||
libjson-xs-perl
|
||||
libjte1
|
||||
libk5crypto3
|
||||
libkeyutils1
|
||||
@@ -276,11 +270,8 @@ liblcms2-2
|
||||
liblcms2-dev
|
||||
libldap-2.4-2
|
||||
libldb1
|
||||
liblldb-6.0
|
||||
liblldb-8
|
||||
liblldb-9
|
||||
libllvm6.0
|
||||
libllvm8
|
||||
libllvm9
|
||||
liblmdb0
|
||||
liblocale-gettext-perl
|
||||
@@ -474,7 +465,6 @@ libmpc3
|
||||
libmpdec2
|
||||
libmpfr4
|
||||
libmpx0
|
||||
libmpx2
|
||||
libmspack0
|
||||
libmysqlclient-dev
|
||||
libmysqlclient20
|
||||
@@ -617,8 +607,6 @@ libssl-doc
|
||||
libssl1.0.0
|
||||
libssl1.1
|
||||
libstdc++-5-dev
|
||||
libstdc++-7-dev
|
||||
libstdc++-8-dev
|
||||
libstdc++-9-dev
|
||||
libstdc++6
|
||||
libstemmer0d
|
||||
@@ -650,6 +638,7 @@ libtinyxml2-2v5
|
||||
libtk8.6
|
||||
libtool
|
||||
libtsan0
|
||||
libtypes-serialiser-perl
|
||||
libubsan0
|
||||
libubsan1
|
||||
libucl1
|
||||
|
||||
125
src/scripts/cache.sh
Normal file
125
src/scripts/cache.sh
Normal file
@@ -0,0 +1,125 @@
|
||||
step_log() {
|
||||
message=$1
|
||||
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
|
||||
}
|
||||
|
||||
add_log() {
|
||||
mark=$1
|
||||
shift
|
||||
subjects=("$@")
|
||||
for subject in "${subjects[@]}"; do
|
||||
if [ "$mark" = "$tick" ]; then
|
||||
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "Added $subject"
|
||||
else
|
||||
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "Failed to setup $subject"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
get_api_version_from_repo() {
|
||||
php_header="https://raw.githubusercontent.com/php/php-src/PHP-$version/main/php.h"
|
||||
status_code=$(curl -sSL -o /tmp/php.h -w "%{http_code}" "$php_header")
|
||||
if [ "$status_code" != "200" ]; then
|
||||
curl -sSL --retry 5 "${php_header/PHP-$version/master}" | grep "PHP_API_VERSION" | cut -d' ' -f 3
|
||||
else
|
||||
grep "PHP_API_VERSION" /tmp/php.h | cut -d' ' -f 3
|
||||
fi
|
||||
}
|
||||
|
||||
get_api_version() {
|
||||
case $version in
|
||||
5.3) echo "20090626" ;;
|
||||
5.4) echo "20100525" ;;
|
||||
5.5) echo "20121212" ;;
|
||||
5.6) echo "20131226" ;;
|
||||
7.0) echo "20151012" ;;
|
||||
7.1) echo "20160303" ;;
|
||||
7.2) echo "20170718" ;;
|
||||
7.3) echo "20180731" ;;
|
||||
7.4) echo "20190902" ;;
|
||||
8.0) echo "20200930" ;;
|
||||
*) get_api_version_from_repo ;;
|
||||
esac
|
||||
}
|
||||
|
||||
fix_ownership() {
|
||||
dir=$1
|
||||
sudo chown -R "$USER":"$(id -g -n)" "$(dirname "$dir")"
|
||||
}
|
||||
|
||||
add_config() {
|
||||
dependent_extension=$1
|
||||
dependency_extension=$2
|
||||
echo "$dependency_extension" | sudo tee "${ext_config_directory:?}/$dependent_extension/$dependency_extension" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
extension_dir_darwin() {
|
||||
api_version=$1
|
||||
if [[ "${version:?}" =~ ${old_versions:?} ]]; then
|
||||
echo "/opt/local/lib/php${version/./}/extensions/no-debug-non-zts-$api_version"
|
||||
else
|
||||
if [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]]; then
|
||||
echo "/opt/homebrew/lib/php/pecl/$api_version"
|
||||
else
|
||||
echo "/usr/local/lib/php/pecl/$api_version"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
extension_dir_linux() {
|
||||
api_version=$1
|
||||
if [[ "${version:?}" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
|
||||
echo "/usr/local/php/$version/lib/php/extensions/no-debug-non-zts-$api_version"
|
||||
else
|
||||
echo "/usr/lib/php/$api_version"
|
||||
fi
|
||||
}
|
||||
|
||||
data() {
|
||||
old_versions="5.[3-5]"
|
||||
nightly_versions="8.[1-9]"
|
||||
date='20210703'
|
||||
if [ "$os" = "Linux" ]; then
|
||||
. /etc/lsb-release
|
||||
os=$os-$DISTRIB_CODENAME
|
||||
api_version=$(get_api_version)
|
||||
dir=$(extension_dir_linux "$api_version")
|
||||
sudo mkdir -p "$dir/deps" && fix_ownership "$dir"
|
||||
elif [ "$os" = "Darwin" ]; then
|
||||
api_version=$(get_api_version)
|
||||
dir=$(extension_dir_darwin "$api_version")
|
||||
sudo mkdir -p "$dir/deps" && fix_ownership "$dir"
|
||||
date='20210707'
|
||||
else
|
||||
os="Windows"
|
||||
dir='C:\\tools\\php\\ext'
|
||||
[[ "$extensions" == *"imagick"* ]] && date='20210512'
|
||||
fi
|
||||
key="$os"-ext-"$version"-$(echo -n "$extensions-$key" | openssl dgst -sha256 | cut -d ' ' -f 2)
|
||||
key="$key-$date"
|
||||
echo "$dir" > "${RUNNER_TEMP:?}"/dir
|
||||
echo "$key" > "${RUNNER_TEMP:?}"/key
|
||||
echo "::set-output name=dir::$dir"
|
||||
echo "::set-output name=key::$key"
|
||||
}
|
||||
|
||||
dependencies() {
|
||||
if [ "$os" = "Linux" ] || [ "$os" = "Darwin" ]; then
|
||||
export tick="✓"
|
||||
export cross="✗"
|
||||
export ext_config_directory="/tmp/extcache"
|
||||
export deps_cache_directory="${RUNNER_TOOL_CACHE}"/deps
|
||||
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)
|
||||
# shellcheck disable=SC1090
|
||||
. "$script_dir/$(echo "$os" | tr '[:upper:]' '[:lower:]').sh"
|
||||
setup_dependencies "$extensions" "$(cat "${RUNNER_TEMP:?}"/dir)"
|
||||
fi
|
||||
}
|
||||
|
||||
run=$1
|
||||
extensions=$2
|
||||
version=$3
|
||||
key=$4
|
||||
os=$(uname -s)
|
||||
|
||||
$run
|
||||
171
src/scripts/darwin.sh
Normal file
171
src/scripts/darwin.sh
Normal file
@@ -0,0 +1,171 @@
|
||||
fetch_brew_tap() {
|
||||
tap=$1
|
||||
tap_user=$(dirname "$tap")
|
||||
tap_name=$(basename "$tap")
|
||||
mkdir -p "$tap_dir/$tap_user"
|
||||
curl -sL "https://github.com/$tap/archive/master.tar.gz" | sudo tar -xzf - -C "$tap_dir/$tap_user"
|
||||
if [ -d "$tap_dir/$tap_user/$tap_name-master" ]; then
|
||||
sudo mv "$tap_dir/$tap_user/$tap_name-master" "$tap_dir/$tap_user/$tap_name"
|
||||
fi
|
||||
}
|
||||
|
||||
add_brew_tap() {
|
||||
tap=$1
|
||||
if ! [ -d "$tap_dir/$tap" ]; then
|
||||
if [ "${ImageOS:=}-${ImageVersion:=}" = "-" ]; then
|
||||
brew tap --shallow "$tap" >/dev/null 2>&1
|
||||
else
|
||||
fetch_brew_tap "$tap" >/dev/null 2>&1
|
||||
if ! [ -d "$tap_dir/$tap" ]; then
|
||||
brew tap --shallow "$tap" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
filter_extensions() {
|
||||
extensions_array=("$@")
|
||||
filtered_extensions=()
|
||||
for ext in "${extensions_array[@]}"; do
|
||||
if grep -i -q -w "$ext" "${script_dir:?}"/../lists/darwin-extensions; then
|
||||
filtered_extensions+=("$ext")
|
||||
fi
|
||||
done
|
||||
echo "${filtered_extensions[@]}"
|
||||
}
|
||||
|
||||
setup_extensions_helper() {
|
||||
dependent_extension=$1
|
||||
dependency_extension=$2
|
||||
extension_dir=$3
|
||||
cached_extension="${deps_cache_directory:?}/$dependency_extension.so"
|
||||
if ! [ -e "$cached_extension" ]; then
|
||||
brew install "$dependency_extension@${version:?}"
|
||||
sudo find "$brew_cellar/$dependency_extension@${version:?}" -name "$dependency_extension.so" -exec cp {} "$cached_extension" \;
|
||||
else
|
||||
echo "Found $dependency_extension extension in cache"
|
||||
sudo cp "$cached_extension" "$extension_dir/"
|
||||
fi
|
||||
add_config "$dependent_extension" "$dependency_extension"
|
||||
}
|
||||
|
||||
setup_extensions() {
|
||||
dependent_extension=$1
|
||||
extension_dir=$2
|
||||
shift 2
|
||||
dependency_extensions_array=("$@")
|
||||
sudo mkdir -p "$cache_directory"/"$extension"
|
||||
echo "::group::Logs to set up extensions required for $extension"
|
||||
for dependency_extension in "${dependency_extensions_array[@]}"; do
|
||||
setup_extensions_helper "$dependent_extension" "$dependency_extension" "$extension_dir"
|
||||
done
|
||||
echo "::endgroup::"
|
||||
add_log "${tick:?}" "${dependency_extensions_array[@]}"
|
||||
}
|
||||
|
||||
add_library_helper() {
|
||||
dep_name=$1
|
||||
cache_dir=$2
|
||||
sudo cp -R "$brew_cellar/$dep_name" "$cache_dir/"
|
||||
sudo chmod -R 777 "$cache_dir/$dep_name"
|
||||
echo "$dep_name" | sudo tee -a "$cache_dir"/list >/dev/null 2>&1
|
||||
(
|
||||
cd "$cache_dir" || exit 1
|
||||
if command -v gtar >/dev/null; then
|
||||
sudo gtar -I "zstd -T0" -cf "$cache_dir"/"$dep_name".tar.zst "$dep_name"
|
||||
else
|
||||
sudo tar -cf - "$dep_name" | zstd -T0 > "$cache_dir"/"$dep_name".tar.zst
|
||||
fi
|
||||
)
|
||||
}
|
||||
|
||||
add_library() {
|
||||
lib=$1
|
||||
cache_dir=$2
|
||||
brew list "$lib" &>/dev/null || brew install "$lib"
|
||||
IFS=' ' read -r -a deps_array <<<"$(brew deps "$lib" | tr '\n' ' ')"
|
||||
to_wait=()
|
||||
for dep_name in "$lib" "${deps_array[@]}"; do
|
||||
add_library_helper "$dep_name" "$cache_dir" &
|
||||
to_wait+=($!)
|
||||
done
|
||||
wait "${to_wait[@]}"
|
||||
sudo rm -R -- "${cache_dir:?}"/*/
|
||||
}
|
||||
|
||||
restore_library_helper() {
|
||||
dep_name=$1
|
||||
cache_dir=$2
|
||||
if command -v gtar >/dev/null; then
|
||||
sudo gtar -I "zstd -d" -xf "$cache_dir"/"$dep_name".tar.zst -C "$brew_cellar"
|
||||
else
|
||||
sudo zstd -dq "$cache_dir"/"$dep_name".tar.zst && sudo tar -xf "$cache_dir"/"$dep_name".tar -C "$brew_cellar"
|
||||
fi
|
||||
if ! [ -d "$brew_prefix/opt/$dep_name" ]; then
|
||||
brew link --force --overwrite "$dep_name" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
restore_library() {
|
||||
cache_dir=$1
|
||||
to_wait=()
|
||||
while read -r dep_name; do
|
||||
restore_library_helper "$dep_name" "$cache_dir" &
|
||||
to_wait+=($!)
|
||||
done <"$cache_dir"/list
|
||||
wait "${to_wait[@]}"
|
||||
}
|
||||
|
||||
setup_libraries() {
|
||||
extension=$1
|
||||
shift 1
|
||||
libraries_array=("$@")
|
||||
ext_deps_dir="$deps_cache_directory/$extension"
|
||||
sudo cp -a "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$extension"/*.rb "$tap_dir"/homebrew/homebrew-core/Formula/
|
||||
sudo mkdir -p "$ext_deps_dir"
|
||||
echo "::group::Logs to set up libraries required for $extension"
|
||||
for lib in "${libraries_array[@]}"; do
|
||||
if ! [ -e "$ext_deps_dir"/list ]; then
|
||||
add_library "$lib" "$ext_deps_dir"
|
||||
else
|
||||
restore_library "$ext_deps_dir"
|
||||
fi
|
||||
done
|
||||
echo "::endgroup::"
|
||||
add_log "$tick" "${libraries_array[@]}"
|
||||
}
|
||||
|
||||
setup_dependencies() {
|
||||
extensions=$1
|
||||
extension_dir=$2
|
||||
cache_directory=/tmp/extcache
|
||||
[[ -z "${extensions// /}" ]] && return
|
||||
IFS=' ' read -r -a extensions_array <<<"$(echo "$extensions" | sed -e "s/pdo[_-]//g" -Ee "s/^|,\s*/ /g")"
|
||||
IFS=' ' read -r -a extensions_array <<<"$(filter_extensions "${extensions_array[@]}")"
|
||||
if [[ -n "${extensions_array[*]// /}" ]]; then
|
||||
add_brew_tap "shivammathur/homebrew-php"
|
||||
add_brew_tap "shivammathur/homebrew-extensions"
|
||||
for extension in "${extensions_array[@]}"; do
|
||||
IFS=' ' read -r -a dependency_array <<<"$(grep "depends_on" "$tap_dir/shivammathur/homebrew-extensions/Formula/$extension@$version.rb" | cut -d '"' -f 2 | tr '\n' ' ')"
|
||||
IFS=' ' read -r -a extension_array <<<"$(echo "${dependency_array[@]}" | grep -Eo "[a-z]*@" | sed 's/@//' | tr '\n' ' ')"
|
||||
IFS=' ' read -r -a libraries_array <<<"${dependency_array[@]//shivammathur*/}"
|
||||
if [[ -n "${libraries_array[*]// /}" ]]; then
|
||||
step_log "Setup libraries for $extension"
|
||||
setup_libraries "$extension" "${libraries_array[@]}"
|
||||
fi
|
||||
if [[ -n "${extension_array[*]// /}" ]]; then
|
||||
step_log "Setup extensions for $extension"
|
||||
setup_extensions "$extension" "$extension_dir" "${extension_array[@]}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
export HOMEBREW_CHANGE_ARCH_TO_ARM=1
|
||||
export HOMEBREW_NO_INSTALL_CLEANUP=1
|
||||
export HOMEBREW_NO_AUTO_UPDATE=1
|
||||
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
|
||||
|
||||
brew_prefix="$(brew --prefix)"
|
||||
brew_cellar="$brew_prefix/Cellar"
|
||||
tap_dir="$(brew --repository)"/Library/Taps
|
||||
107
src/scripts/linux.sh
Normal file
107
src/scripts/linux.sh
Normal file
@@ -0,0 +1,107 @@
|
||||
link_apt_fast() {
|
||||
if ! command -v apt-fast >/dev/null; then
|
||||
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
|
||||
fi
|
||||
}
|
||||
|
||||
fetch_package() {
|
||||
if ! [ -e /tmp/Packages ]; then
|
||||
. /etc/lsb-release
|
||||
deb_build_arch=$(dpkg-architecture -q DEB_BUILD_ARCH)
|
||||
curl -o /tmp/Packages.gz -sL "http://ppa.launchpad.net/ondrej/php/ubuntu/dists/$DISTRIB_CODENAME/main/binary-$deb_build_arch/Packages.gz"
|
||||
gzip -df /tmp/Packages.gz
|
||||
fi
|
||||
}
|
||||
|
||||
get_dependencies() {
|
||||
package=$1
|
||||
prefix=$2
|
||||
sed -e '/Package:\s'"$package$"'/,/^\s*$/!d' /tmp/Packages | grep -Eo "^Depends.*" | tr ',' '\n' | awk -v ORS='' '/^\s'"$prefix"'/{print$0}' | sed -e 's/([^()]*)//g' | sort | uniq | xargs echo -n
|
||||
}
|
||||
|
||||
get_package_link() {
|
||||
package=$1
|
||||
trunk="http://ppa.launchpad.net/ondrej/php/ubuntu"
|
||||
file=$(sed -e '/Package:\s'"$package$"'/,/^\s*$/!d' /tmp/Packages | grep -Eo "^Filename.*" | cut -d' ' -f 2 | tr -d '\r')
|
||||
echo "$trunk/$file"
|
||||
}
|
||||
|
||||
setup_extensions_helper() {
|
||||
dependency_extension=$1
|
||||
extension_dir=$2
|
||||
cached_extension="${deps_cache_directory:?}/$dependency_extension.so"
|
||||
if ! [ -e "$extension_dir/$dependency_extension.so" ]; then
|
||||
if ! [ -e "$cached_extension" ]; then
|
||||
extension_package_link="$(get_package_link "php${version:?}-$dependency_extension")"
|
||||
sudo curl -H "User-Agent: Debian APT-HTTP/GHA(ce)" -o "/tmp/$dependency_extension".deb -sL "$extension_package_link"
|
||||
sudo dpkg-deb -x "/tmp/$dependency_extension".deb /
|
||||
sudo cp "$extension_dir/$dependency_extension.so" "$cached_extension"
|
||||
fix_ownership "$extension_dir"
|
||||
else
|
||||
sudo cp "$cached_extension" "$extension_dir/"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
setup_extensions() {
|
||||
extension_dir=$1
|
||||
IFS=' ' read -r -a dependency_extension_array <<<"$(echo "$2" | xargs -n1 | sort | uniq | xargs)"
|
||||
to_wait=()
|
||||
for dependency_extension in "${dependency_extension_array[@]}"; do
|
||||
setup_extensions_helper "$dependency_extension" "$extension_dir" &
|
||||
to_wait+=($!)
|
||||
done
|
||||
wait "${to_wait[@]}"
|
||||
add_log "${tick:?}" "${dependency_extension_array[@]}"
|
||||
}
|
||||
|
||||
filter_libraries() {
|
||||
libraries="$(echo "$1" | xargs -n1 | sort | uniq | xargs)"
|
||||
for library in $libraries; do
|
||||
if grep -i -q -w "$library" "${script_dir:?}"/../lists/"$DISTRIB_CODENAME"-libs; then
|
||||
libraries=${libraries//$library/}
|
||||
fi
|
||||
done
|
||||
echo "$libraries"
|
||||
}
|
||||
|
||||
setup_libraries() {
|
||||
libraries=$1
|
||||
if [[ -n "${libraries// /}" ]]; then
|
||||
libraries=$(filter_libraries "$libraries")
|
||||
if [[ -n "${libraries// /}" ]]; then
|
||||
step_log "Setup libraries"
|
||||
IFS=' ' read -r -a libraries_array <<<"$libraries"
|
||||
link_apt_fast
|
||||
echo "::group::Logs to set up required libraries"
|
||||
sudo DEBIAN_FRONTEND=noninteractive apt-fast install --no-install-recommends --no-upgrade -y "${libraries_array[@]}"
|
||||
ec="$?"
|
||||
echo "::endgroup::"
|
||||
if [ "$ec" -eq "0" ]; then mark="${tick:?}"; else mark="${cross:?}"; fi
|
||||
add_log "$mark" "${libraries_array[@]}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
setup_dependencies() {
|
||||
extensions=$1
|
||||
extension_dir=$2
|
||||
[[ -z "${extensions// }" ]] && return
|
||||
IFS=' ' read -r -a extensions_array <<<"$(echo "$extensions" | sed -e "s/pdo[_-]//g" -Ee "s/^|,\s*/ php$version-/g")"
|
||||
. /etc/lsb-release
|
||||
sudo rm -rf "${ext_config_directory:?}" || true
|
||||
libraries=""
|
||||
extension_packages=""
|
||||
for extension_package in "${extensions_array[@]}"; do
|
||||
fetch_package
|
||||
libraries="$libraries $(get_dependencies "$extension_package" "lib")"
|
||||
extension_packages="$extension_packages $(get_dependencies "$extension_package" "php$version-")"
|
||||
extension_packages="${extension_packages//php$version-common/}"
|
||||
done
|
||||
if [[ -n "${libraries// /}" ]]; then
|
||||
setup_libraries "$libraries"
|
||||
fi
|
||||
if [[ -n "${extension_packages// /}" ]]; then
|
||||
setup_extensions "$extension_dir" "${extension_packages//php$version-/}"
|
||||
fi
|
||||
}
|
||||
39
src/utils.ts
39
src/utils.ts
@@ -1,4 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,16 @@ export async function getInput(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get outputs
|
||||
*/
|
||||
export async function getOutput(output: string): Promise<string> {
|
||||
return fs.readFileSync(
|
||||
path.join(await readEnv('RUNNER_TEMP'), output),
|
||||
'utf8'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to parse PHP version.
|
||||
*
|
||||
@@ -65,10 +76,26 @@ export async function parseVersion(version: string): Promise<string> {
|
||||
* @param extension_csv
|
||||
*/
|
||||
export async function filterExtensions(extension_csv: string): Promise<string> {
|
||||
return extension_csv
|
||||
.split(',')
|
||||
.filter(extension => {
|
||||
return extension.trim()[0] != ':';
|
||||
})
|
||||
.join(',');
|
||||
return JSON.stringify(
|
||||
extension_csv
|
||||
.split(',')
|
||||
.filter(extension => {
|
||||
return extension.trim()[0] != ':';
|
||||
})
|
||||
.join(',')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get script call
|
||||
*
|
||||
* @param fn
|
||||
* @param args
|
||||
*/
|
||||
export async function scriptCall(
|
||||
fn: string,
|
||||
...args: string[]
|
||||
): Promise<string> {
|
||||
const script: string = path.join(__dirname, '../src/scripts/cache.sh');
|
||||
return ['bash', script, fn, ...args].join(' ');
|
||||
}
|
||||
|
||||
@@ -1,63 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
"ESNext"
|
||||
],
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "./lib",
|
||||
"removeComments": true,
|
||||
"rootDir": "./src",
|
||||
"sourceMap": true,
|
||||
"strict": true,
|
||||
"target": "ESNext"
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": ["__tests__", "lib", "node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user