From 3781acab4b5046d679b64883491c3f0df21a7c72 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Thu, 20 Feb 2020 04:15:24 +0530 Subject: [PATCH 1/4] Fix link in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aad4b8ff..a24e1d2d 100644 --- a/README.md +++ b/README.md @@ -472,7 +472,7 @@ Examples for setting up this GitHub Action with different PHP Frameworks/Package ## :scroll: License -The scripts and documentation in this project are released under the [MIT License](LICENSE "License for shivammathur/setup-php"). This project has multiple [dependencies](#dependencies "Dependencies for this PHP Action"). Their licenses can be found in their respective repositories. +The scripts and documentation in this project are released under the [MIT License](LICENSE "License for shivammathur/setup-php"). This project has multiple [dependencies](#bookmark-dependencies "Dependencies for this PHP Action"). Their licenses can be found in their respective repositories. ## :+1: Contributions From 9dfebd1adb6213f043e31c4d54d284f2de3461f6 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 21 Feb 2020 07:58:19 +0530 Subject: [PATCH 2/4] Refactor scripts --- src/scripts/darwin.sh | 27 ++++++++++++++++----------- src/scripts/linux.sh | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index ca5a2ca8..674b07d3 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -180,6 +180,15 @@ port_setup_php() { add_pecl_old "$1" } +setup_php() { + action=$1 + step_log "Setup PHP" + export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1 + brew tap shivammathur/homebrew-php >/dev/null 2>&1 + brew "$action" shivammathur/php/php@"$version" >/dev/null 2>&1 + brew link --force --overwrite php@"$version" >/dev/null 2>&1 +} + # Variables tick="✓" cross="✗" @@ -190,7 +199,6 @@ existing_version=$(php-config --version | cut -c 1-3) [[ -z "${update}" ]] && update='false' || update="${update}" # Setup PHP -step_log "Setup PHP" if [[ "$version" =~ $old_versions ]]; then export PATH="/opt/local/bin:/opt/local/sbin:$PATH" export TERM=xterm @@ -202,17 +210,14 @@ if [[ "$version" =~ $old_versions ]]; then step_log "Setup PHP" port_setup_php $nodot_version >/dev/null 2>&1 status="Installed" -elif [ "$existing_version" != "$version" ] || [ "$update" = "true" ]; then - export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1 - brew tap shivammathur/homebrew-php >/dev/null 2>&1 - brew install shivammathur/php/php@"$version" >/dev/null 2>&1 - brew link --force --overwrite php@"$version" >/dev/null 2>&1 - if [ "$update" = "true" ]; then - status="Updated to" - else - status="Installed" - fi +elif [ "$existing_version" != "$version" ]; then + setup_php "install" + status="Installed" +elif [ "$existing_version" = "$version" ] && [ "$update" = "true" ]; then + setup_php "upgrade" + status="Updated to" else + step_log "Setup PHP" status="Found" fi ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index f19ebf38..1e043a67 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -25,6 +25,7 @@ update_ppa() { ppa="ondrej-ubuntu-php*.list" fi find /etc/apt/sources.list.d -type f -name "$ppa" -exec sudo "$debconf_fix" apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 + ppa_updated="true" fi } @@ -59,7 +60,7 @@ add_extension() { install_command=$2 prefix=$3 if [[ "$version" =~ $old_versions ]]; then - install_command="update_ppa && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version} && ppa_updated='true'" + install_command="update_ppa && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}" fi if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then # shellcheck disable=SC2046 @@ -69,7 +70,7 @@ add_extension() { add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then (eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || - (update_ppa && eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled" && ppa_updated="true") || + (update_ppa && eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || (sudo pecl install -f "$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" fi @@ -140,7 +141,6 @@ update_extension() { version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version") if [ -z "$version_exists" ]; then update_ppa - ppa_updated="true" fi $apt_install php"$version"-"$extension" fi @@ -242,6 +242,28 @@ switch_version() { done } +# Function to get PHP version in semver format +php_semver() { + if [ ! "$version" = "8.0" ]; then + php"$version" -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-' + else + php -v | head -n 1 | cut -f 2 -d ' ' + fi +} + +# Function to update PHP +update_php() { + update_ppa + initial_version=$(php_semver) + $apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1 + updated_version=$(php_semver) + if [ "$updated_version" != "$initial_version" ]; then + status="Updated to" + else + status="Switched to" + fi +} + # Variables tick="✓" cross="✗" @@ -268,15 +290,13 @@ if [ "$existing_version" != "$version" ]; then version_exists=$(apt-cache policy -- php"$version" | grep "$version") if [ -z "$version_exists" ]; then update_ppa - ppa_updated="true" fi $apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1 fi status="Installed" else if [ "$update" = "true" ]; then - $apt_install php"$version" >/dev/null 2>&1 - status="Updated to" + update_php else status="Switched to" fi @@ -289,18 +309,13 @@ if [ "$existing_version" != "$version" ]; then else if [ "$update" = "true" ]; then - $apt_install php"$version" >/dev/null 2>&1 - status="Updated to" + update_php else status="Found" fi fi -semver=$(php -v | head -n 1 | cut -f 2 -d ' ') -if [ ! "$version" = "8.0" ]; then - semver=$(echo "$semver" | cut -f 1 -d '-') -fi - +semver=$(php_semver) ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") From 0f694c50875aa89175a9e188ca8b049b3a546034 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 21 Feb 2020 13:39:04 +0530 Subject: [PATCH 3/4] Update README --- README.md | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a24e1d2d..d39fc121 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support - [Verbose Setup](#verbose-setup) - [Cache Extensions](#cache-extensions) - [Cache Composer Dependencies](#cache-composer-dependencies) + - [Cache Node.js Dependencies](#cache-nodejs-dependencies) - [Problem Matchers](#problem-matchers) - [Examples](#examples) - [License](#scroll-license) @@ -338,7 +339,7 @@ jobs: ### Cache Extensions -You can persist PHP extensions you setup using the [`shivammathur/cache-extensions`](https://github.com/shivammathur/cache-extensions "GitHub Action to cache php extensions") and [`action/cache`](https://github.com/actions/cache "GitHub Action to cache files") GitHub Actions. Extensions which take very long to setup if cached are available in the next workflow run and enabled directly which reduces the workflow execution time. +You can cache PHP extensions using [`shivammathur/cache-extensions`](https://github.com/shivammathur/cache-extensions "GitHub Action to cache php extensions") and [`action/cache`](https://github.com/actions/cache "GitHub Action to cache files") GitHub Actions. Extensions which take very long to setup if cached are available in the next workflow run and enabled directly which reduces the workflow execution time. ```yaml runs-on: ${{ matrix.operating-system }} @@ -378,12 +379,12 @@ steps: ### Cache Composer Dependencies -You can persist composer's internal cache directory using the [`action/cache`](https://github.com/actions/cache "GitHub Action to cache files") GitHub Action. Dependencies cached are loaded directly instead of downloading them while installation. The files cached are available across check-runs and will reduce the workflow execution time. +If your project uses composer, you can persist composer's internal cache directory. Dependencies cached are loaded directly instead of downloading them while installation. The files cached are available across check-runs and will reduce the workflow execution time. **Note:** Please do not cache `vendor` directory using `action/cache` as that will have side-effects. ```yaml -- name: Get Composer Cache Directory +- name: Get composer cache directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -394,15 +395,34 @@ You can persist composer's internal cache directory using the [`action/cache`](h key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- -- name: Install Dependencies +- name: Install dependencies run: composer install --prefer-dist ``` In the above example, if you support a range of `composer` dependencies and do not commit `composer.lock`, you can use the hash of `composer.json` as the key for your cache. ```yaml -key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} -``` +key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} +``` + +### Cache Node.js Dependencies + +If you project has node.js dependencies, you can persist npm's or yarn's internal cache directory. Dependencies cached install faster. The files cached are available across check-runs and will reduce the workflow execution time. + +**Note:** Please do not cache `node_modules` directory as that will have side-effects. + +```yaml +- name: Get node.js cache directory + id: node-cache-dir + run: echo "::set-output name=dir::$(npm config get cache)" # Use $(yarn cache dir) for yarn + +- name: Cache dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.node-cache-dir.outputs.dir }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} # Use '**/yarn.lock' for yarn + restore-keys: ${{ runner.os }}-node- +``` ### Problem Matchers @@ -411,7 +431,7 @@ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} Setup problem matchers for your `PHP` output by adding this step after the `setup-php` step. This will scan the logs for PHP errors and warnings, and surface them prominently in the GitHub Actions UI by creating annotations and log file decorations. ```yaml -- name: Setup Problem Matchers for PHP +- name: Setup problem matchers for PHP run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" ``` @@ -420,7 +440,7 @@ Setup problem matchers for your `PHP` output by adding this step after the `setu Setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step. This will scan the logs for failing tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations. ```yaml -- name: Setup Problem Matchers for PHPUnit +- name: Setup problem matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" ``` @@ -483,8 +503,8 @@ Contributions are welcome! See [Contributor's Guide](.github/CONTRIBUTING.md "sh If this action helped you. - Please star the project and share it with the community. -- If you blog, write about your experience while using this action. -- I maintain this in my free time, please support me with a [Patreon](https://www.patreon.com/shivammathur "Shivam Mathur Patreon") subscription or a one time contribution using [Paypal](https://www.paypal.me/shivammathur "Shivam Mathur PayPal"). +- If you blog, write about your experience of using this action. +- Please support me with a [Patreon](https://www.patreon.com/shivammathur "Shivam Mathur Patreon") subscription or a contribution using [Paypal](https://www.paypal.me/shivammathur "Shivam Mathur PayPal") so that I'm able to actively maintain this project. - If you need any help using this, please contact me using [Codementor](https://www.codementor.io/shivammathur "Shivam Mathur Codementor") ## :bookmark: Dependencies From 10f86cb1a16a7c25d27ce37023ebf2dd60ce2214 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 21 Feb 2020 12:14:19 +0530 Subject: [PATCH 4/4] Bump version to 2.0.2 --- package-lock.json | 73 +++++++++++++++++++---------------------------- package.json | 10 +++---- 2 files changed, 34 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9069638f..c8810761 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "setup-php", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -575,18 +575,18 @@ } }, "@sinonjs/commons": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.0.tgz", - "integrity": "sha512-qbk9AP+cZUsKdW1GJsBpxPKFmCJ0T8swwzVje3qFd+AkQb74Q/tiuzrdfFg8AD2g5HH/XbE/I8Uc1KYHVYWfhg==", + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.7.1.tgz", + "integrity": "sha512-Debi3Baff1Qu1Unc3mjJ96MgpbwTn43S1+9yJ0llWygPwDNu2aaWBD6yc9y/Z8XDRNhx7U+u2UDg2OGQXkclUQ==", "dev": true, "requires": { "type-detect": "4.0.8" } }, "@types/babel__core": { - "version": "7.1.4", - "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.4.tgz", - "integrity": "sha512-c/5MuRz5HM4aizqL5ViYfW4iEnmfPcfbH4Xa6GgLT21dMc1NGeNnuS6egHheOmP+kCJ9CAzC4pv4SDCWTnRkbg==", + "version": "7.1.5", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.5.tgz", + "integrity": "sha512-+ckxwNj892FWgvwrUWLOghQ2JDgOgeqTPwrcl+0t1pG59CP8qMJ6S/efmEd999vCFSJKOpyMakvU+w380rduUQ==", "dev": true, "requires": { "@babel/parser": "^7.1.0", @@ -616,9 +616,9 @@ } }, "@types/babel__traverse": { - "version": "7.0.8", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.8.tgz", - "integrity": "sha512-yGeB2dHEdvxjP0y4UbRtQaSkXJ9649fYCmIdRoul5kfAoGCwxuCbMhag0k3RPfnuh9kPGm8x89btcfDEXdVWGw==", + "version": "7.0.9", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.0.9.tgz", + "integrity": "sha512-jEFQ8L1tuvPjOI8lnpaf73oCJe+aoxL6ygqSy6c8LcW98zaC+4mzWuQIRCEvKeCOu+lbqdXcg4Uqmm1S8AP1tw==", "dev": true, "requires": { "@babel/types": "^7.3.0" @@ -662,9 +662,9 @@ } }, "@types/jest": { - "version": "25.1.2", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-25.1.2.tgz", - "integrity": "sha512-EsPIgEsonlXmYV7GzUqcvORsSS9Gqxw/OvkGwHfAdpjduNRxMlhsav0O5Kb0zijc/eXSO/uW6SJt9nwull8AUQ==", + "version": "25.1.3", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-25.1.3.tgz", + "integrity": "sha512-jqargqzyJWgWAJCXX96LBGR/Ei7wQcZBvRv0PLEu9ZByMfcs23keUJrKv9FMR6YZf9YCbfqDqgmY+JUBsnqhrg==", "dev": true, "requires": { "jest-diff": "^25.1.0", @@ -678,9 +678,9 @@ "dev": true }, "@types/node": { - "version": "13.7.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.2.tgz", - "integrity": "sha512-uvilvAQbdJvnSBFcKJ2td4016urcGvsiR+N4dHGU87ml8O2Vl6l+ErOi9w0kXSPiwJ1AYlIW+0pDXDWWMOiWbw==", + "version": "13.7.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.4.tgz", + "integrity": "sha512-oVeL12C6gQS/GAExndigSaLxTrKpQPxewx9bOcwfvJiJge4rr7wNaph4J+ns5hrmIV2as5qxqN8YKthn9qh0jw==", "dev": true }, "@types/parse-json": { @@ -3827,9 +3827,9 @@ } }, "make-error": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", - "integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==", + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, "makeerror": { @@ -5517,9 +5517,9 @@ } }, "ts-jest": { - "version": "25.2.0", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.2.0.tgz", - "integrity": "sha512-VaRdb0da46eorLfuHEFf0G3d+jeREcV+Wb/SvW71S4y9Oe8SHWU+m1WY/3RaMknrBsnvmVH0/rRjT8dkgeffNQ==", + "version": "25.2.1", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.2.1.tgz", + "integrity": "sha512-TnntkEEjuXq/Gxpw7xToarmHbAafgCaAzOpnajnFC6jI7oo1trMzAHA04eWpc3MhV6+yvhE8uUBAmN+teRJh0A==", "dev": true, "requires": { "bs-logger": "0.x", @@ -5531,36 +5531,21 @@ "mkdirp": "0.x", "resolve": "1.x", "semver": "^5.5", - "yargs-parser": "10.x" + "yargs-parser": "^16.1.0" }, "dependencies": { - "camelcase": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", - "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", - "dev": true - }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true - }, - "yargs-parser": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz", - "integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==", - "dev": true, - "requires": { - "camelcase": "^4.1.0" - } } } }, "tslib": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", - "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.0.tgz", + "integrity": "sha512-BmndXUtiTn/VDDrJzQE7Mm22Ix3PxgLltW9bSNLoeCY31gnG2OPx0QqJnuc9oMIKioYrz487i6K9o4Pdn0j+Kg==", "dev": true }, "tsutils": { @@ -5618,9 +5603,9 @@ } }, "typescript": { - "version": "3.7.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", - "integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==", + "version": "3.8.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.2.tgz", + "integrity": "sha512-EgOVgL/4xfVrCMbhYKUQTdF37SQn4Iw73H5BgCrF1Abdun7Kwy/QZsE/ssAy0y4LxBbvua3PIbFsbRczWWnDdQ==", "dev": true }, "union-value": { diff --git a/package.json b/package.json index 72b993d2..ef3a5705 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-php", - "version": "2.0.1", + "version": "2.0.2", "private": false, "description": "Setup PHP for use with GitHub Actions", "main": "dist/index.js", @@ -30,8 +30,8 @@ "fs": "0.0.1-security" }, "devDependencies": { - "@types/jest": "^25.1.2", - "@types/node": "^13.7.2", + "@types/jest": "^25.1.3", + "@types/node": "^13.7.4", "@typescript-eslint/eslint-plugin": "^2.20.0", "@typescript-eslint/parser": "^2.20.0", "@zeit/ncc": "^0.21.1", @@ -44,8 +44,8 @@ "jest": "^25.1.0", "jest-circus": "^25.1.0", "prettier": "^1.19.1", - "ts-jest": "^25.2.0", - "typescript": "^3.7.5" + "ts-jest": "^25.2.1", + "typescript": "^3.8.2" }, "husky": { "skipCI": true,