Compare commits

..

188 Commits
2.13.0 ... v1

Author SHA1 Message Date
28c92ba4ee Bump version to 1.11.7
Update Node.js dependencies
2022-04-09 20:24:57 +05:30
ffd019edc6 Refactor updating dependencies on macOS 2022-04-09 20:24:56 +05:30
0e506b34ac Fix composer setup for Composer 2.3 changes 2022-04-09 20:18:31 +05:30
aa0ecfbc6f Add support for mcrypt using shivammathur/extensions tap on macOS 2022-04-09 19:53:51 +05:30
f29cd24dbf Update README 2022-04-09 19:53:36 +05:30
2a41b9d1ba Fix patching brew 2022-04-09 19:48:47 +05:30
2a0c477416 Update Node.js dependencies 2022-02-08 18:10:43 +05:30
61aa0dc2f9 Fix manifest URL for v1 2022-02-07 13:10:17 +05:30
f4e1b8d33e Bump version to 1.11.6 2022-02-02 14:19:38 +05:30
e3a498a6a5 Add CodeQL workflow
Update README

Update Node.js workflow

Fix tests
2022-02-02 14:16:09 +05:30
fbdd58c5bc Bump version to 1.11.5
Replace husky with simple-git-hooks

Update Node.js dependencies
2021-09-28 01:51:40 +05:30
2c5cb7a75e Make all extension variables local 2021-09-28 01:42:44 +05:30
ab12e42197 Add support for expect and ssh2 using shivammathur/extensions on macOS
Add config to brew extensions and refactor add_brew_extension in darwin.sh to use it
2021-09-28 01:38:12 +05:30
5588437714 Update sponsors section 2021-09-28 01:28:53 +05:30
d7eb9ade23 Update SECURITY.md 2021-09-11 04:42:32 +05:30
938988b211 Bump version to 1.11.4
Update Node.js dependencies

Fix build error in install.ts

Add config to generate types

Add bugs, directories, files and types entries in package.json
2021-09-11 04:41:35 +05:30
e030852d0e Use PhpManager for all PHP versions on v1 2021-09-09 02:53:01 +05:30
3aa870b0fe Fix unsupported PHP versions warning on v1 2021-09-09 02:49:04 +05:30
1229133602 Use shivammathur/extensions tap to install vips on macOS 2021-09-09 02:40:49 +05:30
b1b8d8367c Run New-Item with -Force in Win32.ps1 2021-09-09 02:34:37 +05:30
60ff55130a Update sponsors info 2021-09-09 02:30:03 +05:30
e5690a9659 Add windows-2022 to the README 2021-09-09 02:27:14 +05:30
7958a5ccff Bump version 1.11.3
Sync tsconfig.json with v2

Update dependencies
2021-08-23 12:54:39 +05:30
113a31fceb Stop doing shallow clones on macOS self-hosted 2021-08-23 12:49:33 +05:30
c9aea8708f Set HOMEBREW_DEVELOPER=1 in macOS 2021-08-23 12:48:34 +05:30
7435bb8e4a Use --no-install-recommends with APT on Linux 2021-08-23 12:47:56 +05:30
5227e2cd5c Fix to make utils.readEnv more resilient to user input 2021-08-23 12:42:17 +05:30
906893d397 Use shivammathur/extensions tap on macOS for mongodb and yaml 2021-08-23 12:41:33 +05:30
f1b6b2bbe0 Rename macos-11.0 to macos-11 2021-08-23 12:39:55 +05:30
e59c938e82 Update Phive configuration 2021-08-23 12:38:05 +05:30
506357cdb9 Sunset support for Ubuntu 16.04 2021-08-02 22:55:00 +05:30
b57416e44d Fix composer permissions on unix 2021-07-21 18:58:36 +05:30
9d1fe69816 Revert PCRE2 Patch 2021-07-16 15:52:34 +05:30
fec64d1788 Bump version to 1.11.2
Update Node.js dependencies

Fix replacing v prefix in tool version

Use shivammathur/extensions tap for rdkafka on macOS

Update Ubuntu 16.04 warning in install.ts

Add patch for PCRE2
2021-07-13 15:13:18 +05:30
32c1436247 Update dependencies
Update to Jest 27

Set sourceMap to true in tsconfig.json
2021-05-31 04:07:20 +05:30
baab28a534 Fix extension setup 2021-05-31 04:07:07 +05:30
d58b967b58 Force overwrite updated dependencies on macOS 2021-05-27 21:00:30 +05:30
17f3c38947 Deprecate Ubuntu 16.04 2021-05-04 23:53:49 +05:30
988f48930d Switch to setup-php.com short URLs in install.ts 2021-05-04 22:11:06 +05:30
ea50e73b1f Fix to not use system PHP on macOS 2021-05-04 21:32:36 +05:30
bc906f7414 Use mirror for ppa:ondrej/php on Ubuntu 16.04 2021-05-01 16:34:21 +05:30
8bed24ebe1 Add ppa:ondrej/php for all Ubuntu versions 2021-05-01 16:31:03 +05:30
698464efea Fix phalcon3 on windows 2021-04-21 07:38:39 +05:30
45082e25a9 Bump version to 1.11.1
Update Node.js dependencies

Cleanup tsconfig.json

Set moduleResolution to node
2021-04-19 07:11:40 +05:30
f0338c8922 Update SECURITY.md 2021-04-19 07:11:39 +05:30
49311db00a Update Node version to 15.x 2021-04-19 07:11:38 +05:30
7d9584bd3f Add fallback to Install-PSPackage in win32.ps1 2021-04-19 07:11:38 +05:30
45df3b1713 Use lcov.info for coverage 2021-04-19 07:11:37 +05:30
70cd53866f Fix gearman setup 2021-04-19 07:11:32 +05:30
12d6e834b7 Add parameters to ppa/lists functions in linux.sh 2021-04-19 00:58:27 +05:30
9fdc82bced Use shivammathur/extensions for phalcon and psr 2021-04-19 00:54:25 +05:30
c485e8b283 Fix warning in install.ts 2021-04-19 00:48:26 +05:30
7a90166ec2 Cleanup cleanup_lists in linux.sh 2021-04-19 00:46:18 +05:30
8f96f50dcd Make sure global composer.json directory exists 2021-04-19 00:38:14 +05:30
c470f034d0 Fix warning in darwin.sh when linking old libs 2021-04-19 00:36:09 +05:30
e2ad91ce1c Remove pcov patch 2021-04-19 00:32:13 +05:30
cb746892c2 Use packages from shivammathur/php-ubuntu 2021-03-11 03:44:33 +05:30
8f542eae1a Fix linking old_libraries in macOS 2021-03-08 19:46:30 +05:30
0769672a24 Link libs of updated PHP dependencies on macOS 2021-02-28 19:08:35 +05:30
c20693a6ca Bump version to 1.11.0
Update dependencies

Update prettier plugin in .eslintrc.json
2021-02-22 15:37:37 +05:30
0c0ae39775 Assorted fixes 2021-02-22 15:37:36 +05:30
d27996462b Set up codeception using composer
Add fixes for global composer tools
2021-02-22 12:01:59 +05:30
0a5e543af7 Improve regexes in extensions.ts 2021-02-22 11:49:32 +05:30
0cc14f65a2 Do not quote ini values with error constants 2021-02-22 11:48:35 +05:30
1ecc5fdca3 Fix composer config syntax 2021-02-22 11:48:34 +05:30
5520fdb61a Add support to specify version in \d.x notation 2021-02-22 11:48:28 +05:30
d0f1a91dfd Add support for quoted csv in ini-values 2021-02-22 11:04:31 +05:30
276480411d Change Node.js version in the workflow 2021-02-22 11:02:09 +05:30
827b051fea Sync brew params from v2
Add check for image constants
2021-02-22 10:58:46 +05:30
fdaf1f0003 Sync symfony examples from v2 2021-02-22 10:55:37 +05:30
030f4839d4 Update Pre-installed PHP in README 2021-02-22 10:55:36 +05:30
1bb08cc017 Improve pecl support 2021-02-22 10:55:35 +05:30
678ad243bf Exit on failing to setup PHP 2021-02-22 10:55:29 +05:30
20b87bc786 Fetch homebrew taps manually 2021-02-22 10:33:58 +05:30
288f9953ef Add sponsor logos 2021-02-22 10:30:18 +05:30
77ac7d57f1 Improve support for phive 2021-02-22 10:09:52 +05:30
8983fb3ae2 Remove bintray from win32.ps1 2021-02-22 09:59:07 +05:30
87a933f720 Improve extension support
Add support for xdebug2 coverage
2021-02-22 09:19:08 +05:30
847ea65468 Fix php 8 on macos 2020-11-28 15:05:48 +05:30
c52ce057af Bump version to 1.10.1 2020-11-26 23:55:29 +05:30
46b357b6c2 Setup Xdebug 2.9.8 on PHP 7.2 2020-11-26 23:50:49 +05:30
2fc508f43d Fix shellcheck warning in add_tool 2020-11-26 11:30:29 +05:30
d8de30560b Fix fetching extension version from PECL on macOS 2020-11-26 11:06:55 +05:30
02db83ef5f Fix deleting extensions 2020-11-26 11:05:02 +05:30
6728eaf2ad Change description in actions.yml 2020-11-26 11:02:13 +05:30
ca291eadaf Sync dependencies from tap in add_brew_extension 2020-11-26 11:00:53 +05:30
8185c8186b Fix tool setup on windows 2020-11-26 07:32:04 +05:30
44cf056ba8 Bump version to 1.10.0 2020-11-16 03:26:49 +05:30
9bfde13f48 Update README 2020-11-16 03:26:46 +05:30
e38eccad04 Fetch release with tool when latest one does not 2020-11-16 03:01:31 +05:30
fa211a9d07 Improve regexes for pre-release extensions 2020-11-16 02:55:14 +05:30
5865982519 Fix contribution docs 2020-11-16 02:46:39 +05:30
e201830bdd Refactor composer setup 2020-11-16 02:43:59 +05:30
5c4074b01a Adjust filtered composer version 2020-11-16 02:40:00 +05:30
48f537d6d0 Allow installing a specific Composer version 2020-11-16 02:37:19 +05:30
bc40a61480 Install VcRedist from GitHub 2020-11-16 02:32:09 +05:30
3d5fae7917 Use PECL directly for nightly versions 2020-11-16 02:23:20 +05:30
d0591e6d7c Fix composer version for prestissimo & composer-prefetcher to v1 2020-11-16 02:20:15 +05:30
b108a66489 Fix version change if composer is a dependency 2020-11-16 02:09:15 +05:30
f0a05b4f6e Revert "Switch to apt-get"
This reverts commit 1d1c0f2595.
2020-11-16 01:56:09 +05:30
5070ebd871 Revert "Remove dashes from step ids"
This reverts commit b9ef39c812.
2020-11-16 01:55:15 +05:30
bea4065e11 Update dependencies as per runner on macOS 2020-10-23 07:17:55 +05:30
c3875408ad Bump version to 1.9.8 2020-10-19 15:14:40 +05:30
1d1c0f2595 Switch to apt-get 2020-10-19 15:14:39 +05:30
1ac189066e Add warnings to v1 2020-10-19 15:14:32 +05:30
74cdfb97c1 Add support for imagick and igbinary on macOS using shivammathur/homebrew-extensions 2020-10-19 15:05:09 +05:30
ee05ca54f6 Fix matchers setup when action is called twice 2020-10-19 14:58:36 +05:30
12b1061a6b Perform only one URL call to download latest PhpManager.zip asset 2020-10-19 14:58:24 +05:30
1c6058bc18 Update Node.js dependencies 2020-10-15 14:26:38 +05:30
2f8045c593 Minor fixes in scripts 2020-10-15 14:26:37 +05:30
6597a6a15b Fix dependency mess in phalcon4 setup on ubuntu 2020-10-15 14:26:36 +05:30
1cc85eb670 Bump version to 1.9.7 2020-10-15 14:26:36 +05:30
6cba0a914f Move matchers setup to scripts 2020-10-15 14:26:35 +05:30
c43f842cf3 Prioritize with over env for inputs 2020-10-15 14:26:34 +05:30
11e062bf23 Switch to environment files. Apply GHSA-mfwh-5m23-j46w (CVE-2020-15228) 2020-10-15 14:26:34 +05:30
dee3cfee50 Improve problem matchers section in README 2020-10-15 14:26:33 +05:30
26b0fcc6cd Bump version to 1.9.6 2020-10-15 14:26:32 +05:30
ab62fff526 Make sure printf is in PATH in Windows 2020-10-15 14:26:32 +05:30
446bccb14d Download release assets for PowerShell PhpManager
Downloading such assets is preferable since:
- they contain updated metadata (useful for debugging)
- they contain only the production files
- they are pre-built: GitHub doesn't have to create a ZIP from a tag
2020-09-07 02:31:33 +05:30
29d99c6866 Use releases instead of tags to download PowerShell PhpManager
I just started to publish PhpManager to GitHub Releases too
2020-09-07 02:20:16 +05:30
1444e002ab Replace fedora with valid platform name 2020-09-07 02:16:49 +05:30
03b97e24e9 Remove unnecessary parameter version from addArchive 2020-09-07 02:14:46 +05:30
f7fb800623 Bump version to 1.9.5
Switch to fixed getcomposer.org links

Add composer fallback
2020-08-16 07:26:49 +05:30
5593bd4bd3 Remove old PHPUnit on linux 2020-08-16 02:51:32 +05:30
3160874a27 Bump version to 1.9.4 2020-08-10 16:43:54 +05:30
db0bbd209b Change cURL opts 2020-08-10 16:43:54 +05:30
d920044a54 Limit swoole support to PHP 7.4 2020-08-10 16:43:53 +05:30
818ca89f55 Accept PECL default parameters 2020-08-10 16:43:47 +05:30
8876ac788f Use shivammathur/php-builder-windows for PHP 8 on Windows 2020-08-03 14:18:17 +05:30
0390a48770 Remove obsolete pcov.sh 2020-08-03 14:09:32 +05:30
274e348895 Use default packagist mirror for old PHP 2020-08-03 14:06:14 +05:30
37d7b37f43 Remove update_extension from linux.sh 2020-08-03 14:05:42 +05:30
d058d52012 Bump supported version in SECURITY.md 2020-08-03 14:00:18 +05:30
17983e66e5 Bump version to 1.9.3 2020-07-20 20:58:08 +05:30
33a005dd90 Fix logs 2020-07-20 20:58:07 +05:30
1870ffc08c Fix Typo 2020-07-20 17:32:29 +05:30
70fd71ab48 Set memory_limit=-1 on Windows and macOS 2020-07-20 17:28:41 +05:30
2f1900f7bc Fix support for pre-release extensions 2020-07-20 17:25:25 +05:30
19497a0597 Improve updating lists 2020-07-20 17:20:16 +05:30
5b2e081bc0 Install only cli on linux 2020-07-20 17:10:20 +05:30
66fa82fbca Fix coverage 2020-07-20 17:10:19 +05:30
4aa42214b1 Update extensions.test.ts 2020-07-20 17:10:18 +05:30
1e2c96a4b4 Fixed xdebug version for PHP 5.6 and 7.0 2020-07-20 17:10:17 +05:30
3e8d887b0d Set ini values after coverage setup 2020-07-20 17:10:16 +05:30
a3d5500a6a Improve composer setup 2020-07-20 17:10:09 +05:30
e763fddf01 Remove update_formulae in darwin.sh 2020-07-07 00:47:45 +05:30
3cd5c7fd3a Bump version to 1.9.2 2020-07-03 17:46:15 +05:30
988cef62da Add ondrej's PPA on focal 2020-07-03 15:18:11 +05:30
be3ee05178 Use shivammathur/extensions tap for grpc, swoole, protobuf on macos 2020-07-03 15:06:42 +05:30
a74c3369c5 Bump version to 1.9.1 2020-06-20 01:02:16 +05:30
b9ef39c812 Remove dashes from step ids 2020-06-20 01:02:16 +05:30
782615d572 Remove --no-suggest flag in examples 2020-06-20 01:02:15 +05:30
31411b0d4d Improve extension support 2020-06-20 01:02:10 +05:30
6b93e48d83 Fix Xdebug coverage 2020-06-19 17:36:28 +05:30
fe504c5e23 Bump version to 1.9.0 2020-06-09 07:17:38 +05:30
61d755bd59 Fix updating powershell profile 2020-06-08 03:02:40 +05:30
3455b4ca37 Add support for updating composer 2020-06-08 02:15:24 +05:30
35c24a7d2f Refactor linux.sh and fetch nightly script 2020-06-08 02:00:47 +05:30
da7361cc8f Use Invoke-RestMethod to get tag 2020-06-08 01:36:03 +05:30
3f4c1842a0 Remove empty line in logs 2020-06-08 01:34:16 +05:30
062567eeb1 Setup libwebp-dev with PHP8 on linux 2020-05-18 22:34:49 +05:30
00b0d694d0 Update PPA before phalcon setup 2020-05-18 18:03:51 +05:30
54afb29ef6 Update PPA in add_devtools in linux.sh 2020-05-18 17:43:52 +05:30
41329810ef Bump version to 1.8.8 2020-05-17 03:25:48 +05:30
90a6d88c24 Update README.md 2020-05-17 03:25:42 +05:30
8e6968c49e Fix support for phalcon and gearman 2020-05-15 23:34:59 +05:30
4ce413f558 Improve composer support 2020-05-15 23:34:58 +05:30
533e0949a8 cleanup darwin.sh 2020-05-15 23:34:57 +05:30
0ffe535b8e Refactor win32.ps1 2020-05-15 23:34:56 +05:30
55fe8db60d Refactor linux.sh 2020-05-15 23:34:51 +05:30
5af5f992ec Suppress php-config error 2020-05-13 20:36:57 +05:30
e9e024e600 Fix loading PECL extensions 2020-05-05 14:57:36 +05:30
a7ea0636d7 Fix icu4c version for PHP 5.6 and PHP 7.0 on darwin 2020-04-30 16:59:19 +05:30
c471c0a458 Fix libzip-dev error in PHP 8.0 on ubuntu 2020-04-30 07:36:55 +05:30
277239149a Fetch formulae before setup 2020-04-23 16:16:33 +05:30
9385896f2a Bump version to 1.8.7 2020-04-09 21:35:02 +05:30
9cabd8564d Recompile PCOV for PHP8 2020-04-09 21:26:32 +05:30
fdfa901941 Update all lists 2020-03-20 19:04:24 +05:30
527cd148c8 Bump version to 1.8.6 2020-03-18 16:15:06 +05:30
59b6e2b54a Install PhpManager from GitHub repo 2020-03-18 16:15:01 +05:30
5ad0888329 Fix db extensions 2020-03-16 08:04:49 +05:30
3cfc409e14 Bump version to 1.8.5 2020-03-14 09:12:58 +05:30
ebc671081f Bump ECMAScript version 2020-03-14 07:56:11 +05:30
efae663c0f Change case in README 2020-03-14 07:54:36 +05:30
fa8a671e6f Improve code quality 2020-03-14 07:53:43 +05:30
6a4159ba98 Improve extension support 2020-03-14 07:42:02 +05:30
0da52b1327 v1 maintenance release - 1.8.4 2020-03-02 20:40:27 +05:30
3579c7ef28 v1 maintenance release 2020-02-17 03:49:19 +05:30
94 changed files with 6058 additions and 8914 deletions

View File

@ -8,13 +8,12 @@ Please note that this project is released with a [Contributor Code of Conduct](C
* Fork the project. * Fork the project.
* Make your bug fix or feature addition. * Make your bug fix or feature addition.
* Add tests for it, so we don't break it in a future version unintentionally. * Add tests for it. This is important so we don't break it in a future version unintentionally.
* If editing the scripts, create a demo integration test. * Send a pull request to the develop branch.
* Send a pull request to the develop branch with all the details.
Please make sure that you have [set up your user name and email address](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup) for use with Git. Strings such as `silly nick name <root@localhost>` look really stupid in the commit history of a project. Please make sure that you have [set up your user name and email address](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup) for use with Git. Strings such as `silly nick name <root@localhost>` look really stupid in the commit history of a project.
Due to time constraints, you may not always get a quick response. Please do not take delays personally and feel free to remind. Due to time constraints, you may not always get a quick response. Please do not take delays personal and feel free to remind.
## Coding Guidelines ## Coding Guidelines
@ -67,4 +66,4 @@ $ npm run release
Please submit the issue using the appropriate template provided for a bug report or a feature request: Please submit the issue using the appropriate template provided for a bug report or a feature request:
* [Issues](https://github.com/shivammathur/setup-php/issues) * [Issues](https://github.com/shivammathur/setup-php/issues)

6
.github/FUNDING.yml vendored
View File

@ -1,7 +1,3 @@
# These are supported funding model platforms # These are supported funding model platforms
open_collective: setup-php github:shivammathur
tidelift: "npm/setup-php"
community_bridge: setup-php
patreon: shivammathur
custom: https://www.paypal.me/shivammathur

View File

@ -1,42 +1,23 @@
--- ---
name: Bug report name: Bug report
about: Nice, you found a bug! about: Create a report to help us improve
title: '' title: ''
labels: 'bug' labels: ''
assignees: 'shivammathur' assignees: ''
--- ---
**Describe the bug** **Describe the bug**
<!-- Please describe the bug concisely. --> A clear and concise description of what the bug is.
**Version**
- [ ] I have checked releases, and the bug exists in the latest patch version of `v1` or `v2`.
- [ ] `v2`
- [ ] `v1`
**Runners**
<!-- Please mark the GitHub Action runner your workflow uses. -->
- [ ] GitHub Hosted
- [ ] Self Hosted
**Operating systems**
<!-- Please mention the operating systems your workflow uses. -->
**PHP versions**
<!-- Please mention the PHP versions your workflow uses. -->
**To Reproduce** **To Reproduce**
<!-- Please provide the relevant steps of your workflow `.yml` file. --> Please provide the GitHub Action `.yml` file.
**Expected behavior** **Expected behavior**
<!-- A clear and concise description of what you expected to happen. --> A clear and concise description of what you expected to happen.
**Screenshots/Logs** **Screenshots**
<!-- If applicable, add screenshots or logs to help explain your problem. --> If applicable, add screenshots to help explain your problem.
**Additional context** **Additional context**
<!-- Add any other context about the problem here. --> Add any other context about the problem here.
**Are you willing to submit a PR?**
<!-- We accept pull requests targeting the develop branch. -->

View File

@ -1,26 +1,20 @@
--- ---
name: Feature request name: Feature request
about: Suggest a new feature about: Suggest an idea for this project
title: '' title: ''
labels: 'enhancement' labels: ''
assignees: 'shivammathur' assignees: ''
--- ---
**Describe the feature** **Is your feature request related to a problem? Please describe.**
<!-- Please describe concisely the feature you want to add. --> A clear and concise description of what the problem is. Ex. I want to improve [...]
**Version** **Describe the solution you'd like**
- [ ] I have checked releases, and the feature is missing in the latest patch version of `v2`. A clear and concise description of what you want to happen.
**Underlying issue** **Describe alternatives you've considered**
<!-- Please describe the issue this would solve. --> A clear and concise description of any alternative solutions or features you've considered.
**Describe alternatives**
<!-- Please mention any alternative solutions you've considered. -->
**Additional context** **Additional context**
<!-- Add any other context or screenshots about the feature request here. --> Add any other context or screenshots about the feature request here.
**Are you willing to submit a PR?**
<!-- We accept pull requests targeting the develop branch. -->

View File

@ -5,15 +5,16 @@ labels: bug or enhancement
--- ---
## A Pull Request should be associated with a Discussion. ## A Pull Request should be associated with an Issue.
> If you're fixing a bug, adding a new feature or improving something please provide the details in discussions, > We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
> so that the development can be pointed in the intended direction. > If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
> and potentially we'll be able to point development in a particular direction.
Related discussion: <!-- Please link the related discussion --> Related issue:
> Further notes in [Contribution Guidelines](.github/CONTRIBUTING.md) > Further notes in [Contribution Guidelines](.github/CONTRIBUTING.md)
> Thank you for your contribution. > Thank you! We are open to PRs, but please understand if for technical reasons we are unable to accept each and any PR
### Description ### Description

3
.github/SECURITY.md vendored
View File

@ -7,7 +7,7 @@ The following versions of this project are supported for security updates.
| Version | Supported | | Version | Supported |
| ------- | ------------------ | | ------- | ------------------ |
| 1.11.x | :white_check_mark: | | 1.11.x | :white_check_mark: |
| 2.11.x | :white_check_mark: | | 2.14.x | :white_check_mark: |
## Supported PHP Versions ## Supported PHP Versions
@ -18,6 +18,7 @@ This security policy only applies to the latest patches of the following PHP ver
| 7.3 | :white_check_mark: | | 7.3 | :white_check_mark: |
| 7.4 | :white_check_mark: | | 7.4 | :white_check_mark: |
| 8.0 | :white_check_mark: | | 8.0 | :white_check_mark: |
| 8.1 | :white_check_mark: |
## Reporting a Vulnerability ## Reporting a Vulnerability

View File

@ -0,0 +1,4 @@
name : CodeQL Configuration
paths:
- './src'

25
.github/workflows/codeql-workflow.yml vendored Normal file
View File

@ -0,0 +1,25 @@
name: CodeQL Workflow
on:
workflow_dispatch:
schedule:
- cron: '0 15 * * 6'
jobs:
codeql:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
config-file: ./.github/codeql/codeql-configuration.yml
languages: javascript
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@ -1,77 +0,0 @@
name: Docs workflow
on:
workflow_dispatch:
schedule:
- cron: '0 15 * * 6'
jobs:
create:
name: Create
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-20.04, ubuntu-18.04, windows-2019, macos-10.15]
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Save unix
env:
file: php${{ matrix.php-versions }}-${{ matrix.operating-system }}.md
version: ${{ matrix.php-versions }}
if: matrix.operating-system != 'windows-2019'
run: |
echo "## PHP $version" >> "$file"
printf "\n" >> "$file"
echo "\`\`\`" >> "$file"
php -m >> "$file"
echo "\`\`\`" >> "$file"
printf "\n" >> "$file"
- name: Save Windows
env:
file: php${{ matrix.php-versions }}-${{ matrix.operating-system }}.md
version: ${{ matrix.php-versions }}
if: matrix.operating-system == 'windows-2019'
run: |
Write-Output "## PHP ${{ matrix.php-versions }}`n" | Out-File -FilePath "$env:file"
Write-Output "``````" | Out-File -FilePath "$env:file" -Append
php -m | Out-File -FilePath "$env:file" -Append
Write-Output "```````n" | Out-File -FilePath "$env:file" -Append
- uses: actions/upload-artifact@v2
with:
name: lists
path: php${{ matrix.php-versions }}-${{ matrix.operating-system }}.md
update:
name: Update
needs: create
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
repository: ${{ github.repository }}.wiki
- uses: actions/download-artifact@v2
with:
path: ${{ github.workspace }}
- name: Combine
run: |
git config --local user.email "${{ secrets.email }}"
git config --local user.name "${{ github.repository_owner }}"
for os in ubuntu-20.04 ubuntu-18.04 windows-2019 macos-10.15 macos-11; do
echo "These are extensions which are loaded by default on the following PHP versions. More extensions which are available as packages and available on pecl are supported by setup-php. Refer to [php extension support](https://github.com/shivammathur/setup-php#heavy_plus_sign-php-extension-support) for more details." > Php-extensions-loaded-on-"$os".md
for version in 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1; do
if [ "$os" = "macos-11" ]; then
cat lists/php"$version"-macos-10.15.md >> Php-extensions-loaded-on-"$os".md
else
cat lists/php"$version"-"$os".md >> Php-extensions-loaded-on-"$os".md
fi
done
done
rm -rf ./lists
if [ "$(git status --porcelain=v1 2>/dev/null | wc -l)" != "0" ]; then
git add .
git commit -m "Update PHP extensions on wiki - $(date +'%d-%m-%y')"
git push -f https://${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.wiki.git master || true
fi

View File

@ -3,17 +3,13 @@ on:
workflow_dispatch: workflow_dispatch:
pull_request: pull_request:
branches: branches:
- master - releases/v1
- develop
- verbose
paths-ignore: paths-ignore:
- '**.md' - '**.md'
- 'examples/**' - 'examples/**'
push: push:
branches: branches:
- master - releases/v1
- develop
- verbose
paths-ignore: paths-ignore:
- '**.md' - '**.md'
- 'examples/**' - 'examples/**'
@ -25,35 +21,17 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
operating-system: [ubuntu-20.04, ubuntu-18.04, windows-latest, macos-latest] operating-system: [ubuntu-20.04, ubuntu-18.04, windows-latest, macos-latest]
php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
env:
extensions: xml, opcache, xdebug, pcov
key: cache-v3
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@develop
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}
- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}
- name: Setup PHP with extensions and custom config - name: Setup PHP with extensions and custom config
run: node dist/index.js run: node dist/index.js
env: env:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: ${{ env.extensions }} extensions: xml, opcache, xdebug, pcov #optional
ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata #optional
- name: Testing PHP version - name: Testing PHP version
run: | run: |

View File

@ -2,17 +2,13 @@ name: Node workflow
on: on:
pull_request: pull_request:
branches: branches:
- master - releases/v1
- develop
- verbose
paths-ignore: paths-ignore:
- '**.md' - '**.md'
- 'examples/**' - 'examples/**'
push: push:
branches: branches:
- master - releases/v1
- develop
- verbose
paths-ignore: paths-ignore:
- '**.md' - '**.md'
- 'examples/**' - 'examples/**'
@ -28,10 +24,10 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup Node.js 15.x - name: Setup Node.js 16.x
uses: actions/setup-node@v1 uses: actions/setup-node@v1
with: with:
node-version: 15.x node-version: 16.x
- name: Install dependencies - name: Install dependencies
run: npm install run: npm install
@ -45,7 +41,14 @@ jobs:
- name: Run tests - name: Run tests
run: npm test run: npm test
- name: Run npm audit
run: npm audit
- name: Send Coverage - name: Send Coverage
continue-on-error: true uses: codecov/codecov-action@v2
timeout-minutes: 1 with:
run: curl -s https://codecov.io/bash | bash -s -- -t ${{secrets.CODECOV_TOKEN}} -f coverage/lcov.info -n github-actions-codecov-${{ matrix.operating-system }} token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/lcov.info
name: github-actions-codecov-${{ matrix.operating-system }}
fail_ci_if_error: false
verbose: true

View File

@ -1,7 +1,7 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2019-2021 shivammathur and contributors Copyright (c) 2019-2020 shivammathur and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

826
README.md

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ describe('Config tests', () => {
'win32' 'win32'
); );
expect(win32).toContain( expect(win32).toContain(
'Add-Content "$php_dir\\php.ini" "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"' 'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"'
); );
win32 = await config.addINIValues( win32 = await config.addINIValues(
@ -24,7 +24,7 @@ describe('Config tests', () => {
true true
); );
expect(linux).toContain( expect(linux).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" | sudo tee -a "${pecl_file:-${ini_file[@]}}"' 'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"'
); );
linux = await config.addINIValues( linux = await config.addINIValues(
@ -40,7 +40,7 @@ describe('Config tests', () => {
'darwin' 'darwin'
); );
expect(darwin).toContain( expect(darwin).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" | sudo tee -a "${pecl_file:-${ini_file[@]}}"' 'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"'
); );
darwin = await config.addINIValues( darwin = await config.addINIValues(

View File

@ -3,28 +3,15 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => { describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => { it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension( let win32: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1', 'Xdebug, pcov, sqlite, phalcon4, ast-beta',
'7.4', '7.4',
'win32' 'win32'
); );
expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('Add-Extension sqlite3'); expect(win32).toContain('Add-Extension sqlite3');
expect(win32).toContain('Remove-Extension intl'); expect(win32).toContain('phalcon.ps1 phalcon4');
expect(win32).toContain('Add-Phalcon phalcon4');
expect(win32).toContain('Add-Http');
expect(win32).toContain('Add-Ioncube');
expect(win32).toContain('Add-Oci oci8');
expect(win32).toContain('Add-Oci pdo_oci');
expect(win32).toContain('Add-Extension ast beta'); expect(win32).toContain('Add-Extension ast beta');
expect(win32).toContain('Add-Extension grpc stable 1.2.3');
expect(win32).toContain('Add-Extension inotify alpha 1.2.3');
expect(win32).toContain('Add-Extension sqlsrv devel 1.2.3');
win32 = await extensions.addExtension('pcov', '5.6', 'win32');
expect(win32).toContain(
'Add-Log "$cross" "pcov" "pcov is not supported on PHP 5.6"'
);
win32 = await extensions.addExtension('xdebug2', '7.2', 'win32'); win32 = await extensions.addExtension('xdebug2', '7.2', 'win32');
expect(win32).toContain('Add-Extension xdebug stable 2.9.8'); expect(win32).toContain('Add-Extension xdebug stable 2.9.8');
@ -37,7 +24,7 @@ describe('Extension tests', () => {
expect(win32).toContain('Add-Extension mysqli'); expect(win32).toContain('Add-Extension mysqli');
expect(win32).toContain('Add-Extension mysqlnd'); expect(win32).toContain('Add-Extension mysqlnd');
win32 = await extensions.addExtension('mysql', '5.5', 'win32'); win32 = await extensions.addExtension('mysql', '5.6', 'win32');
expect(win32).toContain('Add-Extension mysql'); expect(win32).toContain('Add-Extension mysql');
expect(win32).toContain('Add-Extension mysqli'); expect(win32).toContain('Add-Extension mysqli');
expect(win32).toContain('Add-Extension mysqlnd'); expect(win32).toContain('Add-Extension mysqlnd');
@ -48,64 +35,30 @@ describe('Extension tests', () => {
'win32', 'win32',
true true
); );
expect(win32).toContain('Add-Phalcon phalcon3'); expect(win32).toContain('phalcon.ps1 phalcon3');
expect(win32).toContain('Add-Extension does_not_exist'); expect(win32).toContain('Add-Extension does_not_exist');
win32 = await extensions.addExtension('xdebug', '7.2', 'openbsd'); win32 = await extensions.addExtension('xdebug', '7.2', 'openbsd');
expect(win32).toContain('Platform openbsd is not supported'); expect(win32).toContain('Platform openbsd is not supported');
win32 = await extensions.addExtension('blackfire', '7.3', 'win32');
expect(win32).toContain('Add-Blackfire blackfire');
win32 = await extensions.addExtension('blackfire-1.31.0', '7.3', 'win32');
expect(win32).toContain('Add-Blackfire blackfire-1.31.0');
win32 = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'win32'
);
expect(win32).toContain(
'Add-Log "$cross" "mongodb-mongodb/mongo-php-driver@master" "mongodb-mongodb/mongo-php-driver@master is not supported on PHP 7.3"'
);
}); });
it('checking addExtensionOnLinux', async () => { it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension( let linux: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3', 'Xdebug, pcov, sqlite, ast-beta, xdebug-alpha',
'7.4', '7.4',
'linux' 'linux'
); );
expect(linux).toContain('add_extension xdebug'); expect(linux).toContain('sudo $debconf_fix apt-get install -y php7.4-pcov');
expect(linux).toContain('add_extension sqlite3'); expect(linux).toContain(
expect(linux).toContain('remove_extension intl'); 'sudo $debconf_fix apt-get install -y php7.4-sqlite3'
);
expect(linux).toContain('add_unstable_extension ast beta extension'); expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain('add_pdo_extension mysql');
expect(linux).toContain('add_pdo_extension odbc');
expect(linux).toContain('add_pecl_extension grpc 1.2.3 extension');
expect(linux).toContain( expect(linux).toContain(
'add_unstable_extension xdebug alpha zend_extension' 'add_unstable_extension xdebug alpha zend_extension'
); );
linux = await extensions.addExtension('pcov', '5.6', 'linux'); linux = await extensions.addExtension('gearman', '7.0', 'linux');
expect(linux).toContain( expect(linux).toContain('gearman.sh');
'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"'
);
linux = await extensions.addExtension('gearman', '5.6', 'linux');
expect(linux).toContain('add_gearman');
linux = await extensions.addExtension('gearman', '7.4', 'linux');
expect(linux).toContain('add_gearman');
linux = await extensions.addExtension('couchbase', '5.6', 'linux');
expect(linux).toContain('add_couchbase');
linux = await extensions.addExtension('couchbase', '7.4', 'linux');
expect(linux).toContain('add_couchbase');
linux = await extensions.addExtension('pdo_cubrid', '7.0', 'linux');
expect(linux).toContain('add_cubrid pdo_cubrid');
linux = await extensions.addExtension('cubrid', '7.4', 'linux');
expect(linux).toContain('add_cubrid cubrid');
linux = await extensions.addExtension('xdebug2', '7.2', 'linux'); linux = await extensions.addExtension('xdebug2', '7.2', 'linux');
expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension'); expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension');
@ -114,107 +67,35 @@ describe('Extension tests', () => {
expect(linux).toContain('Platform openbsd is not supported'); expect(linux).toContain('Platform openbsd is not supported');
linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux'); linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux');
expect(linux).toContain('add_phalcon phalcon3'); expect(linux).toContain('phalcon.sh phalcon3 7.3');
expect(linux).toContain('add_phalcon phalcon4'); expect(linux).toContain('phalcon.sh phalcon4 7.3');
linux = await extensions.addExtension('ioncube', '7.3', 'linux');
expect(linux).toContain('add_ioncube');
linux = await extensions.addExtension('geos', '7.3', 'linux');
expect(linux).toContain('add_geos');
linux = await extensions.addExtension('pecl_http', '7.3', 'linux');
expect(linux).toContain('add_http');
linux = await extensions.addExtension('http-1.2.3', '7.3', 'linux');
expect(linux).toContain('add_http http-1.2.3');
linux = await extensions.addExtension('oci8, pdo_oci', '7.3', 'linux');
expect(linux).toContain('add_oci oci8');
expect(linux).toContain('add_oci pdo_oci');
linux = await extensions.addExtension('blackfire', '7.3', 'linux');
expect(linux).toContain('add_blackfire blackfire');
linux = await extensions.addExtension('blackfire-1.31.0', '7.3', 'linux');
expect(linux).toContain('add_blackfire blackfire-1.31.0');
linux = await extensions.addExtension('intl-65.1', '5.6', 'linux');
expect(linux).toContain('add_intl intl-65.1');
linux = await extensions.addExtension('intl-67.1', '7.3', 'linux');
expect(linux).toContain('add_intl intl-67.1');
linux = await extensions.addExtension('intl-68.2', '8.0', 'linux');
expect(linux).toContain('add_intl intl-68.2');
linux = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'linux'
);
expect(linux).toContain(
'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension'
);
}); });
it('checking addExtensionOnDarwin', async () => { it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension( let darwin: string = await extensions.addExtension(
'amqp, apcu, Xdebug, pcov, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, phalcon3, phalcon4, protobuf, psr, rdkafka, redis, swoole, yaml, sqlite, oci8, pdo_oci, :intl, ast-beta, grpc-1.2.3', 'Xdebug, pcov, expect, grpc, igbinary, imagick, phalcon3, phalcon4, protobuf, psr, rdkafka, ssh2, swoole, vips, sqlite, ast-beta',
'7.2', '7.2',
'darwin' 'darwin'
); );
expect(darwin).toContain('add_brew_extension amqp extension'); expect(darwin).toContain('add_brew_extension xdebug');
expect(darwin).toContain('add_brew_extension apcu extension'); expect(darwin).toContain('add_brew_extension pcov');
expect(darwin).toContain('add_brew_extension xdebug zend_extension'); expect(darwin).toContain('add_brew_extension expect');
expect(darwin).toContain('add_brew_extension pcov extension'); expect(darwin).toContain('add_brew_extension grpc');
expect(darwin).toContain('add_brew_extension grpc extension'); expect(darwin).toContain('add_brew_extension igbinary');
expect(darwin).toContain('add_brew_extension igbinary extension'); expect(darwin).toContain('add_brew_extension imagick');
expect(darwin).toContain('add_brew_extension imagick extension'); expect(darwin).toContain('add_brew_extension phalcon3');
expect(darwin).toContain('add_brew_extension imap extension'); expect(darwin).toContain('add_brew_extension phalcon4');
expect(darwin).toContain('add_brew_extension memcache extension'); expect(darwin).toContain('add_brew_extension protobuf');
expect(darwin).toContain('add_brew_extension memcached extension'); expect(darwin).toContain('add_brew_extension psr');
expect(darwin).toContain('add_brew_extension mongodb extension'); expect(darwin).toContain('add_brew_extension rdkafka');
expect(darwin).toContain('add_brew_extension msgpack extension'); expect(darwin).toContain('add_brew_extension ssh2');
expect(darwin).toContain('add_brew_extension phalcon3 extension'); expect(darwin).toContain('add_brew_extension swoole');
expect(darwin).toContain('add_brew_extension phalcon4 extension'); expect(darwin).toContain('add_brew_extension vips');
expect(darwin).toContain('add_brew_extension protobuf extension'); expect(darwin).toContain('pecl_install sqlite3');
expect(darwin).toContain('add_brew_extension psr extension');
expect(darwin).toContain('add_brew_extension rdkafka extension');
expect(darwin).toContain('add_brew_extension redis extension');
expect(darwin).toContain('add_brew_extension swoole extension');
expect(darwin).toContain('add_brew_extension yaml extension');
expect(darwin).toContain('add_extension sqlite3');
expect(darwin).toContain('remove_extension intl');
expect(darwin).toContain('add_unstable_extension ast beta extension'); expect(darwin).toContain('add_unstable_extension ast beta extension');
expect(darwin).toContain('add_pecl_extension grpc 1.2.3 extension');
darwin = await extensions.addExtension('couchbase', '5.6', 'darwin');
expect(darwin).toContain('add_couchbase');
darwin = await extensions.addExtension('couchbase', '7.3', 'darwin');
expect(darwin).toContain('add_couchbase');
darwin = await extensions.addExtension('ioncube', '7.3', 'darwin');
expect(darwin).toContain('add_ioncube');
darwin = await extensions.addExtension('geos', '7.3', 'darwin');
expect(darwin).toContain('add_geos');
darwin = await extensions.addExtension('pecl_http', '7.3', 'darwin');
expect(darwin).toContain('add_http');
darwin = await extensions.addExtension('http-1.2.3', '7.3', 'darwin');
expect(darwin).toContain('add_http http-1.2.3');
darwin = await extensions.addExtension('oci8, pdo_oci', '7.3', 'darwin');
expect(darwin).toContain('add_oci oci8');
expect(darwin).toContain('add_oci pdo_oci');
darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); darwin = await extensions.addExtension('pcov', '5.6', 'darwin');
expect(darwin).toContain( expect(darwin).toContain('pecl_install pcov');
'add_log "$cross" "pcov" "pcov is not supported on PHP 5.6"'
);
darwin = await extensions.addExtension('pcov', '7.2', 'darwin'); darwin = await extensions.addExtension('pcov', '7.2', 'darwin');
expect(darwin).toContain('add_brew_extension pcov'); expect(darwin).toContain('add_brew_extension pcov');
@ -225,21 +106,9 @@ describe('Extension tests', () => {
darwin = await extensions.addExtension('xdebug', '7.0', 'darwin'); darwin = await extensions.addExtension('xdebug', '7.0', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug'); expect(darwin).toContain('add_brew_extension xdebug');
darwin = await extensions.addExtension('xdebug', '7.2', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug');
darwin = await extensions.addExtension('xdebug2', '7.2', 'darwin'); darwin = await extensions.addExtension('xdebug2', '7.2', 'darwin');
expect(darwin).toContain('add_brew_extension xdebug2'); expect(darwin).toContain('add_brew_extension xdebug2');
darwin = await extensions.addExtension('imagick', '5.5', 'darwin');
expect(darwin).toContain('add_extension imagick');
darwin = await extensions.addExtension('blackfire', '7.3', 'darwin');
expect(darwin).toContain('add_blackfire blackfire');
darwin = await extensions.addExtension('blackfire-1.31.0', '7.3', 'darwin');
expect(darwin).toContain('add_blackfire blackfire-1.31.0');
darwin = await extensions.addExtension( darwin = await extensions.addExtension(
'does_not_exist', 'does_not_exist',
'7.2', '7.2',
@ -250,14 +119,5 @@ describe('Extension tests', () => {
darwin = await extensions.addExtension('xdebug', '7.2', 'openbsd'); darwin = await extensions.addExtension('xdebug', '7.2', 'openbsd');
expect(darwin).toContain('Platform openbsd is not supported'); expect(darwin).toContain('Platform openbsd is not supported');
darwin = await extensions.addExtension(
'mongodb-mongodb/mongo-php-driver@master',
'7.3',
'darwin'
);
expect(darwin).toContain(
'add_extension_from_source mongodb https://github.com mongodb mongo-php-driver master extension'
);
}); });
}); });

View File

@ -1,11 +1,10 @@
import * as install from '../src/install'; import * as install from '../src/install';
import * as utils from '../src/utils';
/** /**
* Mock install.ts * Mock install.ts
*/ */
jest.mock('../src/install', () => ({ jest.mock('../src/install', () => ({
getScript: jest build: jest
.fn() .fn()
.mockImplementation( .mockImplementation(
async ( async (
@ -41,18 +40,24 @@ jest.mock('../src/install', () => ({
), ),
run: jest.fn().mockImplementation(async (): Promise<string> => { run: jest.fn().mockImplementation(async (): Promise<string> => {
const os_version: string = process.env['RUNNER_OS'] || ''; const os_version: string = process.env['RUNNER_OS'] || '';
const version: string = await utils.parseVersion( let version: string = process.env['php-version'] || '';
await utils.getInput('php-version', true) version = version.length > 1 ? version.slice(0, 3) : version + '.0';
); let script = '';
const tool = await utils.scriptTool(os_version); switch (os_version) {
const filename = os_version + (await utils.scriptExtension(os_version)); case 'darwin':
return [ case 'linux':
await install.getScript(filename, version, os_version), script = await install.build(os_version + '.sh', version, os_version);
tool, script += 'bash script.sh ' + version + ' ' + __dirname;
filename, break;
version, case 'win32':
__dirname script = await install.build(os_version + '.sh', version, os_version);
].join(' '); script += 'pwsh script.ps1 ' + version + ' ' + __dirname;
break;
default:
script += os_version + ' is not supported';
}
return script;
}) })
})); }));
@ -65,6 +70,7 @@ jest.mock('../src/install', () => ({
* @param ini_values_csv * @param ini_values_csv
* @param coverage_driver * @param coverage_driver
* @param tools * @param tools
* @param pecl
*/ */
function setEnv( function setEnv(
version: string | number, version: string | number,
@ -72,7 +78,8 @@ function setEnv(
extension_csv: string, extension_csv: string,
ini_values_csv: string, ini_values_csv: string,
coverage_driver: string, coverage_driver: string,
tools: string tools: string,
pecl: string
): void { ): void {
process.env['php-version'] = version.toString(); process.env['php-version'] = version.toString();
process.env['RUNNER_OS'] = os; process.env['RUNNER_OS'] = os;
@ -80,96 +87,95 @@ function setEnv(
process.env['ini-values'] = ini_values_csv; process.env['ini-values'] = ini_values_csv;
process.env['coverage'] = coverage_driver; process.env['coverage'] = coverage_driver;
process.env['tools'] = tools; process.env['tools'] = tools;
process.env['pecl'] = pecl;
} }
describe('Install', () => { describe('Install', () => {
it('Test install on windows', async () => { it('Test install on windows', async () => {
setEnv('7.0', 'win32', '', '', '', ''); setEnv('7.0', 'win32', '', '', '', '', '');
let script: string = '' + (await install.run()); let script: string = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('pwsh win32.ps1 7.0 ' + __dirname); expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname);
setEnv('7.3', 'win32', '', '', '', ''); setEnv('7.3', 'win32', '', '', '', '', '');
script = '' + (await install.run()); script = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname); expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', ''); setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '', '');
script = '' + (await install.run()); script = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('pwsh win32.ps1 7.3 ' + __dirname); expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);
}); });
it('Test install on linux', async () => { it('Test install on linux', async () => {
setEnv('7.3', 'linux', '', '', '', ''); setEnv('7.3', 'linux', '', '', '', '', '');
let script: string = '' + (await install.run()); let script: string = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 7.3 '); expect(script).toContain('bash script.sh 7.3 ');
setEnv('latest', 'linux', '', '', '', ''); setEnv('7.4', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash linux.sh 8.0 ');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit');
script = '' + (await install.run()); script = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('bash linux.sh 7.3'); expect(script).toContain('bash script.sh 7.4');
expect(script).toContain('add_tool');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('bash script.sh 7.3');
expect(script).toContain('add_tool'); expect(script).toContain('add_tool');
}); });
it('Test install on darwin', async () => { it('Test install on darwin', async () => {
setEnv('7.3', 'darwin', '', '', '', ''); setEnv('7.3', 'darwin', '', '', '', '', '');
let script: string = '' + (await install.run()); let script: string = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname); expect(script).toContain('bash script.sh 7.3 ' + __dirname);
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', ''); setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', '');
script = '' + (await install.run()); script = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('bash darwin.sh 7.3 ' + __dirname); expect(script).toContain('bash script.sh 7.3 ' + __dirname);
}); });
it('Test malformed version inputs', async () => { it('Test malformed version inputs', async () => {
setEnv('7.4.1', 'darwin', '', '', '', ''); setEnv('7.4.1', 'darwin', '', '', '', '', '');
let script: string = '' + '' + (await install.run()); let script: string = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 7.4 ' + __dirname); expect(script).toContain('bash script.sh 7.4 ' + __dirname);
setEnv(8.0, 'darwin', '', '', '', ''); setEnv(8.0, 'darwin', '', '', '', '', '');
script = '' + (await install.run()); script = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname); expect(script).toContain('bash script.sh 8.0 ' + __dirname);
setEnv(8, 'darwin', '', '', '', ''); setEnv(8, 'darwin', '', '', '', '', '');
script = '' + (await install.run()); script = '' + (await install.run());
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.0 ' + __dirname); expect(script).toContain('bash script.sh 8.0 ' + __dirname);
setEnv(8.1, 'darwin', '', '', '', '');
script = '' + (await install.run());
expect(script).toContain('initial script');
expect(script).toContain('bash darwin.sh 8.1 ' + __dirname);
}); });
}); });

View File

@ -1,524 +1,481 @@
import * as tools from '../src/tools'; import * as tools from '../src/tools';
import * as utils from '../src/utils';
interface IData {
tool: string;
version?: string;
domain?: string;
extension?: string;
os_version?: string;
php_version?: string;
release?: string;
repository?: string;
type?: string;
fetch_latest?: string;
version_parameter?: string;
version_prefix?: string;
}
function getData(data: IData): Record<string, string> {
return {
tool: data.tool,
version: data.version || '',
domain: data.domain || 'https://example.com',
extension: data.extension || '.phar',
os_version: data.os_version || 'linux',
php_version: data.php_version || '7.4',
release: data.release || [data.tool, data.version].join(':'),
repository: data.repository || '',
type: data.type || 'phar',
fetch_latest: data.fetch_latest || 'false',
version_parameter: data.version_parameter || '-V',
version_prefix: data.version_prefix || '',
github: 'https://github.com',
prefix: 'releases',
verb: 'download'
};
}
jest
.spyOn(utils, 'fetch')
.mockImplementation(
async (url: string, token?: string): Promise<Record<string, string>> => {
if (url.includes('atom') && !url.includes('no-release')) {
return {
data: '"releases/tag/1.2.3", "releases/tag/3.2.1", "releases/tag/2.3.1"'
};
} else if (url.includes('no-release')) {
return {data: ''};
} else if (!token || token === 'valid_token') {
return {data: `[{"ref": "refs/tags/1.2.3", "url": "${url}"}]`};
} else if (token === 'beta_token') {
return {data: `[{"ref": "refs/tags/1.2.3-beta1", "url": "${url}"}]`};
} else if (token === 'no_data') {
return {data: '[]'};
} else {
return {error: 'Invalid token'};
}
}
);
describe('Tools tests', () => { describe('Tools tests', () => {
it.each` it('checking getCommand', async () => {
token | version expect(await tools.getCommand('linux', 'tool')).toBe('add_tool ');
${'invalid_token'} | ${'1.2'} expect(await tools.getCommand('darwin', 'tool')).toBe('add_tool ');
${'valid_token'} | ${'1.2.3'} expect(await tools.getCommand('win32', 'tool')).toBe('Add-Tool ');
${'beta_token'} | ${'1.2.3-beta1'} expect(await tools.getCommand('openbsd', 'tool')).toContain(
${''} | ${'1.2.3'} 'Platform openbsd is not supported'
`('checking getSemverVersion: $token', async ({token, version}) => {
process.env['COMPOSER_TOKEN'] = token;
expect(
await tools.getSemverVersion(getData({tool: 'tool', version: '1.2'}))
).toBe(version);
});
it.each`
tool | fetch_latest | version
${'tool'} | ${'true'} | ${'3.2.1'}
${'tool-no-release'} | ${'true'} | ${'latest'}
${'tool'} | ${'false'} | ${'latest'}
`(
'checking getLatestVersion: $tool, $fetch_latest, $version',
async ({tool, fetch_latest, version}) => {
expect(
await tools.getLatestVersion(
getData({
tool: tool,
repository: 'user/' + tool,
fetch_latest: fetch_latest
})
)
).toBe(version);
}
);
it.each`
version | tool | type | expected
${'latest'} | ${'tool'} | ${'phar'} | ${'latest'}
${'1'} | ${'composer'} | ${'phar'} | ${'1'}
${'1.2'} | ${'tool'} | ${'composer'} | ${'1.2.*'}
${'^1.2.3'} | ${'tool'} | ${'phar'} | ${'1.2.3'}
${'>=1.2.3'} | ${'tool'} | ${'phar'} | ${'1.2.3'}
${'>1.2.3'} | ${'tool'} | ${'phar'} | ${'1.2.3'}
${'1.2.3-ALPHA'} | ${'tool'} | ${'phar'} | ${'1.2.3-ALPHA'}
${'1.2.3-alpha'} | ${'tool'} | ${'phar'} | ${'1.2.3-alpha'}
${'1.2.3-beta'} | ${'tool'} | ${'phar'} | ${'1.2.3-beta'}
${'1.2.3-rc'} | ${'tool'} | ${'phar'} | ${'1.2.3-rc'}
${'1.2.3-dev'} | ${'tool'} | ${'phar'} | ${'1.2.3-dev'}
${'1.2.3-alpha1'} | ${'tool'} | ${'phar'} | ${'1.2.3-alpha1'}
${'1.2.3-alpha.1'} | ${'tool'} | ${'phar'} | ${'1.2.3-alpha.1'}
`(
'checking getVersion: $version, $tool, $type',
async ({version, tool, type, expected}) => {
expect(
await tools.getVersion(
version,
getData({tool: tool, version: version, type: type})
)
).toBe(expected);
}
);
it.each`
input | expected
${'tool'} | ${'tool'}
${'alias:1.2.3'} | ${'tool:1.2.3'}
${'tool:1.2.3'} | ${'tool:1.2.3'}
${'tool:^1.2.3'} | ${'tool:^1.2.3'}
${'tool:>=1.2.3'} | ${'tool:>=1.2.3'}
${'tool:>1.2.3'} | ${'tool:>1.2.3'}
${'tool:1.2.3-ALPHA'} | ${'tool:1.2.3-ALPHA'}
${'tool:1.2.3-beta'} | ${'tool:1.2.3-beta'}
${'tool:1.2.3-rc'} | ${'tool:1.2.3-rc'}
${'tool:1.2.3-dev'} | ${'tool:1.2.3-dev'}
${'tool:1.2.3-alpha1'} | ${'tool:1.2.3-alpha1'}
${'tool:1.2.3-alpha.1'} | ${'tool:1.2.3-alpha.1'}
${'user/tool:^1.2.3'} | ${'tool:^1.2.3'}
`('checking getRelease: $input', async ({input, expected}) => {
expect(
await tools.getRelease(input, getData({tool: 'tool', version: 'latest'}))
).toBe(expected);
});
it.each`
input_list | filtered_list
${'a, b'} | ${'composer, a, b'}
${'a, b, composer'} | ${'composer, a, b'}
${'a, b, composer:1.2.3'} | ${'composer:1.2.3, a, b'}
${'a, b, composer:v1.2.3'} | ${'composer:1.2.3, a, b'}
${'a, b, composer:snapshot'} | ${'composer:snapshot, a, b'}
${'a, b, composer:preview'} | ${'composer:preview, a, b'}
${'a, b, composer:1'} | ${'composer:1, a, b'}
${'a, b, composer:2'} | ${'composer:2, a, b'}
${'a, b, composer:v1'} | ${'composer:1, a, b'}
${'a, b, composer:v2'} | ${'composer:2, a, b'}
`('checking filterList $input_list', async ({input_list, filtered_list}) => {
expect(await tools.filterList(input_list.split(', '))).toStrictEqual(
filtered_list.split(', ')
); );
}); });
it.each` it('checking getCommand', async () => {
version | version_prefix | url_suffix expect(await tools.getCommand('linux', 'composertool')).toBe(
${'latest'} | ${'v'} | ${'latest/download/tool.phar'} 'add_composertool '
${'1.2.3'} | ${'v'} | ${'download/v1.2.3/tool.phar'} );
${'1.2.3'} | ${''} | ${'download/1.2.3/tool.phar'} expect(await tools.getCommand('darwin', 'composertool')).toBe(
`( 'add_composertool '
'checking getUrl: $version_prefix$version', );
async ({version, version_prefix, url_suffix}) => { expect(await tools.getCommand('win32', 'composertool')).toBe(
const data = getData({ 'Add-Composertool '
tool: 'tool', );
version: version, expect(await tools.getCommand('openbsd', 'composertool')).toContain(
version_prefix: version_prefix 'Platform openbsd is not supported'
}); );
expect(await tools.getUrl(data)).toContain(url_suffix);
}
);
it.each`
version | version_prefix | url
${'latest'} | ${''} | ${'https://example.com/tool.phar'}
${'1.2.3'} | ${'v'} | ${'https://example.com/tool-v1.2.3.phar'}
`(
'checking getPharUrl: $version_prefix$version',
async ({version, version_prefix, url}) => {
const data = getData({
tool: 'tool',
version: version,
version_prefix: version_prefix
});
expect(await tools.getPharUrl(data)).toBe(url);
}
);
it.each`
os_version | script
${'linux'} | ${'add_tool https://example.com/tool.phar tool "-v"'}
${'darwin'} | ${'add_tool https://example.com/tool.phar tool "-v"'}
${'win32'} | ${'Add-Tool https://example.com/tool.phar tool "-v"'}
${'openbsd'} | ${'Platform openbsd is not supported'}
`('checking addArchive: $os_version', async ({os_version, script}) => {
const data = getData({
tool: 'tool',
version: 'latest',
version_parameter: JSON.stringify('-v'),
os_version: os_version
});
data['url'] = 'https://example.com/tool.phar';
expect(await tools.addArchive(data)).toContain(script);
}); });
it.each` it('checking getCommand', async () => {
os_version | script expect(await tools.getCommand('linux', 'pecl')).toBe('add_pecl ');
${'linux'} | ${'add_composertool tool tool:1.2.3 user/'} expect(await tools.getCommand('darwin', 'pecl')).toBe('add_pecl ');
${'darwin'} | ${'add_composertool tool tool:1.2.3 user/'} expect(await tools.getCommand('win32', 'pecl')).toBe('Add-Pecl ');
${'win32'} | ${'Add-Composertool tool tool:1.2.3 user/'} expect(await tools.getCommand('openbsd', 'pecl')).toContain(
${'openbsd'} | ${'Platform openbsd is not supported'} 'Platform openbsd is not supported'
`('checking addPackage: $os_version', async ({os_version, script}) => { );
const data = getData({
tool: 'tool',
version: '1.2.3',
repository: 'user/tool',
os_version: os_version
});
data['release'] = [data['tool'], data['version']].join(':');
expect(await tools.addPackage(data)).toContain(script);
}); });
it.each` it('checking parseToolVersion', async () => {
version | php_version | os_version | script expect(await tools.getToolVersion('latest')).toBe('latest');
${'latest'} | ${'7.4'} | ${'linux'} | ${'add_tool https://phar.io/releases/phive.phar phive'} expect(await tools.getToolVersion('1.2.3')).toBe('1.2.3');
${'1.2.3'} | ${'7.4'} | ${'darwin'} | ${'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'} expect(await tools.getToolVersion('^1.2.3')).toBe('1.2.3');
${'1.2.3'} | ${'7.2'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.14.5/phive-0.14.5.phar phive'} expect(await tools.getToolVersion('>=1.2.3')).toBe('1.2.3');
${'1.2.3'} | ${'7.1'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.5/phive-0.13.5.phar phive'} expect(await tools.getToolVersion('>1.2.3')).toBe('1.2.3');
${'latest'} | ${'5.6'} | ${'win32'} | ${'Add-Tool https://github.com/phar-io/phive/releases/download/0.12.1/phive-0.12.1.phar phive'} expect(await tools.getToolVersion('1.2.3-ALPHA')).toBe('1.2.3-ALPHA');
${'latest'} | ${'5.5'} | ${'win32'} | ${'Phive is not supported on PHP 5.5'} expect(await tools.getToolVersion('1.2.3-alpha')).toBe('1.2.3-alpha');
`( expect(await tools.getToolVersion('1.2.3-beta')).toBe('1.2.3-beta');
'checking addPhive: $version, $php_version, $os_version', expect(await tools.getToolVersion('1.2.3-rc')).toBe('1.2.3-rc');
async ({version, php_version, os_version, script}) => { expect(await tools.getToolVersion('1.2.3-dev')).toBe('1.2.3-dev');
const data = getData({ expect(await tools.getToolVersion('1.2.3-alpha1')).toBe('1.2.3-alpha1');
tool: 'phive', expect(await tools.getToolVersion('1.2.3-alpha.1')).toBe('1.2.3-alpha.1');
domain: 'https://phar.io',
repository: 'phar-io/phive',
version_parameter: 'status',
version: version,
php_version: php_version,
os_version: os_version
});
script = await tools.addPhive(data);
expect(script).toContain(script);
}
);
it.each`
version | php_version | url
${'latest'} | ${'7.4'} | ${'https://get.blackfire.io/blackfire-player.phar'}
${'1.2.3'} | ${'7.4'} | ${'https://get.blackfire.io/blackfire-player-v1.2.3.phar'}
${'latest'} | ${'5.5'} | ${'https://get.blackfire.io/blackfire-player-v1.9.3.phar'}
${'latest'} | ${'7.0'} | ${'https://get.blackfire.io/blackfire-player-v1.9.3.phar'}
`(
'checking addBlackfirePlayer: $version, $php_version',
async ({version, php_version, url}) => {
const data = getData({
tool: 'blackfire-player',
domain: 'https://get.blackfire.io',
version_prefix: 'v',
version: version,
php_version: php_version
});
expect(await tools.addBlackfirePlayer(data)).toContain(url);
}
);
it.each`
version | url
${'latest'} | ${'https://deployer.org/deployer.phar'}
${'1.2.3'} | ${'https://deployer.org/releases/v1.2.3/deployer.phar'}
`('checking addDeployer: $version', async ({version, url}) => {
const data = getData({
tool: 'deployer',
domain: 'https://deployer.org',
version: version
});
expect(await tools.addDeployer(data)).toContain(url);
}); });
it.each` it('checking parseToolVersion', async () => {
version | no_tool_cache | cache_url | source_url expect(await tools.parseTool('phpunit')).toStrictEqual({
${'latest'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar'} | ${'https://getcomposer.org/composer-stable.phar'} name: 'phpunit',
${'stable'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar'} | ${'https://getcomposer.org/composer-stable.phar'} version: 'latest'
${'snapshot'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar'} | ${'https://getcomposer.org/composer.phar'}
${'preview'} | ${'true'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar'} | ${'https://getcomposer.org/composer-preview.phar'}
${'1'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar'} | ${'https://getcomposer.org/composer-1.phar'}
${'2'} | ${'false'} | ${'https://github.com/shivammathur/composer-cache/releases/latest/download/composer-2.phar'} | ${'https://getcomposer.org/composer-2.phar'}
${'1.2.3'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3.phar'}
${'1.2.3-RC1'} | ${'false'} | ${'https://github.com/composer/composer/releases/download/1.2.3-RC1/composer.phar'} | ${'https://getcomposer.org/composer-1.2.3-RC1.phar'}
`(
'checking addComposer: $version, $no_tool_cache',
async ({version, no_tool_cache, cache_url, source_url}) => {
const data = getData({
tool: 'composer',
domain: 'https://getcomposer.org',
repository: 'composer/composer',
version: version
});
process.env['no_tools_cache'] = no_tool_cache;
if (no_tool_cache !== 'true') {
expect(await tools.addComposer(data)).toContain(
`${cache_url},${source_url}`
);
} else {
expect(await tools.addComposer(data)).toContain(source_url);
}
}
);
it.each`
version | os_version | uri
${'latest'} | ${'linux'} | ${'releases/latest/download/symfony_linux_amd64'}
${'1.2.3'} | ${'linux'} | ${'releases/download/v1.2.3/symfony_linux_amd64'}
${'latest'} | ${'darwin'} | ${'releases/latest/download/symfony_darwin_amd64'}
${'1.2.3'} | ${'darwin'} | ${'releases/download/v1.2.3/symfony_darwin_amd64'}
${'latest'} | ${'win32'} | ${'releases/latest/download/symfony_windows_amd64.exe'}
${'1.2.3'} | ${'win32'} | ${'releases/download/v1.2.3/symfony_windows_amd64.exe'}
${'latest'} | ${'openbsd'} | ${'Platform openbsd is not supported'}
`(
'checking addSymfony: $version, $os_version',
async ({version, os_version, uri}) => {
const data = getData({
tool: 'symfony',
php_version: '7.4',
version: version,
os_version: os_version
});
expect(await tools.addSymfony(data)).toContain(uri);
}
);
it.each`
version | uri
${'latest'} | ${'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true'}
${'1.2.3'} | ${'wp-cli/wp-cli/releases/download/v1.2.3/wp-cli-1.2.3.phar'}
`('checking addWPCLI: $version', async ({version, uri}) => {
const data = getData({
tool: 'wp-cli',
repository: 'wp-cli/wp-cli',
php_version: '7.4',
version_prefix: 'v',
version: version
}); });
expect(await tools.addWPCLI(data)).toContain(uri); expect(await tools.parseTool('phpunit:1.2.3')).toStrictEqual({
}); name: 'phpunit',
version: '1.2.3'
it.each` });
tool | os_version | script expect(await tools.parseTool('phpunit:^1.2.3')).toStrictEqual({
${'phpize'} | ${'linux'} | ${'add_devtools phpize'} name: 'phpunit',
${'php-config'} | ${'linux'} | ${'add_devtools php-config'} version: '1.2.3'
${'phpize'} | ${'darwin'} | ${'add_devtools phpize'} });
${'php-config'} | ${'darwin'} | ${'add_devtools php-config'} expect(await tools.parseTool('phpunit:>=1.2.3')).toStrictEqual({
${'phpize'} | ${'win32'} | ${'Add-Log "$tick" "phpize" "phpize is not a windows tool"'} name: 'phpunit',
${'php-config'} | ${'win32'} | ${'Add-Log "$tick" "php-config" "php-config is not a windows tool"'} version: '1.2.3'
${'phpize'} | ${'openbsd'} | ${'Platform openbsd is not supported'} });
`( expect(await tools.parseTool('phpunit:>1.2.3')).toStrictEqual({
'checking addDevTools: $tool, $os_version', name: 'phpunit',
async ({tool, os_version, script}) => { version: '1.2.3'
const data = getData({ });
version: '7.4', expect(await tools.parseTool('phpunit:1.2.3-ALPHA')).toStrictEqual({
tool: tool, name: 'phpunit',
os_version: os_version version: '1.2.3-ALPHA'
}); });
expect(await tools.addDevTools(data)).toContain(script); expect(await tools.parseTool('phpunit:1.2.3-alpha')).toStrictEqual({
} name: 'phpunit',
); version: '1.2.3-alpha'
});
it.each([ expect(await tools.parseTool('phpunit:1.2.3-beta')).toStrictEqual({
[ name: 'phpunit',
'blackfire, blackfire-player, cs2pr, flex, grpc_php_plugin, php-cs-fixer, phplint, phpstan, phpunit, pecl, phing, phinx, phinx:1.2.3, phive, phpunit-bridge, php-config, phpize, protoc, symfony, vapor, wp', version: '1.2.3-beta'
[ });
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer', expect(await tools.parseTool('phpunit:1.2.3-rc')).toStrictEqual({
'add_blackfire', name: 'phpunit',
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"', version: '1.2.3-rc'
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"', });
'add_composertool flex flex symfony/', expect(await tools.parseTool('phpunit:1.2.3-dev')).toStrictEqual({
'add_grpc_php_plugin latest', name: 'phpunit',
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.2.1/php-cs-fixer.phar php-cs-fixer "-V"', version: '1.2.3-dev'
'add_composertool phplint phplint overtrue/', });
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan "-V"', expect(await tools.parseTool('phpunit:1.2.3-alpha1')).toStrictEqual({
'add_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"', name: 'phpunit',
'add_pecl', version: '1.2.3-alpha1'
'add_tool https://www.phing.info/get/phing-latest.phar phing "-v"', });
'add_composertool phinx phinx robmorgan/', expect(await tools.parseTool('phpunit:1.2.3-alpha.1')).toStrictEqual({
'add_composertool phinx phinx:1.2.3 robmorgan/', name: 'phpunit',
'add_tool https://phar.io/releases/phive.phar phive "status"', version: '1.2.3-alpha.1'
'add_composertool phpunit-bridge phpunit-bridge symfony/',
'add_devtools php-config',
'add_devtools phpize',
'add_protoc latest',
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony-cli "version"',
'add_composertool vapor-cli vapor-cli laravel/',
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
]
]
])('checking addTools on linux', async (tools_csv, scripts) => {
const expected = await tools.addTools(tools_csv, '7.4', 'linux');
scripts.forEach(script => {
expect(expected).toContain(script);
}); });
}); });
it.each([ it('checking getUri', async () => {
[ expect(
'behat, blackfire, blackfire-player, composer-normalize, composer-require-checker, composer-unused, cs2pr:1.2.3, flex, grpc_php_plugin:1.2.3, infection, phan, phan:1.2.3, phing:1.2.3, phinx, phive:1.2.3, php-config, phpcbf, phpcpd, phpcs, phpize, phpmd, phpspec, phpunit-bridge:5.6, protoc:v1.2.3, psalm, symfony-cli, symfony:1.2.3, vapor-cli, wp-cli', await tools.getUri('tool', '.phar', 'latest', 'releases', '', 'download')
[ ).toBe('releases/latest/download/tool.phar');
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer', expect(
'add_composertool behat behat behat/', await tools.getUri('tool', '.phar', '1.2.3', 'releases', '', 'download')
'add_blackfire', ).toBe('releases/download/1.2.3/tool.phar');
'add_tool https://get.blackfire.io/blackfire-player.phar blackfire-player "-V"', expect(
'add_tool https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar composer-normalize "-V"', await tools.getUri('tool', '.phar', '1.2.3', 'releases', 'v', 'download')
'add_composertool composer-require-checker composer-require-checker maglnet/', ).toBe('releases/download/v1.2.3/tool.phar');
'add_composertool composer-unused composer-unused icanhazstring/',
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr "-V"',
'add_composertool flex flex symfony/',
'add_grpc_php_plugin 1.2.3',
'add_tool https://github.com/infection/infection/releases/latest/download/infection.phar infection "-V"',
'add_tool https://github.com/phan/phan/releases/latest/download/phan.phar phan "-v"',
'add_tool https://github.com/phan/phan/releases/download/1.2.3/phan.phar phan "-v"',
'add_tool https://www.phing.info/get/phing-1.2.3.phar phing "-v"',
'add_composertool phinx phinx robmorgan/',
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive',
'add_devtools php-config',
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf "--version"',
'add_tool https://phar.phpunit.de/phpcpd.phar phpcpd "--version"',
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs "--version"',
'add_devtools phpize',
'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"',
'add_composertool phpspec phpspec phpspec/',
'add_composertool phpunit-bridge phpunit-bridge:5.6.* symfony/',
'add_protoc 1.2.3',
'add_tool https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm "-v"',
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_darwin_amd64 symfony-cli "version"',
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony-cli "version"',
'add_composertool vapor-cli vapor-cli laravel/',
'add_tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"'
]
]
])('checking addTools on darwin', async (tools_csv, scripts) => {
const expected = await tools.addTools(tools_csv, '7.4', 'darwin');
scripts.forEach(script => {
expect(expected).toContain(script);
});
}); });
it.each([ it('checking addPhive', async () => {
[ let script: string = await tools.addPhive('1.2.3', '7.4', 'linux');
'blackfire, blackfire-player:1.2.3, cs2pr, deployer, does_not_exist, flex, phinx, phive:0.13.2, php-config, phpize, phpmd, simple-phpunit, symfony, wp', expect(script).toContain(
[ 'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer', );
'Add-Blackfire',
'Add-Tool https://get.blackfire.io/blackfire-player-v1.2.3.phar blackfire-player "-V"', script = await tools.addPhive('latest', '5.6', 'win32');
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr "-V"', expect(script).toContain(
'Add-Tool https://deployer.org/deployer.phar deployer "-V"', 'Add-Tool https://github.com/phar-io/phive/releases/download/0.12.1/phive-0.12.1.phar phive'
'Tool does_not_exist is not supported', );
'Add-Composertool flex flex symfony/',
'Add-Composertool phinx phinx robmorgan/', script = await tools.addPhive('latest', '7.1', 'win32');
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive "status"', expect(script).toContain(
'php-config is not a windows tool', 'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.5/phive-0.13.5.phar phive'
'phpize is not a windows tool', );
'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd "--version"',
'Add-Composertool phpunit-bridge phpunit-bridge symfony/', script = await tools.addPhive('latest', '7.2', 'win32');
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony-cli "version"', expect(script).toContain(
'Add-Tool https://github.com/wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true wp-cli "--version"' 'Add-Tool https://github.com/phar-io/phive/releases/download/0.14.5/phive-0.14.5.phar phive'
] );
]
])('checking addTools on Windows', async (tools_csv, scripts) => {
const expected = await tools.addTools(tools_csv, '7.4', 'win32');
scripts.forEach(script => {
expect(expected).toContain(script);
});
}); });
it.each([ it('checking getPhpunitUri', async () => {
[ expect(await tools.getPharUrl('domain', 'tool', '', 'latest')).toBe(
'composer:v1, codeception/codeception, prestissimo, hirak/prestissimo, composer-prefetcher, narrowspark/automatic-composer-prefetcher, phinx: 1.2, robmorgan/phinx: ^1.2, user/tool:1.2.3, user/tool:~1.2', 'domain/tool.phar'
[ );
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer', expect(await tools.getPharUrl('domain', 'tool', 'v', '1.2.3')).toBe(
'Add-Composertool codeception codeception codeception/', 'domain/tool-v1.2.3.phar'
'Add-Composertool prestissimo prestissimo hirak/', );
'Add-Composertool automatic-composer-prefetcher automatic-composer-prefetcher narrowspark/',
'Add-Composertool phinx phinx:1.2.* robmorgan/',
'Add-Composertool phinx phinx:^1.2 robmorgan/',
'Add-Composertool tool tool:1.2.3 user/',
'Add-Composertool tool tool:~1.2 user/'
]
]
])(
'checking addTools with composer tool using user/tool as input',
async (tools_csv, scripts) => {
const expected = await tools.addTools(tools_csv, '7.4', 'win32');
scripts.forEach(script => {
expect(expected).toContain(script);
});
}
);
it.each`
tools_csv | script
${'none'} | ${''}
${'none, phpunit'} | ${'\nstep_log "Setup Tools"\nadd_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-stable.phar,https://getcomposer.org/composer-stable.phar composer latest\n\nadd_tool https://phar.phpunit.de/phpunit.phar phpunit "--version"'}
${'composer:preview'} | ${'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-preview.phar,https://getcomposer.org/composer-preview.phar composer preview'}
${'composer, composer:v1'} | ${'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-1.phar,https://getcomposer.org/composer-1.phar composer'}
${'composer:v1, composer:preview, composer:snapshot'} | ${'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-snapshot.phar,https://getcomposer.org/composer.phar composer snapshot'}
`('checking composer setup: $tools_csv', async ({tools_csv, script}) => {
expect(await tools.addTools(tools_csv, '7.4', 'linux')).toContain(script);
}); });
it.each` it('checking getDeployerUri', async () => {
tools_csv | token | script expect(await tools.getDeployerUrl('latest')).toBe(
${'cs2pr:1.2'} | ${'invalid_token'} | ${'add_log "$cross" "cs2pr" "Invalid token"'} 'https://deployer.org/deployer.phar'
${'phpunit:1.2'} | ${'invalid_token'} | ${'add_log "$cross" "phpunit" "Invalid token"'} );
${'phpunit:0.1'} | ${'no_data'} | ${'add_log "$cross" "phpunit" "No version found with prefix 0.1."'} expect(await tools.getDeployerUrl('1.2.3')).toBe(
`('checking error: $tools_csv', async ({tools_csv, token, script}) => { 'https://deployer.org/releases/v1.2.3/deployer.phar'
process.env['COMPOSER_TOKEN'] = token; );
expect(await tools.addTools(tools_csv, '7.4', 'linux')).toContain(script); });
it('checking addComposer', async () => {
expect(await tools.addComposer(['a', 'b'])).toStrictEqual([
'composer',
'a',
'b'
]);
expect(await tools.addComposer(['a', 'b', 'composer'])).toStrictEqual([
'composer',
'a',
'b'
]);
expect(await tools.addComposer(['a', 'b', 'composer:1.2'])).toStrictEqual([
'composer',
'a',
'b'
]);
expect(await tools.addComposer(['a', 'b', 'composer:1.2.3'])).toStrictEqual(
['composer:1.2.3', 'a', 'b']
);
expect(
await tools.addComposer(['a', 'b', 'composer:v1.2.3'])
).toStrictEqual(['composer:1.2.3', 'a', 'b']);
expect(
await tools.addComposer(['a', 'b', 'composer:snapshot'])
).toStrictEqual(['composer:snapshot', 'a', 'b']);
expect(
await tools.addComposer(['a', 'b', 'composer:preview'])
).toStrictEqual(['composer:preview', 'a', 'b']);
expect(
await tools.addComposer(['a', 'b', 'c', 'composer:1'])
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
expect(
await tools.addComposer(['a', 'b', 'c', 'composer:2'])
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
expect(
await tools.addComposer(['a', 'b', 'c', 'composer:v1'])
).toStrictEqual(['composer:1', 'a', 'b', 'c']);
expect(
await tools.addComposer(['a', 'b', 'c', 'composer:v2'])
).toStrictEqual(['composer:2', 'a', 'b', 'c']);
expect(
await tools.addComposer(['hirak', 'b', 'c', 'composer:v2'])
).toStrictEqual(['composer:1', 'hirak', 'b', 'c']);
});
it('checking getComposerUrl', async () => {
expect(await tools.getComposerUrl('latest', '7.4')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
expect(await tools.getComposerUrl('stable', '7.4')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
expect(await tools.getComposerUrl('snapshot', '7.4')).toContain(
'https://getcomposer.org/composer.phar'
);
expect(await tools.getComposerUrl('preview', '7.4')).toContain(
'https://getcomposer.org/composer-preview.phar'
);
expect(await tools.getComposerUrl('1', '7.4')).toContain(
'https://getcomposer.org/composer-1.phar'
);
expect(await tools.getComposerUrl('2', '7.4')).toContain(
'https://getcomposer.org/composer-2.phar'
);
expect(await tools.getComposerUrl('1.7.2', '7.4')).toContain(
'https://github.com/composer/composer/releases/download/1.7.2/composer.phar'
);
expect(await tools.getComposerUrl('1.7.2', '7.4')).toContain(
'https://getcomposer.org/composer-1.7.2.phar'
);
expect(await tools.getComposerUrl('2.0.0-RC2', '7.4')).toContain(
'https://github.com/composer/composer/releases/download/2.0.0-RC2/composer.phar'
);
expect(await tools.getComposerUrl('2.0.0-RC2', '7.4')).toContain(
'https://getcomposer.org/composer-2.0.0-RC2.phar'
);
expect(await tools.getComposerUrl('wrong', '7.4')).toContain(
'https://getcomposer.org/composer-stable.phar'
);
});
it('checking getSymfonyUri', async () => {
expect(await tools.getSymfonyUri('latest', 'linux')).toContain(
'releases/latest/download/symfony_linux_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'linux')).toContain(
'releases/download/v1.2.3/symfony_linux_amd64'
);
expect(await tools.getSymfonyUri('latest', 'darwin')).toContain(
'releases/latest/download/symfony_darwin_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'darwin')).toContain(
'releases/download/v1.2.3/symfony_darwin_amd64'
);
expect(await tools.getSymfonyUri('latest', 'win32')).toContain(
'releases/latest/download/symfony_windows_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'win32')).toContain(
'releases/download/v1.2.3/symfony_windows_amd64'
);
expect(await tools.getSymfonyUri('1.2.3', 'openbsd')).toContain(
'Platform openbsd is not supported'
);
});
it('checking getCleanedToolsList', async () => {
const tools_list: string[] = await tools.getCleanedToolsList(
'tool, composer:1.2.3, robmorgan/phinx'
);
expect(tools_list).toStrictEqual(['composer:1.2.3', 'tool', 'phinx']);
});
it('checking addArchive', async () => {
let script: string = await tools.addArchive(
'tool',
'https://tool.com/tool.phar',
'linux'
);
expect(script).toContain('add_tool https://tool.com/tool.phar tool');
script = await tools.addArchive(
'tool',
'https://tool.com/tool.phar',
'darwin'
);
expect(script).toContain('add_tool https://tool.com/tool.phar tool');
script = await tools.addArchive(
'tool',
'https://tool.com/tool.phar',
'win32'
);
expect(script).toContain('Add-Tool https://tool.com/tool.phar tool');
script = await tools.addArchive(
'tool',
'https://tool.com/tool.phar',
'openbsd'
);
expect(script).toContain('Platform openbsd is not supported');
});
it('checking addDevTools', async () => {
let script: string = await tools.addDevTools('phpize', 'linux');
expect(script).toContain('add_devtools');
expect(script).toContain('add_log "$tick" "phpize" "Added"');
script = await tools.addDevTools('php-config', 'linux');
expect(script).toContain('add_devtools');
expect(script).toContain('add_log "$tick" "php-config" "Added"');
script = await tools.addDevTools('phpize', 'darwin');
expect(script).toContain('add_log "$tick" "phpize" "Added"');
script = await tools.addDevTools('php-config', 'darwin');
expect(script).toContain('add_log "$tick" "php-config" "Added"');
script = await tools.addDevTools('phpize', 'win32');
expect(script).toContain(
'Add-Log "$cross" "phpize" "phpize is not a windows tool"'
);
script = await tools.addDevTools('php-config', 'win32');
expect(script).toContain(
'Add-Log "$cross" "php-config" "php-config is not a windows tool"'
);
script = await tools.addDevTools('tool', 'openbsd');
expect(script).toContain('Platform openbsd is not supported');
});
it('checking addPackage', async () => {
let script: string = await tools.addPackage(
'tool',
'tool:1.2.3',
'user/',
'linux'
);
expect(script).toContain('add_composertool tool tool:1.2.3 user/');
script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'darwin');
expect(script).toContain('add_composertool tool tool:1.2.3 user/');
script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'win32');
expect(script).toContain('Add-Composertool tool tool:1.2.3 user/');
script = await tools.addPackage('tool', 'tool:1.2.3', 'user/', 'openbsd');
expect(script).toContain('Platform openbsd is not supported');
});
it('checking addTools on linux', async () => {
const script: string = await tools.addTools(
'cs2pr, php-cs-fixer, phpstan, phpunit, pecl, phinx, phinx:1.2.3, phive, php-config, phpize, symfony',
'7.4',
'linux'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer'
);
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
);
expect(script).toContain(
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar php-cs-fixer'
);
expect(script).toContain(
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar phpstan'
);
expect(script).toContain(
'add_tool https://phar.io/releases/phive.phar phive'
);
expect(script).toContain(
'add_tool https://phar.phpunit.de/phpunit.phar phpunit'
);
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/latest/download/symfony_linux_amd64 symfony'
);
expect(script).toContain('add_pecl');
expect(script).toContain('add_composertool phinx phinx robmorgan/');
expect(script).toContain('add_composertool phinx phinx:1.2.3 robmorgan/');
expect(script).toContain('add_devtools');
expect(script).toContain('add_log "$tick" "php-config" "Added"');
expect(script).toContain('add_log "$tick" "phpize" "Added"');
});
it('checking addTools on darwin', async () => {
const script: string = await tools.addTools(
'phpcs, phpcbf, phpcpd, phpmd, psalm, phinx, phive:1.2.3, cs2pr:1.2.3, phpize, php-config, symfony:1.2.3',
'7.4',
'darwin'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer'
);
expect(script).toContain(
'add_tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/download/1.2.3/cs2pr cs2pr'
);
expect(script).toContain(
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar phpcs'
);
expect(script).toContain(
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar phpcbf'
);
expect(script).toContain(
'add_tool https://phar.phpunit.de/phpcpd.phar phpcpd'
);
expect(script).toContain(
'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd'
);
expect(script).toContain(
'https://github.com/vimeo/psalm/releases/latest/download/psalm.phar psalm'
);
expect(script).toContain('add_composertool phinx phinx robmorgan/');
expect(script).toContain(
'add_tool https://github.com/phar-io/phive/releases/download/1.2.3/phive-1.2.3.phar phive'
);
expect(script).toContain(
'add_tool https://github.com/symfony/cli/releases/download/v1.2.3/symfony_darwin_amd64 symfony'
);
expect(script).toContain('add_log "$tick" "phpize" "Added"');
expect(script).toContain('add_log "$tick" "php-config" "Added"');
});
it('checking addTools on windows', async () => {
const script: string = await tools.addTools(
'cs2pr, deployer, phpmd, phinx, phive:0.13.2, php-config, phpize, symfony, does_not_exist, composer',
'7.4',
'win32'
);
expect(script).toContain(
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-stable.phar,https://getcomposer.org/composer-stable.phar composer'
);
expect(script).toContain(
'Add-Tool https://github.com/staabm/annotate-pull-request-from-checkstyle/releases/latest/download/cs2pr cs2pr'
);
expect(script).toContain(
'Add-Tool https://deployer.org/deployer.phar deployer'
);
expect(script).toContain(
'Add-Tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar phpmd'
);
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
expect(script).toContain(
'Add-Tool https://github.com/phar-io/phive/releases/download/0.13.2/phive-0.13.2.phar phive'
);
expect(script).toContain(
'Add-Tool https://github.com/symfony/cli/releases/latest/download/symfony_windows_amd64.exe symfony'
);
expect(script).toContain('phpize is not a windows tool');
expect(script).toContain('php-config is not a windows tool');
expect(script).toContain('Tool does_not_exist is not supported');
});
it('checking addTools with composer tool using user/tool as input', async () => {
const script: string = await tools.addTools(
'codeception/codeception, hirak/prestissimo, narrowspark/automatic-composer-prefetcher, robmorgan/phinx',
'7.4',
'win32'
);
expect(script).toContain(
'Add-Tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer'
);
expect(script).toContain('Add-Composertool prestissimo prestissimo hirak/');
expect(script).toContain('Add-Composertool phinx phinx robmorgan/');
expect(script).toContain(
'Add-Composertool composer-prefetcher composer-prefetcher narrowspark/automatic-'
);
});
it('checking composer setup', async () => {
let script: string = await tools.addTools(
'composer, composer:v1',
'7.4',
'linux'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-1.phar,https://getcomposer.org/composer-1.phar composer'
);
script = await tools.addTools('composer:preview', '7.4', 'linux');
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-preview.phar,https://getcomposer.org/composer-preview.phar composer'
);
script = await tools.addTools(
'composer:v1, composer:preview, composer:snapshot',
'7.4',
'linux'
);
expect(script).toContain(
'add_tool https://github.com/shivammathur/composer-cache/releases/latest/download/composer-7.4-snapshot.phar,https://getcomposer.org/composer.phar composer'
);
}); });
}); });

View File

@ -8,6 +8,10 @@ jest.mock('@actions/core', () => ({
}) })
})); }));
jest.spyOn(utils, 'fetch').mockImplementation(async (url): Promise<string> => {
return `{ "latest": "8.0", "5.x": "5.6", "url": "${url}" }`;
});
async function cleanup(path: string): Promise<void> { async function cleanup(path: string): Promise<void> {
fs.unlink(path, error => { fs.unlink(path, error => {
if (error) { if (error) {
@ -28,42 +32,21 @@ describe('Utils tests', () => {
}); });
it('checking getInput', async () => { it('checking getInput', async () => {
process.env['test'] = 'setup-php';
expect(await utils.getInput('test', false)).toBe('setup-php'); expect(await utils.getInput('test', false)).toBe('setup-php');
expect(await utils.getInput('setup-php', false)).toBe('setup-php'); expect(await utils.getInput('setup-php', false)).toBe('setup-php');
expect(await utils.getInput('DoesNotExist', false)).toBe(''); expect(await utils.getInput('DoesNotExist', false)).toBe('');
await expect(async () => { expect(async () => {
await utils.getInput('DoesNotExist', true); await utils.getInput('DoesNotExist', true);
}).rejects.toThrow('Input required and not supplied: DoesNotExist'); }).rejects.toThrow('Input required and not supplied: DoesNotExist');
}); });
it('checking fetch', async () => { it('checking fetch', async () => {
const manifest = await utils.getManifestURL(); expect(await utils.fetch('test_url')).toBe(
let response: Record<string, string> = await utils.fetch(manifest); '{ "latest": "8.0", "5.x": "5.6", "url": "test_url" }'
expect(response.error).toBe(undefined); );
expect(response.data).toContain('latest');
response = await utils.fetch(manifest, 'invalid_token');
expect(response.error).not.toBe(undefined);
expect(response.data).toBe(undefined);
});
it('checking getManifestURL', async () => {
expect(await utils.getManifestURL()).toContain('php-versions.json');
}); });
it('checking parseVersion', async () => { it('checking parseVersion', async () => {
jest
.spyOn(utils, 'fetch')
.mockImplementation(
async (url, token?): Promise<Record<string, string>> => {
if (!token || token === 'valid_token') {
return {data: `{ "latest": "8.0", "5.x": "5.6", "url": "${url}" }`};
} else {
return {error: 'Invalid token'};
}
}
);
expect(await utils.parseVersion('latest')).toBe('8.0'); expect(await utils.parseVersion('latest')).toBe('8.0');
expect(await utils.parseVersion('7')).toBe('7.0'); expect(await utils.parseVersion('7')).toBe('7.0');
expect(await utils.parseVersion('7.4')).toBe('7.4'); expect(await utils.parseVersion('7.4')).toBe('7.4');
@ -90,7 +73,7 @@ describe('Utils tests', () => {
expect(await utils.color('warning')).toBe('33'); expect(await utils.color('warning')).toBe('33');
}); });
it('checking readFile', async () => { it('checking readScripts', async () => {
const darwin: string = fs.readFileSync( const darwin: string = fs.readFileSync(
path.join(__dirname, '../src/scripts/darwin.sh'), path.join(__dirname, '../src/scripts/darwin.sh'),
'utf8' 'utf8'
@ -103,12 +86,12 @@ describe('Utils tests', () => {
path.join(__dirname, '../src/scripts/win32.ps1'), path.join(__dirname, '../src/scripts/win32.ps1'),
'utf8' 'utf8'
); );
expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin); expect(await utils.readScript('darwin.sh')).toBe(darwin);
expect(await utils.readFile('darwin.sh', 'src/scripts')).toBe(darwin); expect(await utils.readScript('darwin.sh')).toBe(darwin);
expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux); expect(await utils.readScript('linux.sh')).toBe(linux);
expect(await utils.readFile('linux.sh', 'src/scripts')).toBe(linux); expect(await utils.readScript('linux.sh')).toBe(linux);
expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32); expect(await utils.readScript('win32.ps1')).toBe(win32);
expect(await utils.readFile('win32.ps1', 'src/scripts')).toBe(win32); expect(await utils.readScript('win32.ps1')).toBe(win32);
}); });
it('checking writeScripts', async () => { it('checking writeScripts', async () => {
@ -116,12 +99,9 @@ describe('Utils tests', () => {
const runner_dir: string = process.env['RUNNER_TOOL_CACHE'] || ''; const runner_dir: string = process.env['RUNNER_TOOL_CACHE'] || '';
const script_path: string = path.join(runner_dir, 'test.sh'); const script_path: string = path.join(runner_dir, 'test.sh');
await utils.writeScript('test.sh', testString); await utils.writeScript('test.sh', testString);
await fs.readFile( fs.readFile(script_path, function (error: Error | null, data: Buffer) {
script_path, expect(testString).toBe(data.toString());
function (error: Error | null, data: Buffer) { });
expect(testString).toBe(data.toString());
}
);
await cleanup(script_path); await cleanup(script_path);
}); });
@ -154,9 +134,17 @@ describe('Utils tests', () => {
'b=3, 4', 'b=3, 4',
'c=5' 'c=5'
]); ]);
expect( expect(await utils.CSVArray('\'a=1,2\', "b=3, 4", c=5, d=~e~')).toEqual([
await utils.CSVArray('a=E_ALL, b=E_ALL & ~ E_ALL, c="E_ALL", d=\'E_ALL\'') 'a=1,2',
).toEqual(['a=E_ALL', 'b=E_ALL & ~ E_ALL', 'c=E_ALL', 'd=E_ALL']); 'b=3, 4',
'c=5',
"d='~e~'"
]);
expect(await utils.CSVArray('a=\'1,2\', b="3, 4", c=5')).toEqual([
'a=1,2',
'b=3, 4',
'c=5'
]);
expect(await utils.CSVArray('')).toEqual([]); expect(await utils.CSVArray('')).toEqual([]);
expect(await utils.CSVArray(' ')).toEqual([]); expect(await utils.CSVArray(' ')).toEqual([]);
}); });
@ -215,7 +203,6 @@ describe('Utils tests', () => {
); );
expect(await utils.getExtensionPrefix('xsl')).toEqual('extension'); expect(await utils.getExtensionPrefix('xsl')).toEqual('extension');
expect(await utils.getExtensionPrefix('xdebug')).toEqual('zend_extension'); expect(await utils.getExtensionPrefix('xdebug')).toEqual('zend_extension');
expect(await utils.getExtensionPrefix('xdebug3')).toEqual('zend_extension');
expect(await utils.getExtensionPrefix('opcache')).toEqual('zend_extension'); expect(await utils.getExtensionPrefix('opcache')).toEqual('zend_extension');
}); });
@ -227,81 +214,4 @@ describe('Utils tests', () => {
'Platform openbsd is not supported' 'Platform openbsd is not supported'
); );
}); });
it('checking getUnsupportedLog', async () => {
expect(await utils.getUnsupportedLog('ext', '5.6', 'linux')).toContain(
'add_log "$cross" "ext" "ext is not supported on PHP 5.6"'
);
});
it('checking getCommand', async () => {
expect(await utils.getCommand('linux', 'tool')).toBe('add_tool ');
expect(await utils.getCommand('darwin', 'tool')).toBe('add_tool ');
expect(await utils.getCommand('win32', 'tool')).toBe('Add-Tool ');
expect(await utils.getCommand('openbsd', 'tool')).toContain(
'Platform openbsd is not supported'
);
});
it('checking joins', async () => {
expect(await utils.joins('a', 'b', 'c')).toBe('a b c');
});
it('checking scriptExtension', async () => {
expect(await utils.scriptExtension('linux')).toBe('.sh');
expect(await utils.scriptExtension('darwin')).toBe('.sh');
expect(await utils.scriptExtension('win32')).toBe('.ps1');
expect(await utils.scriptExtension('openbsd')).toContain(
'Platform openbsd is not supported'
);
});
it('checking scriptTool', async () => {
expect(await utils.scriptTool('linux')).toBe('bash');
expect(await utils.scriptTool('darwin')).toBe('bash');
expect(await utils.scriptTool('win32')).toBe('pwsh');
expect(await utils.scriptTool('openbsd')).toContain(
'Platform openbsd is not supported'
);
});
it('checking customPackage', async () => {
const script_path: string = path.join('ext', 'pkg.sh');
expect(await utils.customPackage('pkg', 'ext', '1.2.3', 'linux')).toContain(
script_path + '\nadd_pkg 1.2.3'
);
expect(
await utils.customPackage('pdo_pkg', 'ext', '1.2.3', 'linux')
).toContain(script_path + '\nadd_pkg 1.2.3');
expect(
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@release',
'extension'
)
).toContain(
'\nadd_extension_from_source ext https://sub.domain.XN--tld org repo release extension'
);
});
}); });

View File

@ -7,7 +7,7 @@ branding:
inputs: inputs:
php-version: php-version:
description: 'Setup PHP version.' description: 'Setup PHP version.'
default: '8.0' default: '7.4'
required: true required: true
extensions: extensions:
description: 'Setup PHP extensions.' description: 'Setup PHP extensions.'
@ -21,9 +21,18 @@ inputs:
tools: tools:
description: 'Setup popular tools globally.' description: 'Setup popular tools globally.'
required: false required: false
outputs: extension-csv:
php-version: description: 'Deprecated! Use extensions instead.'
description: 'PHP version in semver format' deprecationMessage: 'The extension-csv property is deprecated. Use extensions instead.'
required: false
ini-values-csv:
description: 'Deprecated! Use ini-values instead.'
deprecationMessage: 'The ini-values-csv property is deprecated. Use ini-values instead.'
required: false
pecl:
description: 'Deprecated! Use tools instead to setup PECL.'
deprecationMessage: 'The pecl property is deprecated. Specify pecl in tools instead.'
required: false
runs: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

2157
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
- name: Get composer cache directory - name: Get composer cache directory

View File

@ -1,31 +0,0 @@
# GitHub Action for Blackfire Player
name: Play a Blackfire Scenario
on: [push, pull_request]
jobs:
blackfire-player:
name: Blackfire (PHP ${{ matrix.php-versions }})
# Add your Blackfire credentials securely using GitHub Secrets
env:
BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }}
BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }}
BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }}
BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }}
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['7.2', '7.3', '7.4']
# blackfire-player supports PHP >= 5.5
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: blackfire
tools: blackfire, blackfire-player #Setup Blackfire client, agent and player
coverage: none
- name: Play the scenario
run: blackfire-player run scenario.bkf # Refer to https://blackfire.io/docs/player/index#usage

View File

@ -1,31 +0,0 @@
# GitHub Action for Blackfire
name: Profiling with blackfire
on: [push, pull_request]
jobs:
blackfire:
name: Blackfire (PHP ${{ matrix.php-versions }})
# Add your Blackfire credentials securely using GitHub Secrets
env:
BLACKFIRE_SERVER_ID: ${{ secrets.BLACKFIRE_SERVER_ID }}
BLACKFIRE_SERVER_TOKEN: ${{ secrets.BLACKFIRE_SERVER_TOKEN }}
BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }}
BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }}
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
php-versions: ['7.2', '7.3', '7.4']
# Blackfire supports PHP >= 5.3 on ubuntu and macos and PHP >= 5.4 on windows
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extensions: blackfire
tools: blackfire #Setup Blackfire cli
coverage: none
- name: Profile
run: blackfire run php my-script.php # Refer to https://blackfire.io/docs/cookbooks/profiling-cli

View File

@ -27,7 +27,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
# You can also use ext-apcu or ext-memcached instead of ext-redis # You can also use ext-apcu or ext-memcached instead of ext-redis
@ -65,7 +65,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl
@ -92,7 +92,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl

View File

@ -27,7 +27,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
# You can also use ext-apcu or ext-memcached instead of ext-redis # You can also use ext-apcu or ext-memcached instead of ext-redis
@ -63,7 +63,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl
@ -90,7 +90,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl

View File

@ -13,7 +13,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, pdo_sqlite, pdo_mysql extensions: mbstring, intl, pdo_sqlite, pdo_mysql
@ -43,7 +43,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl
@ -70,7 +70,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v1
with: with:
php-version: '7.3' php-version: '7.3'
extensions: mbstring, intl extensions: mbstring, intl

View File

@ -12,7 +12,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, curl, dom extensions: mbstring, intl, curl, dom

View File

@ -36,7 +36,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql extensions: mbstring, dom, fileinfo, mysql

View File

@ -38,7 +38,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, pgsql extensions: mbstring, dom, fileinfo, pgsql

View File

@ -14,7 +14,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo extensions: mbstring, dom, fileinfo

View File

@ -36,7 +36,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql extensions: mbstring, dom, fileinfo, mysql

View File

@ -38,7 +38,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, pgsql extensions: mbstring, dom, fileinfo, pgsql

View File

@ -14,7 +14,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, fileinfo, mysql extensions: mbstring, dom, fileinfo, mysql

View File

@ -36,7 +36,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, zip, phalcon4, mysql #use phalcon3 for the phalcon 3.x. extensions: mbstring, dom, zip, phalcon4, mysql #use phalcon3 for the phalcon 3.x.

View File

@ -37,7 +37,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, dom, zip, phalcon4, pgsql #use phalcon3 for the phalcon 3.x extensions: mbstring, dom, zip, phalcon4, pgsql #use phalcon3 for the phalcon 3.x

View File

@ -18,7 +18,7 @@ jobs:
with: with:
node-version: ${{ matrix.node-versions }} node-version: ${{ matrix.node-versions }}
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring extensions: mbstring

View File

@ -12,7 +12,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, simplexml, dom extensions: mbstring, simplexml, dom

View File

@ -26,7 +26,6 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql
coverage: xdebug #optional coverage: xdebug #optional
- name: Start mysql service - name: Start mysql service
@ -43,15 +42,15 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer- restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies - name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader run: |
composer require --dev symfony/orm-pack symfony/phpunit-bridge
composer install --no-progress --prefer-dist --optimize-autoloader
php bin/phpunit install
- name: Run Migration - name: Run Migration
run: | run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed" php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed" php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env: env:
DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony DATABASE_URL: mysql://root:symfony@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/symfony
- name: Install PHPUnit - name: Run Tests
run: simple-phpunit install run: php bin/phpunit --coverage-text
- name: Run tests
run: simple-phpunit --coverage-text

View File

@ -26,7 +26,6 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pgsql extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pgsql
coverage: xdebug #optional coverage: xdebug #optional
- name: Get composer cache directory - name: Get composer cache directory
@ -41,15 +40,15 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer- restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies - name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader run: |
composer require --dev symfony/orm-pack symfony/phpunit-bridge
composer install --no-progress --prefer-dist --optimize-autoloader
php bin/phpunit install
- name: Run Migration - name: Run Migration
run: | run: |
composer require --dev symfony/orm-pack
php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed" php bin/console doctrine:schema:update --force || echo "No migrations found or schema update failed"
php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed" php bin/console doctrine:migrations:migrate || echo "No migrations found or migration failed"
env: env:
DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?charset=UTF-8 DATABASE_URL: postgres://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?charset=UTF-8
- name: Install PHPUnit - name: Run Tests
run: simple-phpunit install run: php bin/phpunit --coverage-text
- name: Run tests
run: simple-phpunit --coverage-text

View File

@ -17,7 +17,6 @@ jobs:
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
tools: phpunit-bridge
extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite
coverage: xdebug #optional coverage: xdebug #optional
- name: Get composer cache directory - name: Get composer cache directory
@ -32,8 +31,9 @@ jobs:
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer- restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies - name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader run: |
- name: Install PHPUnit composer require --dev symfony/phpunit-bridge
run: simple-phpunit install composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run tests php bin/phpunit install
run: simple-phpunit --coverage-text - name: Run Tests
run: php bin/phpunit --coverage-text

View File

@ -33,7 +33,7 @@ jobs:
with: with:
node-version: 10.x node-version: 10.x
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, gd, imagick, zip, dom, mysql extensions: mbstring, intl, gd, imagick, zip, dom, mysql

View File

@ -33,7 +33,7 @@ jobs:
with: with:
node-version: 10.x node-version: 10.x
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, gd, imagick, zip, dom, pgsql extensions: mbstring, intl, gd, imagick, zip, dom, pgsql

View File

@ -12,7 +12,7 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions - name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php uses: shivammathur/setup-php@v1 #https://github.com/shivammathur/setup-php
with: with:
php-version: ${{ matrix.php-versions }} php-version: ${{ matrix.php-versions }}
extensions: mbstring, bcmath, curl, intl extensions: mbstring, bcmath, curl, intl

5239
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,24 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "2.13.0", "version": "1.11.7",
"private": false, "private": false,
"description": "Setup PHP for use with GitHub Actions", "description": "Setup PHP for use with GitHub Actions",
"main": "lib/install.js", "main": "lib/install.js",
"types": "lib/install.d.ts",
"directories": {
"lib": "lib",
"test": "__tests__",
"src": "src"
},
"files": [
"lib",
"src"
],
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
"lint": "eslint **/*.ts --cache --fix", "lint": "eslint **/src/*.ts --cache --fix",
"format": "prettier --write **/*.ts && git add .", "format": "prettier --write **/src/*.ts && git add .",
"format-check": "prettier --check **/*.ts", "format-check": "prettier --check **/src/*.ts",
"release": "ncc build -o dist && git add -f dist/", "release": "ncc build -o dist && git add -f dist/",
"test": "jest" "test": "jest"
}, },
@ -24,33 +34,33 @@
"author": "shivammathur", "author": "shivammathur",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.5.0", "@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0", "@actions/exec": "^1.1.1",
"@actions/io": "^1.1.1", "@actions/io": "^1.1.2",
"fs": "0.0.1-security" "fs": "0.0.1-security"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.1", "@types/jest": "^27.4.1",
"@types/node": "^16.7.1", "@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^4.29.2", "@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^4.29.2", "@typescript-eslint/parser": "^5.18.0",
"@vercel/ncc": "^0.29.2", "@vercel/ncc": "^0.33.3",
"eslint": "^7.32.0", "eslint": "^8.13.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.24.1", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^24.4.0", "eslint-plugin-jest": "^26.1.4",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^4.0.0",
"husky": "^4.3.8", "jest": "^27.5.1",
"jest": "^27.0.6", "jest-circus": "^27.5.1",
"jest-circus": "^27.0.6", "prettier": "^2.6.2",
"prettier": "^2.3.2", "simple-git-hooks": "^2.7.0",
"ts-jest": "^27.0.5", "ts-jest": "^27.1.4",
"typescript": "^4.3.5" "typescript": "^4.6.3"
}, },
"husky": { "bugs": {
"skipCI": true, "url": "https://github.com/shivammathur/setup-php/issues"
"hooks": { },
"pre-commit": "npm run format && npm run lint && npm run test && npm run build && npm run release" "simple-git-hooks": {
} "pre-commit": "npm run format && npm run lint && npm run test && npm run build && npm run release"
} }
} }

View File

@ -9,16 +9,13 @@ export async function addINIValuesUnix(
ini_values_csv: string ini_values_csv: string
): Promise<string> { ): Promise<string> {
const ini_values: Array<string> = await utils.CSVArray(ini_values_csv); const ini_values: Array<string> = await utils.CSVArray(ini_values_csv);
let script = ''; let script = '\n';
await utils.asyncForEach(ini_values, async function (line: string) { await utils.asyncForEach(ini_values, async function (line: string) {
script += script +=
'\n' + (await utils.addLog('$tick', line, 'Added to php.ini', 'linux')); (await utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n';
}); });
return ( return (
'echo "' + 'echo "' + ini_values.join('\n') + '" >> ${pecl_file:-$ini_file}' + script
ini_values.join('\n') +
'" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null 2>&1' +
script
); );
} }
@ -37,7 +34,10 @@ export async function addINIValuesWindows(
(await utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n'; (await utils.addLog('$tick', line, 'Added to php.ini', 'win32')) + '\n';
}); });
return ( return (
'Add-Content "$php_dir\\php.ini" "' + ini_values.join('\n') + '"' + script 'Add-Content C:\\tools\\php\\php.ini "' +
ini_values.join('\n') +
'"' +
script
); );
} }

View File

@ -0,0 +1,28 @@
amqp=amqp
apcu=apcu
expect=expect
grpc=grpc
igbinary=igbinary
imagick=imagick
imap=imap
memcache=memcache
memcached=memcached
mongodb=mongodb
msgpack=msgpack
pcov=pcov
pecl_http=http
phalcon3=phalcon
phalcon4=phalcon
propro=propro
protobuf=protobuf
psr=psr
raphf=raphf
rdkafka=rdkafka
redis=redis
ssh2=ssh2
swoole=swoole
vips=vips
xdebug=xdebug
xdebug2=xdebug
yaml=yaml
zmq=zmq

View File

@ -1,17 +0,0 @@
8,jessie
9,stretch
10,buster
11,bullseye
12,bookworm
16.04 LTS,xenial
16.10,yakkety
17.04,zesty
17.10,artful
18.04 LTS,bionic
18.10,cosmic
19.04,disco
19.10,eoan
20.04 LTS,focal
20.10,groovy
21.04,hirsute
21.10,impish
1 8 jessie
2 9 stretch
3 10 buster
4 11 bullseye
5 12 bookworm
6 16.04 LTS xenial
7 16.10 yakkety
8 17.04 zesty
9 17.10 artful
10 18.04 LTS bionic
11 18.10 cosmic
12 19.04 disco
13 19.10 eoan
14 20.04 LTS focal
15 20.10 groovy
16 21.04 hirsute
17 21.10 impish

View File

@ -1,29 +0,0 @@
{
"problemMatcher": [
{
"owner": "php_native_error",
"severity": "error",
"pattern": [
{
"regexp": "^(.*error):\\s+\\s+(.+) in (.+) on line (\\d+)$",
"code": 1,
"message": 2,
"file": 3,
"line": 4
}
]
}, {
"owner": "php_native_warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.*Warning|.*Deprecated|.*Notice):\\s+\\s+(.+) in (.+) on line (\\d+)$",
"code": 1,
"message": 2,
"file": 3,
"line": 4
}
]
}
]
}

View File

@ -1,236 +0,0 @@
{
"composer-normalize": {
"type": "phar",
"repository": "ergebnis/composer-normalize",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"cs2pr": {
"type": "phar",
"repository": "staabm/annotate-pull-request-from-checkstyle",
"extension": "",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"infection": {
"type": "phar",
"repository": "infection/infection",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"phan": {
"type": "phar",
"repository": "phan/phan",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-v"
},
"php-cs-fixer": {
"type": "phar",
"repository": "FriendsOfPHP/PHP-CS-Fixer",
"extension": ".phar",
"domain": "https://github.com",
"fetch_latest": "true",
"version_prefix": "v",
"version_parameter": "-V"
},
"phpcbf": {
"type": "phar",
"repository": "squizlabs/PHP_CodeSniffer",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "--version"
},
"phpcs": {
"type": "phar",
"repository": "squizlabs/PHP_CodeSniffer",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "--version"
},
"phpmd": {
"type": "phar",
"repository": "phpmd/phpmd",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "--version"
},
"phpstan": {
"type": "phar",
"repository": "phpstan/phpstan",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-V"
},
"psalm": {
"type": "phar",
"repository": "vimeo/psalm",
"extension": ".phar",
"domain": "https://github.com",
"version_prefix": "",
"version_parameter": "-v"
},
"behat": {
"type": "composer",
"repository": "behat/behat"
},
"codeception": {
"type": "composer",
"repository": "codeception/codeception"
},
"automatic-composer-prefetcher": {
"type": "composer",
"alias": "composer-prefetcher",
"repository": "narrowspark/automatic-composer-prefetcher"
},
"composer-require-checker": {
"type": "composer",
"repository": "maglnet/composer-require-checker"
},
"composer-unused": {
"type": "composer",
"repository": "icanhazstring/composer-unused"
},
"flex": {
"type": "composer",
"repository": "symfony/flex"
},
"phinx": {
"type": "composer",
"repository": "robmorgan/phinx"
},
"phplint": {
"type": "composer",
"repository": "overtrue/phplint"
},
"phpspec": {
"type": "composer",
"repository": "phpspec/phpspec"
},
"phpunit-bridge": {
"alias": "simple-phpunit",
"type": "composer",
"repository": "symfony/phpunit-bridge"
},
"prestissimo": {
"type": "composer",
"repository": "hirak/prestissimo"
},
"vapor-cli": {
"type": "composer",
"alias": "vapor",
"repository": "laravel/vapor-cli"
},
"blackfire": {
"type": "custom-package",
"alias": "blackfire-agent"
},
"grpc_php_plugin": {
"type": "custom-package",
"repository": "grpc/grpc",
"domain": "https://github.com",
"version_prefix": "v"
},
"protoc": {
"type": "custom-package",
"repository": "protocolbuffers/protobuf",
"domain": "https://github.com",
"version_prefix": "v"
},
"blackfire-player": {
"type": "custom-function",
"domain": "https://get.blackfire.io",
"function": "blackfire_player",
"version_prefix": "v",
"version_parameter": "-V"
},
"composer": {
"type": "custom-function",
"domain": "https://getcomposer.org",
"repository": "composer/composer",
"function": "composer"
},
"deployer": {
"type": "custom-function",
"domain": "https://deployer.org",
"repository": "deployphp/deployer",
"function": "deployer",
"version_prefix": "v",
"version_parameter": "-V"
},
"pecl": {
"type": "custom-function",
"function": "pecl"
},
"phing": {
"type": "custom-function",
"domain": "https://www.phing.info",
"repository": "phingofficial/phing",
"function": "phing",
"extension": ".phar",
"version_prefix": "",
"version_parameter": "-v"
},
"phive": {
"type": "custom-function",
"repository": "phar-io/phive",
"domain": "https://phar.io",
"function": "phive",
"version_prefix": "",
"version_parameter": "status"
},
"phpcpd": {
"type": "custom-function",
"repository": "sebastianbergmann/phpcpd",
"domain": "https://phar.phpunit.de",
"function": "phpcpd",
"version_prefix": "",
"version_parameter": "--version"
},
"phpunit": {
"type": "custom-function",
"repository": "sebastianbergmann/phpunit",
"domain": "https://phar.phpunit.de",
"function": "phpcpd",
"version_prefix": "",
"version_parameter": "--version"
},
"phpize": {
"type": "custom-function",
"function": "dev_tools",
"alias": "php-config"
},
"php-config": {
"type": "custom-function",
"function": "dev_tools"
},
"symfony-cli": {
"type": "custom-function",
"function": "symfony",
"alias": "symfony",
"domain": "https://github.com",
"repository": "symfony/cli",
"version_prefix": "v",
"version_parameter": "version"
},
"wp-cli": {
"type": "custom-function",
"function": "wp_cli",
"repository": "wp-cli/wp-cli",
"domain": "https://github.com",
"alias": "wp",
"extension": ".phar",
"version_parameter": "--version",
"version_prefix": "v"
}
}

View File

@ -1,115 +0,0 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/tools_schema.json",
"type": "object",
"title": "Tools",
"default": {},
"examples": [
{
"tool": {
"alias": "tool_alias",
"domain": "https://example.com",
"extension": ".ext",
"fetch_latest": "true",
"function": "function_name",
"repository": "user/tool",
"type": "phar, composer, custom-package or custom-function",
"version_parameter": "--version",
"version_prefix": "v"
}
}
],
"items": {
"properties": {
"alias": {
"$id": "#/items/properties/alias",
"type": "string",
"title": "The alias schema",
"description": "Alias for a tool.",
"examples": [
"tool_alias"
]
},
"domain": {
"$id": "#/items/properties/domain",
"type": "string",
"title": "The domain schema",
"description": "Domain URL of the tool.",
"examples": [
"https://example.com"
]
},
"extension": {
"$id": "#/items/properties/extension",
"type": "string",
"title": "The extension schema",
"description": "File extension of the tool.",
"examples": [
".ext"
]
},
"fetch_latest": {
"$id": "#/items/properties/fetch_latest",
"type": "string",
"title": "The fetch_latest schema",
"description": "Fetch the latest version from GitHub releases.",
"enum": [
"true",
"false"
]
},
"function": {
"$id": "#/items/properties/function",
"type": "string",
"title": "The function schema",
"description": "Function name in tools.ts which returns the script to setup the tool.",
"examples": [
"function_name"
]
},
"repository": {
"$id": "#/items/properties/repository",
"type": "string",
"title": "The repository schema",
"description": "GitHub repository of the tool.",
"examples": [
"user/tool"
]
},
"type": {
"$id": "#/items/properties/type",
"type": "string",
"title": "The type schema",
"description": "Type of tool: phar, composer, custom-package or custom-function.",
"enum": [
"phar",
"composer",
"custom-package",
"custom-function"
]
},
"version_parameter": {
"$id": "#/items/properties/version_parameter",
"type": "string",
"title": "The version_parameter schema",
"description": "Parameter to get the tool version.",
"examples": [
"--version"
]
},
"version_prefix": {
"$id": "#/items/properties/version_prefix",
"type": "string",
"title": "The version_prefix schema",
"description": "Prefix of the version in the download URL.",
"examples": [
"v"
]
}
},
"required": [
"type"
],
"additionalProperties": true
}
}

View File

@ -2,33 +2,22 @@ import * as utils from './utils';
import * as extensions from './extensions'; import * as extensions from './extensions';
import * as config from './config'; import * as config from './config';
/**
* Function to setup Xdebug
*
* @param extension
* @param version
* @param os_version
* @param pipe
*/
export async function addCoverageXdebug( export async function addCoverageXdebug(
extension: string, extension: string,
version: string, version: string,
os_version: string, os_version: string,
pipe: string pipe: string
): Promise<string> { ): Promise<string> {
let script = '\n'; const xdebug =
script +=
(await extensions.addExtension(':pcov', version, os_version, true)) + pipe;
script +=
(await extensions.addExtension(extension, version, os_version, true)) + (await extensions.addExtension(extension, version, os_version, true)) +
pipe; pipe;
script += await utils.addLog( const log = await utils.addLog(
'$tick', '$tick',
extension, extension,
'Xdebug enabled as coverage driver', 'Xdebug enabled as coverage driver',
os_version os_version
); );
return script; return xdebug + '\n' + log;
} }
/** /**
@ -44,17 +33,26 @@ export async function addCoveragePCOV(
pipe: string pipe: string
): Promise<string> { ): Promise<string> {
let script = '\n'; let script = '\n';
switch (true) { switch (version) {
default: default:
script +=
(await extensions.addExtension(':xdebug', version, os_version, true)) +
pipe;
script += script +=
(await extensions.addExtension('pcov', version, os_version, true)) + (await extensions.addExtension('pcov', version, os_version, true)) +
pipe; pipe +
'\n';
script += script +=
(await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n'; (await config.addINIValues('pcov.enabled=1', os_version, true)) + '\n';
// add command to disable xdebug and enable pcov
switch (os_version) {
case 'linux':
case 'darwin':
script += 'remove_extension xdebug' + pipe + '\n';
break;
case 'win32':
script += 'Remove-Extension xdebug' + pipe + '\n';
break;
}
// success // success
script += await utils.addLog( script += await utils.addLog(
'$tick', '$tick',
@ -64,8 +62,8 @@ export async function addCoveragePCOV(
); );
// version is not supported // version is not supported
break; break;
case '5.6':
case /5\.[3-6]|7\.0/.test(version): case '7.0':
script += await utils.addLog( script += await utils.addLog(
'$cross', '$cross',
'pcov', 'pcov',
@ -91,11 +89,17 @@ export async function disableCoverage(
pipe: string pipe: string
): Promise<string> { ): Promise<string> {
let script = '\n'; let script = '\n';
script += switch (os_version) {
(await extensions.addExtension(':pcov', version, os_version, true)) + pipe; case 'linux':
script += case 'darwin':
(await extensions.addExtension(':xdebug', version, os_version, true)) + script += 'remove_extension xdebug' + pipe + '\n';
pipe; script += 'remove_extension pcov' + pipe + '\n';
break;
case 'win32':
script += 'Remove-Extension xdebug' + pipe + '\n';
script += 'Remove-Extension pcov' + pipe + '\n';
break;
}
script += await utils.addLog( script += await utils.addLog(
'$tick', '$tick',
'none', 'none',
@ -121,7 +125,7 @@ export async function addCoverage(
coverage_driver = coverage_driver.toLowerCase(); coverage_driver = coverage_driver.toLowerCase();
const script: string = const script: string =
'\n' + (await utils.stepLog('Setup Coverage', os_version)); '\n' + (await utils.stepLog('Setup Coverage', os_version));
const pipe: string = (await utils.suppressOutput(os_version)) + '\n'; const pipe: string = await utils.suppressOutput(os_version);
switch (coverage_driver) { switch (coverage_driver) {
case 'pcov': case 'pcov':
return script + (await addCoveragePCOV(version, os_version, pipe)); return script + (await addCoveragePCOV(version, os_version, pipe));

View File

@ -1,3 +1,4 @@
import * as path from 'path';
import * as utils from './utils'; import * as utils from './utils';
/** /**
@ -11,88 +12,55 @@ export async function addExtensionDarwin(
version: string version: string
): Promise<string> { ): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let add_script = '\n'; let script = '\n';
let remove_script = '';
await utils.asyncForEach(extensions, async function (extension: string) { await utils.asyncForEach(extensions, async function (extension: string) {
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-'); const [extension_name, stability]: string[] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name); const ext_prefix = await utils.getExtensionPrefix(extension_name);
const command_prefix = 'pecl_install ';
let command = '';
switch (true) { switch (true) {
// match :extension // match pre-release versions
case /^:/.test(ext_name): case /.+-(beta|alpha|devel|snapshot)/.test(extension):
remove_script += '\nremove_extension ' + ext_name.slice(1); script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
ext_prefix;
return; return;
// match extensions for compiling from source // match 5.6 to 8.0 amqp, expect, grpc, igbinary, imagick, imap, mongodb, msgpack, pecl_http, propro, protobuf, raphf, rdkafka, redis, ssh2, swoole, xdebug, xdebug2, yaml, zmq
case /.+-.+\/.+@.+/.test(extension): // match 7.1pcov to 8.0pcov
add_script += await utils.parseExtensionSource(extension, ext_prefix); // match 7.0vips to 8.0vips
return; case /(5\.6|7\.[0-4]|8.0)(amqp|expect|grpc|igbinary|imagick|imap|mcrypt|mongodb|msgpack|^(pecl_)?http$|propro|protobuf|psr|raphf|rdkafka|redis|ssh2|swoole|xdebug|xdebug2|yaml|zmq)/.test(
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
// match couchbase, geos, pdo_oci, oci8, http, pecl_http
// match 5.3ioncube...7.4ioncube
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(
version_extension version_extension
): ):
case /^couchbase$|^geos$|^pdo_oci$|^oci8$|^(pecl_)?http|^pdo_firebird$/.test( case /(7\.[1-4]|8\.0])pcov/.test(version_extension):
extension case /^(5\.6|7\.[0-3])phalcon3$|^7\.[2-4]phalcon4$/.test(
):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
add_script += await utils.customPackage(
ext_name,
'ext',
extension,
'darwin'
);
return;
// match pre-release versions. For example - xdebug-beta
case /.+-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(extension):
add_script += await utils.joins(
'\nadd_unstable_extension',
ext_name,
ext_version,
ext_prefix
);
return;
// match semver
case /.+-\d+\.\d+\.\d+.*/.test(extension):
add_script += await utils.joins(
'\nadd_pecl_extension',
ext_name,
ext_version,
ext_prefix
);
return;
// match 5.3pcov to 7.0pcov
case /(5\.[3-6]|7\.0)pcov/.test(version_extension):
add_script += await utils.getUnsupportedLog('pcov', version, 'darwin');
return;
// match 5.6 and newer - amqp, apcu, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, protobuf, raphf, rdkafka, redis, swoole, xdebug, xdebug2, yaml, zmq
// match 7.1 and newer - pcov
// match 5.6 to 7.4 - propro
case /(?<!5\.[3-5])(amqp|apcu|grpc|igbinary|imagick|imap|memcache|memcached|mongodb|msgpack|protobuf|psr|raphf|rdkafka|redis|swoole|xdebug|xdebug2|yaml|zmq)/.test(
version_extension version_extension
): ):
case /(5\.6|7\.[0-4])propro/.test(version_extension): case /(7\.[0-4]|8\.0])vips/.test(version_extension):
case /(?<!5\.[3-6]|7\.0)pcov/.test(version_extension): command = 'add_brew_extension ' + extension_name.replace('pecl_', '');
case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4/.test(version_extension): break;
add_script += await utils.joins(
'\nadd_brew_extension',
ext_name,
ext_prefix
);
return;
// match sqlite // match sqlite
case /^sqlite$/.test(extension): case /^sqlite$/.test(extension):
extension = 'sqlite3'; extension = 'sqlite3';
command = command_prefix + extension;
break; break;
default: default:
command = command_prefix + extension;
break; break;
} }
add_script += await utils.joins('\nadd_extension', extension, ext_prefix); script +=
'\nadd_extension ' +
extension +
' "' +
command +
'" ' +
(await utils.getExtensionPrefix(extension));
}); });
return add_script + remove_script; return script;
} }
/** /**
@ -106,104 +74,52 @@ export async function addExtensionWindows(
version: string version: string
): Promise<string> { ): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let add_script = '\n'; let script = '\n';
let remove_script = '';
await utils.asyncForEach(extensions, async function (extension: string) { await utils.asyncForEach(extensions, async function (extension: string) {
const [ext_name, ext_version]: string[] = extension.split('-'); const [extension_name, stability]: string[] = extension.split('-');
const version_extension: string = version + extension; const version_extension: string = version + extension;
let matches: RegExpExecArray;
switch (true) { switch (true) {
// Match :extension // match pre-release versions
case /^:/.test(ext_name): case /.+-(beta|alpha|devel|snapshot)/.test(extension):
remove_script += '\nRemove-Extension ' + ext_name.slice(1); script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break; break;
// match 5.3blackfire...8.0blackfire // match 5.6mysql, 5.6mysqli, 5.6mysqlnd
// match 5.3blackfire-(semver)...8.0blackfire-(semver) case /^5\.6(mysql|mysqli|mysqlnd)$/.test(version_extension):
// match pdo_oci and oci8 script +=
// match 5.3ioncube...7.4ioncube '\nAdd-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
// match 7.1pecl_http...8.0pecl_http and 7.1http...8.0http
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(
version_extension
):
case /^pdo_oci$|^oci8$|^pdo_firebird$/.test(extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
case /^(7\.[1-4]|8\.0)(pecl_)?http/.test(version_extension):
add_script += await utils.customPackage(
ext_name,
'ext',
extension,
'win32'
);
return;
// match pre-release versions. For example - xdebug-beta
case /.+-(stable|beta|alpha|devel|snapshot)/.test(extension):
add_script += await utils.joins(
'\nAdd-Extension',
ext_name,
ext_version.replace('stable', '')
);
break;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.getUnsupportedLog(
extension,
version,
'win32'
);
break;
// match semver without state
case /.+-\d+\.\d+\.\d+$/.test(extension):
add_script += await utils.joins(
'\nAdd-Extension',
ext_name,
'stable',
ext_version
);
break;
// match semver with state
case /.+-\d+\.\d+\.\d+[a-zA-Z]+\d*/.test(extension):
matches = /.+-(\d+\.\d+\.\d+)([a-zA-Z]+)\d*/.exec(
version_extension
) as RegExpExecArray;
add_script += await utils.joins(
'\nAdd-Extension',
ext_name,
matches[2].replace('preview', 'devel'),
matches[1]
);
break; break;
// match 7.2xdebug2 to 7.4xdebug2 // match 7.2xdebug2 to 7.4xdebug2
case /7\.[2-4]xdebug2/.test(version_extension): case /7\.[2-4]xdebug2/.test(version_extension):
add_script += '\nAdd-Extension xdebug stable 2.9.8'; script += '\nAdd-Extension xdebug stable 2.9.8';
break; break;
// match 5.3pcov to 7.0pcov // match 7.0mysql..8.0mysql
case /(5\.[3-6]|7\.0)pcov/.test(version_extension): // match 7.0mysqli..8.0mysqli
add_script += await utils.getUnsupportedLog('pcov', version, 'win32'); // match 7.0mysqlnd..8.0mysqlnd
break; case /[7-8]\.\d(mysql|mysqli|mysqlnd)$/.test(version_extension):
// match 5.3 to 5.6 - mysql, mysqli, mysqlnd script += '\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
case /^5\.[3-6](?<!pdo_)(mysql|mysqli|mysqlnd)$/.test(version_extension):
add_script +=
'\nAdd-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
break;
// match 7.0 and newer mysql, mysqli and mysqlnd
case /(?<!5\.[3-6])(?<!pdo_)(mysql|mysqli|mysqlnd)$/.test(
version_extension
):
add_script += '\nAdd-Extension mysqli\nAdd-Extension mysqlnd';
break; break;
// match sqlite // match sqlite
case /^sqlite$/.test(extension): case /^sqlite$/.test(extension):
extension = 'sqlite3'; extension = 'sqlite3';
add_script += await utils.joins('\nAdd-Extension', extension); script += '\nAdd-Extension ' + extension;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
'\n& ' +
path.join(__dirname, '../src/scripts/ext/phalcon.ps1') +
' ' +
extension +
' ' +
version +
'\n';
break; break;
default: default:
add_script += '\nAdd-Extension ' + extension; script += '\nAdd-Extension ' + extension;
break; break;
} }
}); });
return add_script + remove_script; return script;
} }
/** /**
@ -211,99 +127,69 @@ export async function addExtensionWindows(
* *
* @param extension_csv * @param extension_csv
* @param version * @param version
* @param pipe
*/ */
export async function addExtensionLinux( export async function addExtensionLinux(
extension_csv: string, extension_csv: string,
version: string version: string,
pipe: string
): Promise<string> { ): Promise<string> {
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let add_script = '\n'; let script = '\n';
let remove_script = '';
await utils.asyncForEach(extensions, async function (extension: string) { await utils.asyncForEach(extensions, async function (extension: string) {
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [ext_name, ext_version]: string[] = extension.split('-'); const [extension_name, stability]: string[] = extension.split('-');
const ext_prefix = await utils.getExtensionPrefix(ext_name); const ext_prefix = await utils.getExtensionPrefix(extension_name);
const command_prefix = 'sudo $debconf_fix apt-get install -y php';
let command = '';
switch (true) { switch (true) {
// Match :extension // match pre-release versions
case /^:/.test(ext_name): case /.+-(beta|alpha|devel|snapshot)/.test(extension):
remove_script += '\nremove_extension ' + ext_name.slice(1); script +=
'\nadd_unstable_extension ' +
extension_name +
' ' +
stability +
' ' +
ext_prefix;
return; return;
// match extensions for compiling from source // match 5.6gearman..7.4gearman
case /.+-.+\/.+@.+/.test(extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix); script +=
'\n. ' + path.join(__dirname, '../src/scripts/ext/gearman.sh');
return; return;
// match 5.3blackfire...8.0blackfire // match 7.0phalcon3...7.3phalcon3 or 7.2phalcon4...7.4phalcon4
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
// match 5.3pdo_cubrid...7.2php_cubrid, 5.3cubrid...7.4cubrid
// match couchbase, geos, pdo_oci, oci8, http, pecl_http
// match 5.3ioncube...7.4ioncube
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(
version_extension
):
case /^((5\.[3-6])|(7\.[0-2]))pdo_cubrid$|^((5\.[3-6])|(7\.[0-4]))cubrid$/.test(
version_extension
):
case /^couchbase$|^gearman$|^geos$|^pdo_oci$|^oci8$|^(pecl_)?http|^pdo_firebird$/.test(
extension
):
case /(?<!5\.[3-5])intl-[\d]+\.[\d]+$/.test(version_extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
add_script += await utils.customPackage( script +=
ext_name, '\nbash ' +
'ext', path.join(__dirname, '../src/scripts/ext/phalcon.sh') +
extension, ' ' +
'linux' extension +
); ' ' +
version;
return; return;
// match pre-release versions. For example - xdebug-beta // match 7.2xdebug2 to 7.4xdebug2
case /.+-(stable|beta|alpha|devel|snapshot|rc|preview)/.test(extension):
add_script += await utils.joins(
'\nadd_unstable_extension',
ext_name,
ext_version,
ext_prefix
);
return;
// match semver versions
case /.+-\d+\.\d+\.\d+.*/.test(extension):
add_script += await utils.joins(
'\nadd_pecl_extension',
ext_name,
ext_version,
ext_prefix
);
return;
// match 5.3pcov to 7.0pcov
case /(5\.[3-6]|7\.0)pcov/.test(version_extension):
add_script += await utils.getUnsupportedLog('pcov', version, 'linux');
return;
// match 7.2xdebug2...7.4xdebug2
case /^7\.[2-4]xdebug2$/.test(version_extension): case /^7\.[2-4]xdebug2$/.test(version_extension):
add_script += await utils.joins( script += '\nadd_pecl_extension xdebug 2.9.8 ' + ext_prefix;
'\nadd_pecl_extension',
'xdebug',
'2.9.8',
ext_prefix
);
return;
// match pdo extensions
case /^pdo[_-].+/.test(extension):
extension = extension.replace(/pdo[_-]|3/, '');
add_script += '\nadd_pdo_extension ' + extension;
return; return;
// match sqlite // match sqlite
case /^sqlite$/.test(extension): case /^sqlite$/.test(extension):
extension = 'sqlite3'; extension = 'sqlite3';
command = command_prefix + version + '-' + extension + pipe;
break; break;
default: default:
command =
command_prefix +
version +
'-' +
extension.replace('pdo_', '').replace('pdo-', '') +
pipe;
break; break;
} }
add_script += await utils.joins('\nadd_extension', extension, ext_prefix); script +=
'\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix;
}); });
return add_script + remove_script; return script;
} }
/** /**
@ -320,15 +206,15 @@ export async function addExtension(
os_version: string, os_version: string,
no_step = false no_step = false
): Promise<string> { ): Promise<string> {
const log: string = await utils.stepLog('Setup Extensions', os_version); const pipe: string = await utils.suppressOutput(os_version);
let script = '\n'; let script = '\n';
switch (no_step) { switch (no_step) {
case true: case true:
script += log + (await utils.suppressOutput(os_version)); script += (await utils.stepLog('Setup Extensions', os_version)) + pipe;
break; break;
case false: case false:
default: default:
script += log; script += await utils.stepLog('Setup Extensions', os_version);
break; break;
} }
@ -338,7 +224,7 @@ export async function addExtension(
case 'darwin': case 'darwin':
return script + (await addExtensionDarwin(extension_csv, version)); return script + (await addExtensionDarwin(extension_csv, version));
case 'linux': case 'linux':
return script + (await addExtensionLinux(extension_csv, version)); return script + (await addExtensionLinux(extension_csv, version, pipe));
default: default:
return await utils.log( return await utils.log(
'Platform ' + os_version + ' is not supported', 'Platform ' + os_version + ' is not supported',

View File

@ -13,21 +13,25 @@ import * as utils from './utils';
* @param version * @param version
* @param os_version * @param os_version
*/ */
export async function getScript( export async function build(
filename: string, filename: string,
version: string, version: string,
os_version: string os_version: string
): Promise<string> { ): Promise<string> {
// taking inputs
const name = 'setup-php'; const name = 'setup-php';
const url = 'https://setup-php.com/support'; const url = 'https://setup-php.com/support';
// taking inputs const extension_csv: string =
process.env['fail_fast'] = await utils.getInput('fail-fast', false); (await utils.getInput('extensions', false)) ||
const extension_csv: string = await utils.getInput('extensions', false); (await utils.getInput('extension', false)) ||
const ini_values_csv: string = await utils.getInput('ini-values', false); (await utils.getInput('extension-csv', false));
const ini_values_csv: string =
(await utils.getInput('ini-values', false)) ||
(await utils.getInput('ini-values-csv', false));
const coverage_driver: string = await utils.getInput('coverage', false); const coverage_driver: string = await utils.getInput('coverage', false);
const tools_csv: string = await utils.getInput('tools', false); const tools_csv: string = await utils.getInput('tools', false);
let script: string = await utils.readFile(filename, 'src/scripts'); let script: string = await utils.readScript(filename);
script += await tools.addTools(tools_csv, version, os_version); script += await tools.addTools(tools_csv, version, os_version);
if (extension_csv) { if (extension_csv) {
@ -57,20 +61,38 @@ export async function run(): Promise<void> {
); );
return; return;
} }
core.warning(
'setup-php v1 is deprecated.\nPlease upgrade to v2 - https://setup-php.com/w/Switch-to-v2'
);
const version: string = await utils.parseVersion( const version: string = await utils.parseVersion(
await utils.getInput('php-version', true) await utils.getInput('php-version', true)
); );
if (parseFloat(version) < 5.6 || parseFloat(version) > 8.0) {
core.setFailed(
`setup-php v1 supports only PHP 5.6 to 8.0.\nPlease upgrade to v2 - https://setup-php.com/w/Switch-to-v2`
);
return;
}
if (version) { if (version) {
const os_version: string = process.platform; const os_version: string = process.platform;
const tool = await utils.scriptTool(os_version); // check the os version and run the respective script
const script = os_version + (await utils.scriptExtension(os_version)); let script_path = '';
const location = await getScript(script, version, os_version); switch (os_version) {
await exec(await utils.joins(tool, location, version, __dirname)); case 'darwin':
case 'linux':
script_path = await build(os_version + '.sh', version, os_version);
await exec('bash ' + script_path + ' ' + version + ' ' + __dirname);
break;
case 'win32':
script_path = await build('win32.ps1', version, os_version);
await exec('pwsh ' + script_path + ' ' + version + ' ' + __dirname);
break;
}
} else { } else {
core.setFailed('Unable to get the PHP version'); core.setFailed('Unable to get the PHP version');
} }
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error as Error);
} }
} }

View File

@ -1,314 +0,0 @@
# Variables
export tick="✓"
export cross="✗"
export curl_opts=(-sL)
export old_versions="5.[3-5]"
export jit_versions="8.[0-9]"
export nightly_versions="8.[1-9]"
export xdebug3_versions="7.[2-4]|8.[0-9]"
export tool_path_dir="/usr/local/bin"
export composer_home="$HOME/.composer"
export composer_bin="$composer_home/vendor/bin"
export composer_json="$composer_home/composer.json"
export composer_lock="$composer_home/composer.lock"
export latest="releases/latest/download"
export github="https://github.com/shivammathur"
export jsdeliver="https://cdn.jsdelivr.net/gh/shivammathur"
# Function to log start of a operation.
step_log() {
message=$1
printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
}
# Function to log result of a operation.
add_log() {
mark=$1
subject=$2
message=$3
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" "$message"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
[ "$fail_fast" = "true" ] && exit 1
fi
}
# Function to log result of installing extension.
add_extension_log() {
(
check_extension "$(echo "$1" | cut -d '-' -f 1)" && add_log "$tick" "$1" "$2"
) || add_log "$cross" "$1" "Could not install $1 on PHP ${semver:?}"
}
# Function to read env inputs.
read_env() {
[[ -z "${update}" ]] && update='false' && UPDATE='false' || update="${update}"
[ "$update" = false ] && [[ -n ${UPDATE} ]] && update="${UPDATE}"
[[ -z "${runner}" ]] && runner='github' && RUNNER='github' || runner="${runner}"
[ "$runner" = false ] && [[ -n ${RUNNER} ]] && runner="${RUNNER}"
[[ -z "${fail_fast}" ]] && fail_fast='false' || fail_fast="${fail_fast}"
}
# Function to download a file using cURL.
# mode: -s pipe to stdout, -v save file and return status code
# execute: -e save file as executable
get() {
mode=$1
execute=$2
file_path=$3
shift 3
links=("$@")
if [ "$mode" = "-s" ]; then
sudo curl "${curl_opts[@]}" "${links[0]}"
else
for link in "${links[@]}"; do
status_code=$(sudo curl -w "%{http_code}" -o "$file_path" "${curl_opts[@]}" "$link")
[ "$status_code" = "200" ] && break
done
[ "$execute" = "-e" ] && sudo chmod a+x "$file_path"
[ "$mode" = "-v" ] && echo "$status_code"
fi
}
# Function to download and run scripts from GitHub releases with jsdeliver fallback.
run_script() {
repo=$1
shift
args=("$@")
get -q -e /tmp/install.sh "$github/$repo/$latest/install.sh" "$jsdeliver/$1@main/scripts/install.sh"
bash /tmp/install.sh "${args[@]}"
}
# Function to install required packages on self-hosted runners.
self_hosted_setup() {
if [ "$runner" = "self-hosted" ]; then
if [[ "${version:?}" =~ $old_versions ]]; then
add_log "$cross" "PHP" "PHP $version is not supported on self-hosted runner"
exit 1
else
self_hosted_helper >/dev/null 2>&1
fi
fi
}
# Function to test if extension is loaded.
check_extension() {
extension=$1
if [ "$extension" != "mysql" ]; then
php -m | grep -i -q -w "$extension"
else
php -m | grep -i -q "$extension"
fi
}
# Function to enable cached extensions.
enable_cache_extension() {
deps=()
for ext in /tmp/extcache/"$1"/*; do
deps+=("$(basename "$ext")")
done
if [ "x${deps[*]}" = "x" ]; then
sudo rm -rf /tmp/extcache/"$1"
enable_extension "$1" "$2"
else
deps+=("$1")
if php "${deps[@]/#/-d ${2}=}" -m 2>/dev/null | grep -i -q "$1"; then
for ext in "${deps[@]}"; do
sudo rm -rf /tmp/extcache/"$ext"
enable_extension "$ext" "$2"
done
fi
fi
}
# Function to enable existing extensions.
enable_extension() {
modules_dir="/var/lib/php/modules/$version"
[ -d "$modules_dir" ] && sudo find "$modules_dir" -path "*disabled*$1" -delete
if [ -d /tmp/extcache/"$1" ]; then
enable_cache_extension "$1" "$2"
elif ! check_extension "$1" && [ -e "${ext_dir:?}/$1.so" ]; then
echo "$2=${ext_dir:?}/$1.so" | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
fi
}
# Function to configure PHP
configure_php() {
(
echo -e "date.timezone=UTC\nmemory_limit=-1"
[[ "$version" =~ $jit_versions ]] && echo -e "opcache.enable=1\nopcache.jit_buffer_size=256M\nopcache.jit=1235"
[[ "$version" =~ $xdebug3_versions ]] && echo -e "xdebug.mode=coverage"
) | sudo tee -a "${pecl_file:-${ini_file[@]}}" >/dev/null
}
# Function to configure PECL.
configure_pecl() {
if ! [ -e /tmp/pecl_config ]; then
for script in pear pecl; do
sudo "$script" config-set php_ini "${pecl_file:-${ini_file[@]}}"
sudo "$script" channel-update "$script".php.net
done
echo '' | sudo tee /tmp/pecl_config >/dev/null 2>&1
fi
}
# Function to get the PECL version of an extension.
get_pecl_version() {
extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(stable|alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/'
response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "([0-9]+\.[0-9]+\.[0-9]+${stability}[0-9]+)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
fi
echo "$pecl_version"
}
# Function to install PECL extensions and accept default options
pecl_install() {
local extension=$1
add_pecl >/dev/null 2>&1
yes '' 2>/dev/null | sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to install a specific version of PECL extension.
add_pecl_extension() {
extension=$1
pecl_version=$2
prefix=$3
enable_extension "$extension" "$prefix"
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi
ext_version=$(php -r "echo phpversion('$extension');")
if [ "$ext_version" = "$pecl_version" ]; then
add_log "${tick:?}" "$extension" "Enabled"
else
disable_extension "$extension" >/dev/null 2>&1
delete_extension "$extension" >/dev/null 2>&1
pecl_install "$extension-$pecl_version"
add_extension_log "$extension-$pecl_version" "Installed and enabled"
fi
}
# Function to setup pre-release extensions using PECL.
add_unstable_extension() {
extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
add_pecl_extension "$extension" "$pecl_version" "$prefix"
}
# Function to extract tool version.
get_tool_version() {
tool=$1
param=$2
alp="[a-zA-Z0-9]"
version_regex="[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}"
if [ "$tool" = "composer" ]; then
if [ "$param" != "snapshot" ]; then
composer_version="$(grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex")"
else
composer_version="$(grep -Ea "const\sBRANCH_ALIAS_VERSION" "$tool_path_dir/composer" | grep -Eo "$version_regex")+$(grep -Ea "const\sVERSION" "$tool_path_dir/composer" | grep -Eo "[a-zA-z0-9]+" | tail -n 1)"
fi
echo "$composer_version" | sudo tee /tmp/composer_version
else
$tool "$param" 2>/dev/null | sed -Ee "s/[Cc]omposer(.)?$version_regex//g" | grep -Eo "$version_regex" | head -n 1
fi
}
# Function to configure composer
configure_composer() {
tool_path=$1
sudo ln -sf "$tool_path" "$tool_path.phar"
php -r "try {\$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception \$e) {exit(1);}"
if [ $? -eq 1 ]; then
add_log "$cross" "composer" "Could not download composer"
exit 1
fi
if ! [ -d "$composer_home" ]; then
sudo -u "$(id -un)" -g "$(id -gn)" mkdir -p -m=00755 "$composer_home"
else
sudo chown -R "$(id -un)":"$(id -gn)" "$composer_home"
fi
if ! [ -e "$composer_json" ]; then
echo '{}' | tee "$composer_json" >/dev/null
chmod 644 "$composer_json"
fi
composer -q config -g process-timeout 0
echo "$composer_bin" >>"$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
fi
}
# Function to setup a remote tool.
add_tool() {
url=$1
tool=$2
ver_param=$3
tool_path="$tool_path_dir/$tool"
if ! [[ "$PATH" =~ $tool_path_dir ]]; then
export PATH=$PATH:"$tool_path_dir"
echo "export PATH=\$PATH:$tool_path_dir" | sudo tee -a "$GITHUB_ENV" >/dev/null
fi
if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
IFS="," read -r -a url <<<"$url"
status_code=$(get -v -e "$tool_path" "${url[@]}")
if [ "$status_code" != "200" ] && [[ "${url[0]}" =~ .*github.com.*releases.*latest.* ]]; then
url[0]="${url[0]//releases\/latest\/download/releases/download/$(get -s -n "" "$(echo "${url[0]}" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "${url[0]}" | sed -e "s/.*\///")" | cut -d '/' -f 1)}"
status_code=$(get -v -e "$tool_path" "${url[0]}")
fi
if [ "$status_code" = "200" ]; then
add_tools_helper "$tool"
tool_version=$(get_tool_version "$tool" "$ver_param")
add_log "$tick" "$tool" "Added $tool $tool_version"
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
}
# Function to setup a tool using composer.
add_composertool() {
tool=$1
release=$2
prefix=$3
if [[ "$tool" =~ prestissimo|composer-prefetcher ]]; then
composer_version=$(cat /tmp/composer_version)
if [ "$(echo "$composer_version" | cut -d'.' -f 1)" != "1" ]; then
echo "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool"
add_log "$cross" "$tool" "Skipped"
return
fi
fi
(
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
composer global require "$prefix$release" 2>&1 | tee /tmp/composer.log >/dev/null 2>&1
log=$(grep "$prefix$tool" /tmp/composer.log) &&
tool_version=$(get_tool_version 'echo' "$log") &&
add_log "$tick" "$tool" "Added $tool $tool_version"
) || add_log "$cross" "$tool" "Could not setup $tool"
add_tools_helper "$tool"
if [ -e "$composer_bin/composer" ]; then
sudo cp -p "$tool_path_dir/composer" "$composer_bin"
fi
}
# Function to get PHP version in semver format.
php_semver() {
php -v | grep -Eo -m 1 "[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z]+([0-9]+)?)?" | head -n 1
}
# Function to get the tag for a php version.
php_src_tag() {
php_src_tag='master'
if ! [[ ${version:?} =~ $nightly_versions ]]; then
php_src_tag="php-$semver"
fi
echo "$php_src_tag"
}

View File

@ -1,44 +1,89 @@
# Function to setup environment for self-hosted runners. # Function to log start of a operation
self_hosted_helper() { step_log() {
if ! command -v brew >/dev/null; then message=$1
step_log "Setup Brew" printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
get -q -e "/tmp/install.sh" "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" && /tmp/install.sh >/dev/null 2>&1
add_log "${tick:?}" "Brew" "Installed Homebrew"
fi
} }
# Function to delete extension. # Function to log result of a operation
delete_extension() { add_log() {
extension=$1 mark=$1
sudo rm -rf "${scan_dir:?}"/*"$extension"* "${ext_dir:?}"/"$extension".so >/dev/null 2>&1 subject=$2
} message=$3
if [ "$mark" = "$tick" ]; then
# Function to disable extension. printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
disable_extension() {
extension=$1
sudo sed -Ei '' "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file:?}"
}
# Function to remove extensions.
remove_extension() {
extension=$1
if check_extension "$extension"; then
disable_extension "$extension"
delete_extension "$extension"
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Removed") ||
add_log "${cross:?}" ":$extension" "Could not remove $extension on PHP ${semver:?}"
else else
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver" printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi fi
} }
# Function to fetch a brew tap. # Function to remove extensions
remove_extension() {
local extension=$1
sudo sed -Ei '' "/=(.*\/)?\"?$extension/d" "$ini_file"
sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
}
# Function to test if extension is loaded
check_extension() {
local extension=$1
if [ "$extension" != "mysql" ]; then
php -m | grep -i -q -w "$extension"
else
php -m | grep -i -q "$extension"
fi
}
# Function to install PECL extensions and accept default options
pecl_install() {
local extension=$1
yes '' | sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to get the PECL version
get_pecl_version() {
local extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "([0-9]+\.[0-9]+\.[0-9]+${stability}[0-9]+)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
fi
echo "$pecl_version"
}
# Function to install a PECL version
add_pecl_extension() {
local extension=$1
pecl_version=$2
prefix=$3
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then
echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"
fi
ext_version=$(php -r "echo phpversion('$extension');")
if [ "$ext_version" = "$pecl_version" ]; then
add_log "$tick" "$extension" "Enabled"
else
remove_extension "$extension"
(
pecl_install "$extension-$pecl_version" >/dev/null 2>&1 &&
check_extension "$extension" &&
add_log "$tick" "$extension" "Installed and enabled"
) || add_log "$cross" "$extension" "Could not install $extension-$pecl_version on PHP $semver"
fi
}
# Function to fetch a brew tap
fetch_brew_tap() { fetch_brew_tap() {
tap=$1 tap=$1
tap_user=$(dirname "$tap") tap_user=$(dirname "$tap")
tap_name=$(basename "$tap") tap_name=$(basename "$tap")
mkdir -p "$tap_dir/$tap_user" mkdir -p "$tap_dir/$tap_user"
get -s -n "" "https://github.com/$tap/archive/master.tar.gz" | sudo tar -xzf - -C "$tap_dir/$tap_user" sudo curl "${curl_opts[@]}" "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 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" sudo mv "$tap_dir/$tap_user/$tap_name-master" "$tap_dir/$tap_user/$tap_name"
fi fi
@ -48,13 +93,9 @@ fetch_brew_tap() {
add_brew_tap() { add_brew_tap() {
tap=$1 tap=$1
if ! [ -d "$tap_dir/$tap" ]; then if ! [ -d "$tap_dir/$tap" ]; then
if [ "${runner:?}" = "self-hosted" ]; then fetch_brew_tap "$tap" >/dev/null 2>&1
if ! [ -d "$tap_dir/$tap" ]; then
brew tap "$tap" >/dev/null 2>&1 brew tap "$tap" >/dev/null 2>&1
else
fetch_brew_tap "$tap" >/dev/null 2>&1
if ! [ -d "$tap_dir/$tap" ]; then
brew tap "$tap" >/dev/null 2>&1
fi
fi fi
fi fi
} }
@ -62,54 +103,140 @@ add_brew_tap() {
# Function to install a php extension from shivammathur/extensions tap. # Function to install a php extension from shivammathur/extensions tap.
add_brew_extension() { add_brew_extension() {
formula=$1 formula=$1
prefix=$2 extension=$(grep "$formula=" "$dist"/../src/configs/brew_extensions | cut -d '=' -f 2)
extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")" [[ -z "$extension" ]] && extension="$(echo "$formula" | sed -E "s/pecl_|[0-9]//g")"
enable_extension "$extension" "$prefix" add_brew_tap shivammathur/homebrew-php
if check_extension "$extension"; then add_brew_tap shivammathur/homebrew-extensions
add_log "${tick:?}" "$extension" "Enabled" sudo mv "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$formula"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true
else brew install "$formula@$version"
add_brew_tap shivammathur/homebrew-php sudo cp "$brew_prefix/opt/$formula@$version/$extension.so" "$ext_dir"
add_brew_tap shivammathur/homebrew-extensions
sudo mv "$tap_dir"/shivammathur/homebrew-extensions/.github/deps/"$formula"/* "$tap_dir/homebrew/homebrew-core/Formula/" 2>/dev/null || true
update_dependencies >/dev/null 2>&1
brew install -f "$formula@$version" >/dev/null 2>&1
sudo cp "$brew_prefix/opt/$formula@$version/$extension.so" "$ext_dir"
add_extension_log "$extension" "Installed and enabled"
fi
} }
# Function to setup extensions. # Function to setup extensions
add_extension() { add_extension() {
extension=$1 local extension=$1
prefix=$2 install_command=$2
enable_extension "$extension" "$prefix" prefix=$3
if check_extension "$extension"; then if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then
add_log "${tick:?}" "$extension" "Enabled" echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled"
else elif check_extension "$extension"; then
if [[ "$version" =~ ${old_versions:?} ]] && [ "$extension" = "imagick" ]; then add_log "$tick" "$extension" "Enabled"
run_script "php5-darwin" "${version/./}" "$extension" >/dev/null 2>&1 elif ! check_extension "$extension"; then
else (
pecl_install "$extension" >/dev/null 2>&1 && eval "$install_command" >/dev/null 2>&1 &&
if [[ "$version" =~ ${old_versions:?} ]]; then echo "$prefix=$ext_dir/$extension.so" >>"$ini_file"; fi check_extension "$extension" &&
fi add_log "$tick" "$extension" "Installed and enabled"
add_extension_log "$extension" "Installed and enabled" ) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi fi
} }
# Function to handle request to add phpize and php-config. # Function to pre-release extensions using PECL
add_devtools() { add_unstable_extension() {
local extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
add_pecl_extension "$extension" "$pecl_version" "$prefix"
}
# Function to configure composer
configure_composer() {
tool_path=$1
sudo ln -sf "$tool_path" "$tool_path.phar"
php -r "try {\$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception \$e) {exit(1);}"
if [ $? -eq 1 ]; then
add_log "$cross" "composer" "Could not download composer"
exit 1;
fi
if ! [ -d "$composer_home" ]; then
sudo -u "$(id -un)" -g "$(id -gn)" mkdir -p -m=00755 "$composer_home"
else
sudo chown -R "$(id -un)":"$(id -gn)" "$composer_home"
fi
if ! [ -e "$composer_json" ]; then
echo '{}' | tee "$composer_json" >/dev/null
chmod 644 "$composer_json"
fi
composer -q config -g process-timeout 0
echo "$composer_bin" >> "$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
fi
}
# Function to setup a remote tool.
add_tool() {
url=$1
tool=$2
tool_path="$tool_path_dir/$tool"
if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
if [ "$tool" = "composer" ]; then
IFS="," read -r -a urls <<< "$url"
status_code=$(sudo curl -f -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[0]}") ||
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[1]}")
else
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
if [ "$status_code" != "200" ] && [[ "$url" =~ .*github.com.*releases.*latest.* ]]; then
url="${url//releases\/latest\/download/releases/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)}"
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then
configure_composer "$tool_path"
elif [ "$tool" = "phan" ]; then
add_extension fileinfo "pecl_install fileinfo" extension >/dev/null 2>&1
add_extension ast "pecl_install ast" extension >/dev/null 2>&1
elif [ "$tool" = "phive" ]; then
add_extension curl "pecl_install curl" extension >/dev/null 2>&1
add_extension mbstring "pecl_install mbstring" extension >/dev/null 2>&1
add_extension xml "pecl_install xml" extension >/dev/null 2>&1
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path"
tr -d '\r' < "$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path"
sudo chmod a+x "$tool_path"
fi
add_log "$tick" "$tool" "Added"
else
add_log "$cross" "$tool" "Could not setup $tool"
fi
}
# Function to add a tool using composer
add_composertool() {
tool=$1 tool=$1
add_log "${tick:?}" "$tool" "Added $tool $semver" release=$2
prefix=$3
(
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
composer global require "$prefix$release" >/dev/null 2>&1 &&
add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool"
if [ -e "$composer_bin/composer" ]; then
sudo cp -p "$tool_path_dir/composer" "$composer_bin"
fi
if [ "$tool" = "codeception" ]; then
sudo ln -s "$composer_bin"/codecept "$composer_bin"/codeception
fi
} }
# Function to handle request to add PECL. # Function to configure PECL
configure_pecl() {
for tool in pear pecl; do
sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1
sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1
done
}
# Function to log PECL, it is installed along with PHP
add_pecl() { add_pecl() {
configure_pecl >/dev/null 2>&1 add_log "$tick" "PECL" "Added"
pecl_version=$(get_tool_version "pecl" "version")
add_log "${tick:?}" "PECL" "Found PECL $pecl_version"
} }
# Function to link all libraries of a formula. # Function to backup all libraries of a formula
link_libraries() { link_libraries() {
formula=$1 formula=$1
formula_prefix="$(brew --prefix "$formula")" formula_prefix="$(brew --prefix "$formula")"
@ -120,46 +247,36 @@ link_libraries() {
done done
} }
# Patch brew to overwrite packages.
patch_brew() { patch_brew() {
formula_installer="$brew_repo"/Library/Homebrew/formula_installer.rb formula_installer="$brew_repo"/Library/Homebrew/formula_installer.rb
code=" keg.link(verbose: verbose?" code=" keg.link\(verbose: verbose\?"
sudo sed -i '' "s/$code)/$code, overwrite: true)/" "$formula_installer" sudo sed -Ei '' "s/$code.*/$code, overwrite: true\)/" "$formula_installer"
# shellcheck disable=SC2064 # shellcheck disable=SC2064
trap "sudo sed -i '' 's/$code, overwrite: true)/$code)/' $formula_installer" exit trap "sudo sed -Ei '' 's/$code.*/$code, overwrite: overwrite?\)/' $formula_installer" exit
} }
# Helper function to update the dependencies. # Helper function to update the dependencies.
update_dependencies_helper() { update_dependencies_helper() {
dependency=$1 dependency=$1
get -q -n "$tap_dir/homebrew/homebrew-core/Formula/$dependency.rb" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$dependency.rb" curl -o "$tap_dir/homebrew/homebrew-core/Formula/$formula.rb" "${curl_opts[@]}" "https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/$formula.rb"
link_libraries "$dependency" link_libraries "$dependency"
} }
# Function to update dependencies. # Function to update dependencies
update_dependencies() { update_dependencies() {
if ! [ -e /tmp/update_dependencies ] && [ "${runner:?}" != "self-hosted" ] && [ "${ImageOS:-}" != "" ] && [ "${ImageVersion:-}" != "" ]; then if ! [ -e /tmp/update_dependencies ]; then
patch_brew if [ "${ImageOS:-}" != "" ] && [ "${ImageVersion:-}" != "" ]; then
while read -r dependency; do patch_brew
update_dependencies_helper "$dependency" & while read -r dependency; do
to_wait+=($!) update_dependencies_helper "$dependency" &
done <"$tap_dir/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}" to_wait+=($!)
wait "${to_wait[@]}" done <"$tap_dir/shivammathur/homebrew-php/.github/deps/${ImageOS:?}_${ImageVersion:?}"
wait "${to_wait[@]}"
fi
echo '' | sudo tee /tmp/update_dependencies >/dev/null 2>&1 echo '' | sudo tee /tmp/update_dependencies >/dev/null 2>&1
fi fi
} }
# Function to fix dependencies on install PHP version.
fix_dependencies() {
broken_deps_paths=$(php -v 2>&1 | grep -Eo '/opt/[a-zA-Z0-9@\.]+')
if [ "x$broken_deps_paths" != "x" ]; then
update_dependencies
IFS=" " read -r -a formulae <<< "$(echo "$broken_deps_paths" | tr '\n' ' ' | sed 's|/opt/||g' 2>&1)$php_formula"
brew reinstall "${formulae[@]}"
brew link --force --overwrite "$php_formula" || true
fi
}
# Function to get PHP version if it is already installed using Homebrew. # Function to get PHP version if it is already installed using Homebrew.
get_brewed_php() { get_brewed_php() {
php_cellar="$brew_prefix"/Cellar/php php_cellar="$brew_prefix"/Cellar/php
@ -170,80 +287,63 @@ get_brewed_php() {
fi fi
} }
# Function to setup PHP 5.6 and newer using Homebrew. # Function to setup PHP and composer
add_php() { setup_php() {
action=$1
existing_version=$2
add_brew_tap shivammathur/homebrew-php add_brew_tap shivammathur/homebrew-php
update_dependencies update_dependencies
if [ "$existing_version" != "false" ]; then brew upgrade shivammathur/php/php@"$version" 2>/dev/null || brew install shivammathur/php/php@"$version"
([ "$action" = "upgrade" ] && brew upgrade -f "$php_formula") || brew unlink "$php_formula" brew link --force --overwrite php@"$version"
else
brew install -f "$php_formula"
fi
brew link --force --overwrite "$php_formula"
} }
# Function to get extra version. # Function to configure PHP
php_extra_version() { configure_php() {
if [[ ${version:?} =~ ${nightly_versions:?} ]]; then (
echo " ($(brew cat "$php_formula" | grep -Eo "commit=[0-9a-zA-Z]+" | cut -d'=' -f 2))" echo -e "date.timezone=UTC\nmemory_limit=-1"
fi [[ "$version" =~ 8.0 ]] && echo -e "opcache.enable=1\nopcache.jit_buffer_size=256M\nopcache.jit=1235"
} [[ "$version" =~ 7.[2-4]|8.0 ]] && echo -e "xdebug.mode=coverage"
) | sudo tee -a "$ini_file" >/dev/null
# Function to Setup PHP.
setup_php() {
step_log "Setup PHP"
existing_version=$(get_brewed_php)
if [[ "$version" =~ ${old_versions:?} ]]; then
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
status="Installed"
elif [ "$existing_version" != "$version" ]; then
add_php "install" "$existing_version" >/dev/null 2>&1
status="Installed"
elif [ "$existing_version" = "$version" ] && [ "${update:?}" = "true" ]; then
add_php "upgrade" "$existing_version" >/dev/null 2>&1
status="Updated to"
else
status="Found"
fix_dependencies >/dev/null 2>&1
fi
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
sudo chmod 777 "$ini_file" "${tool_path_dir:?}"
configure_php
ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
semver=$(php_semver)
extra_version=$(php_extra_version)
if [ "${semver%.*}" != "$version" ]; then
add_log "$cross" "PHP" "Could not setup PHP $version"
exit 1
fi
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
echo "::set-output name=php-version::$semver"
add_log "$tick" "PHP" "$status PHP $semver$extra_version"
} }
# Variables # Variables
tick="✓"
cross="✗"
version=$1 version=$1
dist=$2 dist=$2
php_formula=shivammathur/php/php@"$version" tool_path_dir="/usr/local/bin"
curl_opts=(-sL)
composer_home="$HOME/.composer"
composer_bin="$composer_home/vendor/bin"
composer_json="$composer_home/composer.json"
composer_lock="$composer_home/composer.lock"
brew_prefix="$(brew --prefix)" brew_prefix="$(brew --prefix)"
brew_repo="$(brew --repository)" brew_repo="$(brew --repository)"
tap_dir="$brew_repo"/Library/Taps tap_dir="$brew_repo"/Library/Taps
scripts="${dist}"/../src/scripts existing_version=$(get_brewed_php)
export HOMEBREW_CHANGE_ARCH_TO_ARM=1 export HOMEBREW_CHANGE_ARCH_TO_ARM=1
export HOMEBREW_DEVELOPER=1 export HOMEBREW_DEVELOPER=1
export HOMEBREW_NO_INSTALL_CLEANUP=1 export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_AUTO_UPDATE=1 export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
# shellcheck source=. # Setup PHP
. "${scripts:?}"/ext/source.sh step_log "Setup PHP"
. "${scripts:?}"/tools/add_tools.sh if [ "$existing_version" != "$version" ]; then
. "${scripts:?}"/common.sh setup_php >/dev/null 2>&1
read_env status="Installed"
self_hosted_setup else
setup_php status="Found"
fi
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
sudo chmod 777 "$ini_file" "$tool_path_dir"
configure_php
ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer"
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
if [ "${semver%.*}" != "$version" ]; then
add_log "$cross" "PHP" "Could not setup PHP $version"
exit 1
fi
configure_pecl
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -1,32 +0,0 @@
# Function to install blackfire extension.
Function Add-Blackfire() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[string]
$extension
)
try {
$no_dot_version = $version.replace('.', '')
$extension_version = $extension.split('-')[1]
if ($extension_version -notmatch "\S") {
if($version -lt '7.0') {
$extension_version = '1.50.0'
} else {
$extension_version = (Invoke-RestMethod https://blackfire.io/api/v1/releases).probe.php
}
}
if (Test-Path $ext_dir\blackfire.dll) {
Enable-PhpExtension -Extension blackfire -Path $php_dir
$status="Enabled"
} else {
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
Invoke-WebRequest -Uri "https://packages.blackfire.io/binaries/blackfire-php/${extension_version}/blackfire-php-windows_${arch}-php-${no_dot_version}${nts}.dll" -OutFile $ext_dir\blackfire.dll > $null 2>&1
Enable-PhpExtension -Extension blackfire -Path $php_dir
$status="Installed and enabled"
}
Add-Log $tick $extension $status
} catch {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}

View File

@ -1,21 +0,0 @@
# Function to install blackfire extension.
add_blackfire() {
extension=$1
version=${version:?}
no_dot_version=${version/./}
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
extension_version=$(echo "$extension" | cut -d '-' -f 2)
blackfire_ini_file="${pecl_file:-${ini_file[@]}}"
if [ ! -e "${ext_dir:?}/blackfire.so" ]; then
if [ "$extension_version" = "blackfire" ]; then
if [[ ${version:?} =~ 5.[3-6] ]]; then
extension_version='1.50.0'
else
extension_version=$(get -s -n "" https://blackfire.io/api/v1/releases | grep -Eo 'php":"([0-9]+.[0-9]+.[0-9]+)' | cut -d '"' -f 3)
fi
fi
get -q -n "${ext_dir:?}/blackfire.so" https://packages.blackfire.io/binaries/blackfire-php/"$extension_version"/blackfire-php-"$platform"_amd64-php-"$no_dot_version".so >/dev/null 2>&1
fi
echo "extension=blackfire.so" | sudo tee -a "$blackfire_ini_file" >/dev/null 2>&1
add_extension_log "$extension-$extension_version" "Installed and enabled"
}

View File

@ -1,43 +0,0 @@
# Function to install libraries required by couchbase
add_couchbase_libs() {
if [ "$(uname -s)" = "Linux" ]; then
trunk="https://github.com/couchbase/libcouchbase/releases"
if [[ ${version:?} =~ 5.[3-6]|7.[0-1] ]]; then
release="2.10.9"
else
release="$(curl -sL $trunk/latest | grep -Eo "libcouchbase-[0-9]+\.[0-9]+\.[0-9]+" | head -n 1 | cut -d'-' -f 2)"
fi
deb_url="$trunk/download/$release/libcouchbase-${release}_ubuntu${VERSION_ID/./}_${VERSION_CODENAME}_amd64.tar"
get -q -n /tmp/libcouchbase.tar "$deb_url"
sudo tar -xf /tmp/libcouchbase.tar -C /tmp
install_packages libev4 libevent-dev
sudo dpkg -i /tmp/libcouchbase-*/*.deb
else
if [[ ${version:?} =~ 5.[3-6]|7.[0-1] ]]; then
brew install libcouchbase@2
brew link --overwrite --force libcouchbase@2
else
brew install libcouchbase
fi
fi
}
# Function to add couchbase.
add_couchbase() {
add_couchbase_libs >/dev/null 2>&1
enable_extension "couchbase" "extension"
if check_extension "couchbase"; then
add_log "${tick:?}" "couchbase" "Enabled"
else
if [[ "${version:?}" =~ ${old_versions:?} ]]; then
pecl_install couchbase-2.2.3 >/dev/null 2>&1
elif [[ "${version:?}" =~ 5.6|7.[0-1] ]]; then
pecl_install couchbase-2.6.2 >/dev/null 2>&1
elif [[ "${version:?}" =~ 7.2 ]]; then
pecl_install couchbase-3.0.4 >/dev/null 2>&1
else
pecl_install couchbase >/dev/null 2>&1
fi
add_extension_log "couchbase" "Installed and enabled"
fi
}

View File

@ -1,60 +0,0 @@
# Function to log license details.
add_license_log() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$ext" "Click to read the $ext related license information"
printf "Cubrid CCI package is required for %s extension.\n" "$ext"
printf "The extension %s and Cubrid CCI are provided under the license linked below.\n" "$ext"
printf "Refer to: \033[35;1m%s \033[0m\n" "https://github.com/CUBRID/cubrid-cci/blob/develop/COPYING"
echo "::endgroup::"
}
# Function to setup gcc-7 and g++-7
setup_compiler() {
if ! command -v gcc-7 >/dev/null || ! command -v g++-7 >/dev/null; then
add_ppa ubuntu-toolchain-r/test
add_packages gcc-7 g++-7 -y
fi
printf "gcc g++" | xargs -d ' ' -I {} sudo update-alternatives --install /usr/bin/{} {} /usr/bin/{}-7 7
}
# Function to set cubrid repo for the extension.
set_cubrid_repo() {
case "${ext:?}" in
"cubrid") cubrid_repo="cubrid-php";;
"pdo_cubrid") cubrid_repo="cubrid-pdo";;
esac
}
# Function to set cubrid branch for a PHP version.
set_cubrid_branch() {
case "${version:?}" in
5.[3-6]) cubrid_branch="RB-9.3.0";;
*) cubrid_branch="develop";;
esac
}
add_cubrid_helper() {
ext=$1
enable_extension "$ext" extension
if ! check_extension "$ext"; then
status='Installed and enabled'
set_cubrid_repo
set_cubrid_branch
patch_phpize
read -r "${ext}_PREFIX_CONFIGURE_OPTS" <<< "CFLAGS=-Wno-implicit-function-declaration"
read -r "${ext}_CONFIGURE_OPTS" <<< "--with-php-config=$(command -v php-config)"
add_extension_from_source "$ext" https://github.com CUBRID "$cubrid_repo" "$cubrid_branch" extension
restore_phpize
fi
}
# Function to add cubrid and pdo_cubrid.
add_cubrid() {
ext=$1
status='Enabled'
add_cubrid_helper "$ext" >/dev/null 2>&1
add_extension_log "$ext" "$status"
check_extension "$ext" && add_license_log
}
# shellcheck source=.
. "${scripts:?}"/ext/patches/phpize.sh

View File

@ -1,20 +0,0 @@
Function Add-Choco() {
try {
if($null -eq (Get-Command -Name choco.exe -ErrorAction SilentlyContinue)) {
# Source: https://docs.chocolatey.org/en-us/choco/setup
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
}
} catch { }
}
Function Add-Firebird() {
Add-Choco > $null 2>&1
choco install firebird -params '/ClientAndDevTools' -y --force > $null 2>&1
if((Get-ChildItem $env:ProgramFiles\**\**\fbclient.dll | Measure-Object).Count -eq 1) {
Add-Extension pdo_firebird
} else {
Add-Log $cross pdo_firebird "Could not install pdo_firebird on PHP $( $installed.FullVersion )"
}
}

View File

@ -1,35 +0,0 @@
add_firebird_client_darwin() {
firebird_tag='R3_0_7'
pkg_name=$(get -s -n "" https://github.com/FirebirdSQL/firebird/releases/tag/"$firebird_tag" | grep -Eo "Firebird-.*.pkg" | head -n 1)
get -q -e "/tmp/firebird.pkg" https://github.com/FirebirdSQL/firebird/releases/download/"$firebird_tag"/"$pkg_name"
sudo installer -pkg /tmp/firebird.pkg -target /
sudo mkdir -p /opt/firebird/include /opt/firebird/lib
sudo find /Library/Frameworks/Firebird.framework -name '*.h' -exec cp "{}" /opt/firebird/include \;
sudo find /Library/Frameworks/Firebird.framework -name '*.dylib' -exec cp "{}" /opt/firebird/lib \;
}
add_firebird_helper() {
firebird_dir=$1
tag="$(php_src_tag)"
export PDO_FIREBIRD_CONFIGURE_OPTS="--with-pdo-firebird=$firebird_dir"
export PDO_FIREBIRD_LINUX_LIBS="firebird-dev"
export PDO_FIREBIRD_PATH="ext/pdo_firebird"
add_extension_from_source pdo_firebird https://github.com php php-src "$tag" extension get
}
add_firebird() {
enable_extension pdo_firebird
if ! check_extension pdo_firebird; then
if [ "$(uname -s)" = "Linux" ]; then
if [[ "${version:?}" =~ 5.3|${nightly_versions:?} ]]; then
add_firebird_helper /usr >/dev/null 2>&1
else
add_pdo_extension firebird >/dev/null 2>&1
fi
else
add_firebird_client_darwin >/dev/null 2>&1
add_firebird_helper /opt/firebird >/dev/null 2>&1
fi
add_extension_log pdo_firebird "Installed and enabled"
fi
}

View File

@ -1,15 +1,11 @@
# Helper function to add gearman extension. # Helper function to add gearman extension.
add_gearman_helper() { add_gearman_helper() {
add_ppa ondrej/pkg-gearman add_ppa ondrej/pkg-gearman
install_packages libgearman-dev sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y libgearman-dev
enable_extension gearman extension enable_extension gearman extension
if ! check_extension gearman; then if ! check_extension gearman; then
status="Installed and enabled" status="Installed and enabled"
if [[ "${version:?}" =~ 5.[3-5] ]]; then sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"${version:?}"-gearman || pecl_install gearman
pecl_install gearman-1.1.2
else
install_packages php"${version:?}"-gearman || pecl_install gearman
fi
enable_extension gearman extension enable_extension gearman extension
fi fi
} }
@ -18,5 +14,9 @@ add_gearman_helper() {
add_gearman() { add_gearman() {
status="Enabled" status="Enabled"
add_gearman_helper >/dev/null 2>&1 add_gearman_helper >/dev/null 2>&1
add_extension_log "gearman" "$status" if check_extension gearman; then
add_log "${tick:?}" "gearman" "$status"
fi
} }
add_gearman

View File

@ -1,17 +0,0 @@
# Helper function to compile and install geos
add_geos_helper() {
export GEOS_LINUX_LIBS='libgeos-dev'
export GEOS_DARWIN_LIBS='geos'
add_extension_from_source geos https://github.com libgeos php-geos 1.0.0 extension get
}
# Function to add geos
add_geos() {
enable_extension "geos" "extension"
if check_extension "geos"; then
add_log "${tick:?}" "geos" "Enabled"
else
add_geos_helper >/dev/null 2>&1
add_extension_log "geos" "Installed and enabled"
fi
}

View File

@ -1,55 +0,0 @@
Function Get-ICUUrl() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
$icu_version,
[Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()]
$arch,
[Parameter(Position = 2, Mandatory = $true)]
[ValidateNotNull()]
$vs_version
)
$trunk = "https://windows.php.net"
$urls=@("${trunk}/downloads/php-sdk/deps/${vs_version}/${arch}", "${trunk}/downloads/php-sdk/deps/archives/${vs_version}/${arch}")
foreach ($url in $urls) {
$web_content = Invoke-WebRequest -Uri $url
foreach ($link in $web_content.Links) {
if ($link -match "/.*ICU-${icu_version}.*/") {
return $trunk + $link.HREF
}
}
}
}
Function Repair-ICU() {
$icu = deplister $ext_dir\php_http.dll | Select-String "icu[a-z]+(\d+).dll,([A-Z]+)" | Foreach-Object { $_.Matches }
if($icu -and $icu.Groups[2].Value -ne 'OK') {
$vs = "vs" + $installed.VCVersion
if ($installed.VCVersion -lt 16) {
$vs = "vc" + $installed.VCVersion
}
$zip_url = Get-ICUUrl $icu.Groups[1].Value $installed.Architecture $vs
if ($zip_url -ne '') {
New-Item -Path "$php_dir" -Name "icu" -ItemType "directory" | Out-Null
Invoke-WebRequest -Uri $zip_url -OutFile "$php_dir\icu\icu.zip"
Expand-Archive -Path $php_dir\icu\icu.zip -DestinationPath $php_dir\icu -Force
Get-ChildItem $php_dir\icu\bin -Filter *.dll | Copy-Item -Destination $php_dir -Force
}
}
}
Function Add-Http() {
Add-Extension raphf >$null 2>&1
if($version -lt '8.0') {
Add-Extension propro >$null 2>&1
}
Add-Extension pecl_http >$null 2>&1
Repair-ICU
try {
php --ri "http" 2> $null | Out-Null
Add-Log $tick "http" "Installed and enabled"
} catch {
Add-Log $cross "http" "Could not install http on PHP $( $installed.FullVersion )"
}
}

View File

@ -1,120 +0,0 @@
# Function to get http version for a PHP version.
get_http_version() {
if [[ ${version:?} =~ 5.[3-6] ]]; then
echo "pecl_http-2.6.0"
elif [[ ${version:?} =~ 7.[0-4] ]]; then
echo "pecl_http-3.2.4"
else
echo "pecl_http-$(get_pecl_version "pecl_http" "stable")"
fi
}
# Function to enable http extension.
enable_http() {
enable_extension propro extension
enable_extension raphf extension
if (! [[ ${version:?} =~ ${jit_versions:?} ]] && check_extension propro && check_extension raphf) ||
( [[ ${version:?} =~ ${jit_versions:?} ]] && check_extension raphf); then
enable_extension http extension
fi
}
# Function to install extensions.
add_extension_helper() {
if [ "$os" = "Linux" ]; then
add_extension "$1" extension
else
add_brew_extension "$1" extension
fi
}
# Function to install http dependencies.
add_http_dependencies() {
if [[ ${version:?} =~ ${old_versions:?} ]]; then
add_pecl_extension raphf 1.1.2 extension
add_pecl_extension propro 1.0.2 extension
elif [[ ${version:?} =~ 5.6|7.[0-4] ]]; then
add_extension_helper propro
add_extension_helper raphf
else
add_extension_helper raphf
fi
}
# Function to get configure options for http.
get_http_configure_opts() {
if [ "$os" = 'Linux' ]; then
for lib in zlib libbrotli libcurl libevent libicu libidn2 libidn libidnkit2 libidnkit; do
http_opts+=( "--with-http-$lib-dir=/usr" )
done
else
http_opts+=( "--with-http-zlib-dir=$(xcrun --show-sdk-path)/usr" )
http_opts+=( "--with-http-libbrotli-dir=$(brew --prefix brotli)" )
http_opts+=( "--with-http-libcurl-dir=$(brew --prefix curl)" )
http_opts+=( "--with-http-libicu-dir=$(brew --prefix icu4c)" )
http_opts+=( "--with-http-libevent-dir=$(brew --prefix libevent)" )
http_opts+=( "--with-http-libidn2-dir=$(brew --prefix libidn2)" )
fi
}
# Compile and install http explicitly.
# This is done as pecl compiles raphf and propro as well.
add_http_helper() {
ext=$1
http_opts=() && get_http_configure_opts
export HTTP_PREFIX_CONFIGURE_OPTS="CFLAGS=-Wno-implicit-function-declaration"
http_configure_opts="--with-http --with-php-config=$(command -v php-config) ${http_opts[*]}"
export HTTP_CONFIGURE_OPTS="$http_configure_opts"
export HTTP_LINUX_LIBS="zlib1g libbrotli-dev libcurl4-openssl-dev libevent-dev libicu-dev libidn2-dev"
export HTTP_DARWIN_LIBS="brotli curl icu4c libevent libidn2"
if [[ "${version:?}" =~ ${nightly_versions:?} ]]; then
add_extension_from_source http https://github.com m6w6 ext-http master extension
else
add_extension_from_source pecl_http https://pecl.php.net http http "${ext##*-}" extension pecl
fi
}
# Function to setup latest http extension.
add_http_latest() {
enable_http
if ! check_extension http; then
add_http_dependencies
if [ "$os" = "Linux" ]; then
if ! [[ "${version:?}" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
install_packages "php$version-http"
else
add_http_helper "$(get_http_version)" "$os"
fi
else
if ! [[ "${version:?}" =~ ${old_versions:?} ]]; then
add_brew_extension pecl_http extension
fi
fi
status="Installed and enabled"
fi
}
# Function to setup http extension given a version.
add_http_version() {
ext=$1
enable_http
if [ "x$(php -r "echo phpversion('http');")" != "x${ext##*-}" ]; then
remove_extension http >/dev/null
add_http_helper pecl_http-"${ext##*-}" "$os"
status="Installed and enabled"
fi
}
# Function to setup http extension
add_http() {
ext=$1
status="Enabled"
if [[ "$ext" =~ ^(pecl_http|http)$ ]]; then
add_http_latest >/dev/null 2>&1
else
add_http_version "$ext" >/dev/null 2>&1
fi
add_extension_log "http" "$status"
}
os="$(uname -s)"

View File

@ -1,23 +0,0 @@
# Function to install ICU
install_icu() {
icu=$1
if [ "$(php -i | grep "ICU version =>" | sed -e "s|.*=> s*||")" != "$icu" ]; then
get -q -n /tmp/icu.tar.zst "https://github.com/shivammathur/icu-intl/releases/download/icu4c/icu4c-$icu.tar.zst"
sudo tar -I zstd -xf /tmp/icu.tar.zst -C /usr/local
sudo cp -r /usr/local/icu/lib/* /usr/lib/x86_64-linux-gnu/
fi
}
# Function to add ext-intl with the given version of ICU
add_intl() {
icu=$(echo "$1" | cut -d'-' -f 2)
supported_version=$(get -s -n "" https://api.github.com/repos/shivammathur/icu-intl/releases | grep -Po "${icu//./\\.}" | head -n 1)
if [ "$icu" != "$supported_version" ]; then
add_log "${cross:?}" "intl" "ICU $icu is not supported"
else
install_icu "$icu" >/dev/null 2>&1
get -q -n "${ext_dir:?}/intl.so" "https://github.com/shivammathur/icu-intl/releases/download/intl/php${version:?}-intl-$icu.so"
enable_extension intl extension
add_extension_log intl "Installed and enabled with ICU $icu"
fi
}

View File

@ -1,32 +0,0 @@
# Function to log result of a operation.
Function Add-LicenseLog() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "ioncube" "Click to read the ioncube loader license information"
Get-Content $ext_dir\ioncube\LICENSE.txt
Write-Output "::endgroup::"
}
# Function to add ioncube extension.
Function Add-Ioncube() {
try {
if (-not(Test-Path $ext_dir\php_ioncube.dll)) {
$status = 'Installed and enabled'
$arch_part = $arch
if ($arch -eq 'x64') {
$arch_part = 'x86-64'
}
$vc = $installed.VCVersion
$ts_part = ""
if (-not($installed.ThreadSafe)) {
$ts_part = "_nonts"
}
Invoke-WebRequest -Uri "https://downloads.ioncube.com/loader_downloads/ioncube_loaders_win$ts_part`_vc$vc`_$arch_part.zip" -OutFile $ext_dir\ioncube.zip
Expand-Archive -Path $ext_dir\ioncube.zip -DestinationPath $ext_dir -Force
Copy-Item $ext_dir\ioncube\ioncube_loader_win_$version.dll $ext_dir\php_ioncube.dll
}
"zend_extension=$ext_dir\php_ioncube.dll`r`n" + (Get-Content $php_dir\php.ini -Raw) | Set-Content $php_dir\php.ini
Add-Log $tick "ioncube" $status
Add-LicenseLog
} catch {
Add-Log $cross "ioncube" "Could not install ioncube on PHP $($installed.FullVersion)"
}
}

View File

@ -1,19 +0,0 @@
# Function to log result of a operation.
add_license_log() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "ioncube" "Click to read the ioncube loader license information"
cat /tmp/ioncube/LICENSE.txt
echo "::endgroup::"
}
# Function to install ioncube.
add_ioncube() {
if [ ! -e "${ext_dir:?}/ioncube.so" ]; then
status='Installed and enabled'
os_name='lin' && [ "$(uname -s)" = "Darwin" ] && os_name='mac'
get -s -n "" https://downloads.ioncube.com/loader_downloads/ioncube_loaders_"$os_name"_x86-64.tar.gz | tar -xzf - -C /tmp
sudo mv /tmp/ioncube/ioncube_loader_"$os_name"_"${version:?}".so "$ext_dir/ioncube.so"
fi
echo "zend_extension=$ext_dir/ioncube.so" | sudo tee "${scan_dir:?}/00-ioncube.ini" >/dev/null 2>&1
add_extension_log "ioncube" "$status"
check_extension "ioncube" && add_license_log
}

View File

@ -1,60 +0,0 @@
# Function to log license information.
Function Add-LicenseLog() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $extension "Click to read the $extension related license information"
printf "Oracle Instant Client package is required for %s extension.\n" $extension
printf "It is provided under the Oracle Technology Network Development and Distribution License.\n"
printf "Refer to: \033[35;1m%s \033[0m\n" "https://www.oracle.com/downloads/licenses/instant-client-lic.html"
Write-Output "::endgroup::"
}
# Function to get instantclinet.
Function Add-InstantClient() {
if (-not(Test-Path $php_dir\oci.dll)) {
$suffix = 'windows'
if ($arch -eq 'x86') {
$suffix = 'nt'
}
Invoke-WebRequest -Uri https://download.oracle.com/otn_software/nt/instantclient/instantclient-basiclite-$suffix.zip -OutFile $php_dir\instantclient.zip
Expand-Archive -Path $php_dir\instantclient.zip -DestinationPath $php_dir -Force
Copy-Item $php_dir\instantclient*\* $php_dir
}
}
# Function to install oci8 and pdo_oci.
Function Add-Oci() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateSet('oci8', 'pdo_oci')]
[string]
$extension
)
try {
$status = 'Enabled'
Add-InstantClient
if ($extension -eq "pdo_oci") {
Enable-PhpExtension pdo_oci -Path $php_dir
} else {
if(-not(Test-Path $ext_dir\php_oci8.dll)) {
$status = 'Installed and enabled'
$ociVersion = Get-PeclPackageVersion oci8 -MinimumStability stable -MaximumStability stable | Select-Object -First 1
if ($version -eq '7.0') {
$ociVersion = '2.1.8'
} elseif ($version -lt '7.0') {
$ociVersion = '2.0.12'
} elseif ($version -lt '8.0') {
$ociVersion = '2.2.0'
}
$ociUrl = Get-PeclArchiveUrl oci8 $ociVersion $installed
Invoke-WebRequest -Uri $ociUrl -OutFile $php_dir\oci8.zip
Expand-Archive -Path $php_dir\oci8.zip -DestinationPath $ext_dir -Force
}
Add-Content -Value "`r`nextension=php_oci8.dll" -Path $php_dir\php.ini
}
Add-Log $tick $extension $status
Add-LicenseLog
} catch {
Add-Log $cross $extension "Could not install $extension on PHP $( $installed.FullVersion )"
}
}

View File

@ -1,63 +0,0 @@
# Function to log result of a operation.
add_license_log() {
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "$ext" "Click to read the $ext related license information"
printf "Oracle Instant Client package is required for %s extension.\n" "$ext"
printf "It is provided under the Oracle Technology Network Development and Distribution License.\n"
printf "Refer to: \033[35;1m%s \033[0m\n" "https://www.oracle.com/downloads/licenses/instant-client-lic.html"
echo "::endgroup::"
}
# Function to install instantclient and SDK.
add_client() {
if [ ! -e "$oracle_client" ]; then
sudo mkdir -p -m 777 "$oracle_home" "$oracle_client"
for package in basiclite sdk; do
if [ "$os" = 'Linux' ]; then
libs='/usr/lib/'
os_name='linux'
arch='linuxx64'
lib_ext='so'
elif [ "$os" = 'Darwin' ]; then
libs='/usr/local/lib/'
os_name='mac'
arch='macos'
lib_ext='dylib'
fi
get -q -n "/opt/oracle/$package.zip" "https://download.oracle.com/otn_software/$os_name/instantclient/instantclient-$package-$arch.zip"
unzip -o "/opt/oracle/$package.zip" -d "$oracle_home"
done
for icdir in /opt/oracle/instantclient_*; do
sudo mv "$icdir"/* "$oracle_client"/
done
sudo ln -sf /opt/oracle/instantclient/*.$lib_ext* $libs
fi
}
# Function to install oci8 and pdo_oci.
add_oci_helper() {
if ! [ -e "${ext_dir:?}/$ext.so" ]; then
status='Installed and enabled'
read -r "${ext}_LINUX_LIBS" <<< "libaio-dev"
read -r "${ext}_CONFIGURE_OPTS" <<< "--with-php-config=$(command -v php-config) --with-${ext/_/-}=instantclient,$oracle_client"
read -r "${ext}_PATH" <<< "ext/$ext"
patch_phpize
add_extension_from_source "$ext" https://github.com php php-src "$(php_src_tag)" extension get
restore_phpize
fi
}
# Function to add oci extension oci8 and pdo_oci.
add_oci() {
ext=$1
status='Enabled'
oracle_home='/opt/oracle'
oracle_client=$oracle_home/instantclient
os=$(uname -s)
add_client >/dev/null 2>&1
add_oci_helper >/dev/null 2>&1
add_extension_log "$ext" "$status"
check_extension "$ext" && add_license_log
}
# shellcheck source=.
. "${scripts:?}"/ext/patches/phpize.sh

View File

@ -1,11 +0,0 @@
patch_firebird() {
if [[ "${version:?}" =~ ${old_versions:?} ]]; then
sudo sed -i '' '/PHP_CHECK_PDO_INCLUDES/d' config.m4 2>/dev/null || sudo sed -i '/PHP_CHECK_PDO_INCLUDES/d' config.m4
fi
lib_arch=$(gcc -dumpmachine)
lib_dir=/usr/lib/"$lib_arch"
if [ -d "$lib_dir" ]; then
sudo ln -sf "$lib_dir"/libfbclient.so.2 /usr/lib/libfbclient.so
sudo ln -sf "$lib_dir"/libib_util.so /usr/lib/
fi
}

View File

@ -1,7 +0,0 @@
patch_geos() {
if [ "$(php -r "echo PHP_VERSION_ID;")" -ge 70000 ]; then
sed -i~ -e "s/, ce->name/, ZSTR_VAL(ce->name)/; s/ulong /zend_ulong /" geos.c
fi
get -q -n /tmp/php8.patch https://git.remirepo.net/cgit/rpms/php/php-geos.git/plain/0003-add-all-arginfo-and-fix-build-with-PHP-8.patch
patch -p1 < /tmp/php8.patch 2>/dev/null || true
}

View File

@ -1,11 +0,0 @@
patch_pecl_http() {
if [ "$(uname -s)" = 'Darwin' ] && ! [[ ${version:?} =~ ${old_versions:?} ]]; then
if [[ ${version:?} =~ 5.6|7.[0-4] ]]; then
sed -i '' -e "s|ext/propro|$(brew --prefix propro@"${version:?}")/include/php/ext/propro@${version:?}|" "./src/php_http_api.h"
fi
sed -i '' -e "s|ext/raphf|$(brew --prefix raphf@"${version:?}")/include/php/ext/raphf@${version:?}|" "./src/php_http_api.h"
if [ "${version:?}" = "5.6" ]; then
sed -i '' -e "s|\$abs_srcdir|\$abs_srcdir ${brew_prefix:?}/include|" -e "s|/ext/propro|/php/ext/propro@5.6|" -e "s|/ext/raphf|/php/ext/raphf@5.6|" "./config9.m4"
fi
fi
}

View File

@ -1,6 +0,0 @@
patch_pdo_oci() {
get -q -n config.m4 https://raw.githubusercontent.com/php/php-src/PHP-8.0/ext/pdo_oci/config.m4
if [[ ${version:?} =~ 5.[3-6] ]]; then
sudo sed -i '' "/PHP_CHECK_PDO_INCLUDES/d" config.m4 2>/dev/null || sudo sed -i "/PHP_CHECK_PDO_INCLUDES/d" config.m4
fi
}

View File

@ -1,26 +0,0 @@
# Function to get phpize location on darwin.
get_phpize() {
if [[ "${version:?}" =~ 5.[3-5] ]]; then
echo '/opt/local/bin/phpize'
else
echo "/usr/local/bin/$(readlink /usr/local/bin/phpize)"
fi
}
# Function to patch phpize to link to php headers on darwin.
patch_phpize() {
if [ "$(uname -s)" = "Darwin" ]; then
sudo cp "$phpize_orig" "$phpize_orig.bck"
sudo sed -i '' 's~includedir=.*~includedir="$(xcrun --show-sdk-path)/usr/include/php"~g' "$phpize_orig"
fi
}
# Function to restore phpize.
restore_phpize() {
if [ "$os" = "Darwin" ]; then
sudo mv "$phpize_orig.bck" "$phpize_orig" || true
fi
}
os="$(uname -s)"
phpize_orig="$(get_phpize)"

View File

@ -1,4 +0,0 @@
patch_protobuf() {
mkdir -p third_party/wyhash
cp ../../../../third_party/wyhash/* third_party/wyhash
}

View File

@ -1,54 +1,56 @@
# Function to install phalcon Param (
Function Add-PhalconHelper() {
if ($extension_version -eq '4') {
Install-Phpextension -Extension phalcon -MinimumStability stable -Path $php_dir
} else {
$domain = 'https://github.com'
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
$match = Invoke-WebRequest -Uri "$domain/phalcon/cphalcon/releases/v3.4.5" | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`""
$zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll"
Enable-PhpExtension -Extension phalcon -Path $php_dir
}
}
Function Add-Phalcon() {
Param (
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()] [ValidateNotNull()]
[ValidateSet('phalcon3', 'phalcon4')] [ValidateSet('phalcon3', 'phalcon4')]
[string] [string]
$extension $extension,
) [Parameter(Position = 1, Mandatory = $true)]
try { [ValidateNotNull()]
$status = 'Enabled' [ValidateLength(1, [int]::MaxValue)]
$extension_version = $extension.substring($extension.Length - 1) [string]
$version
)
if($extension_version -eq '4') { # Function to install phalcon
if (Test-Path $ext_dir\php_psr.dll) { Function Install-Phalcon() {
Enable-PhpExtension -Extension psr -Path $php_dir if ($extension_version -eq '4') {
} else { Install-Phpextension phalcon -MinimumStability stable -Path $php_dir
Install-Phpextension -Extension psr -MinimumStability stable -Path $php_dir
}
}
if(Test-Path $ext_dir\php_phalcon.dll) {
$phalcon = Get-PhpExtension $ext_dir\php_phalcon.dll
if($phalcon.Version[0] -eq $extension_version) {
Enable-PhpExtension -Extension phalcon -Path $php_dir
} else {
$status = 'Installed and enabled'
Remove-Item $ext_dir\php_phalcon.dll
Add-PhalconHelper
}
} else { } else {
$status = 'Installed and enabled' $installed = Get-Php -Path $php_dir
Add-PhalconHelper $nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
$match = Invoke-WebRequest -UseBasicParsing -Uri "$domain/phalcon/cphalcon/releases/v3.4.5" | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`""
$zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll"
Enable-PhpExtension -Extension phalcon -Path $php_dir
} }
Add-Log $tick $extension $status printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled"
} catch [Exception] {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
} }
$tick = ([char]8730)
$domain = 'https://github.com'
$php_dir = 'C:\tools\php'
$ext_dir = $php_dir + '\ext'
$extension_version = $extension.substring($extension.Length - 1)
if($extension_version -eq '4') {
if (Test-Path $ext_dir\php_psr.dll) {
Enable-PhpExtension -Extension psr -Path $php_dir
} else {
Install-Phpextension psr -MinimumStability stable -Path $php_dir
}
}
if(Test-Path $ext_dir\php_phalcon.dll) {
$phalcon = Get-PhpExtension $ext_dir\php_phalcon.dll
if($phalcon.Version[0] -eq $extension_version) {
Enable-PhpExtension -Extension phalcon -Path $php_dir
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Enabled"
} else {
Remove-Item $ext_dir\php_phalcon.dll
Install-Phalcon
}
} else {
Install-Phalcon
}

View File

@ -1,58 +1,71 @@
# Helper function to add phalcon. # Function to log result of a operation
add_phalcon_helper() { add_log() {
status='Installed and enabled' mark=$1
if [ "$extension" = "phalcon4" ]; then subject=$2
install_packages "php${version:?}-psr" "php${version:?}-$extension" message=$3
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" "$message"
else else
install_packages "php${version:?}-$extension" printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi fi
} }
# Function to add phalcon3. # Function to update php ppa
add_phalcon3() { update_ppa() {
if [ -e "${ext_dir:?}/phalcon.so" ]; then if [ "$ppa_updated" = "false" ]; then
phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1) find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-get update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
if [ "$phalcon_version" != "$extension_major_version" ]; then ppa_updated="true"
add_phalcon_helper
else
echo "extension=phalcon.so" | sudo tee -a "$phalcon_ini_file"
fi
else
add_phalcon_helper
fi fi
} }
# Function to add phalcon4. # Function to install phalcon
add_phalcon4() { install_phalcon() {
if [ -e "${ext_dir:?}/psr.so" ] && ! php -m | grep -i -q -w psr; then local extension=$1
echo "extension=psr.so" | sudo tee -a "${ini_file:?}" version=$2
(update_ppa && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "php$version-psr" "php$version-$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
}
ini_file="/etc/php/$2/cli/conf.d/50-phalcon.ini"
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
extension_major_version=$(echo "$1" | grep -i -Po '\d')
ppa_updated="false"
tick="✓"
cross="✗"
if [ "$extension_major_version" = "4" ]; then
if [ -e "$ext_dir/psr.so" ] && ! php -m | grep -i -q -w psr; then
echo "extension=psr.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
fi fi
if [ -e "$ext_dir/phalcon.so" ]; then if [ -e "$ext_dir/phalcon.so" ]; then
if php -m | grep -i -q -w psr; then if php -m | grep -i -q -w psr; then
phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1) phalcon_version=$(php -d="extension=phalcon" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then if [ "$phalcon_version" != "$extension_major_version" ]; then
add_phalcon_helper install_phalcon "$1" "$2"
else else
echo "extension=phalcon.so" | sudo tee -a "$phalcon_ini_file" echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_log "$tick" "$1" "Enabled"
fi fi
else else
add_phalcon_helper install_phalcon "$1" "$2"
fi fi
else else
add_phalcon_helper install_phalcon "$1" "$2"
fi fi
} fi
# Function to add phalcon. if [ "$extension_major_version" = "3" ]; then
add_phalcon() { if [ -e "$ext_dir/phalcon.so" ]; then
extension=$1 phalcon_version=$(php -d="extension=phalcon.so" -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
status='Enabled' if [ "$phalcon_version" != "$extension_major_version" ]; then
phalcon_ini_file="${pecl_file:-${ini_file[@]}}" install_phalcon "$1" "$2"
extension_major_version=${extension: -1} else
if [ "$extension_major_version" = "4" ]; then echo "extension=phalcon.so" | sudo tee -a "$ini_file" >/dev/null 2>&1
add_phalcon4 >/dev/null 2>&1 add_log "$tick" "$1" "Enabled"
elif [ "$extension_major_version" = "3" ]; then fi
add_phalcon3 >/dev/null 2>&1 else
install_phalcon "$1" "$2"
fi fi
add_extension_log "phalcon" "$status" fi
}

View File

@ -1,144 +0,0 @@
# Function to parse extension environment variables
parse_args() {
extension=$1
suffix=$(echo "$2" | tr '[:lower:]' '[:upper:]')
up_ext_name=$(echo "$extension" | tr '[:lower:]' '[:upper:]')
var="${extension}_${suffix}"
up_var="${up_ext_name}_${suffix}"
! [[ "$suffix" =~ .*PREFIX|LIBS|PATH.* ]] && hyp='-'
output=$(echo "${!var} ${!up_var}" | sed "s/, *$hyp/ $hyp/g" | sed -E "s/^,|,$//g")
echo "$output" | xargs -n 1 | sort | uniq | xargs
}
# Function to log if a library is installed
add_lib_log() {
lib=$1
if check_lib "$lib"; then
add_log "${tick:?}" "$lib" "Installed"
else
add_log "${cross:?}" "$lib" "Could not install $lib"
fi
}
# Function to check if a library is installed
check_lib() {
lib=$1
if [ "$(uname -s)" = "Linux" ]; then
[ "x$(dpkg -s "$lib" 2>/dev/null | grep Status)" != "x" ]
else
[ "x$(find "${brew_prefix:?}"/Cellar -maxdepth 1 -name "$lib")" != "x" ]
fi
}
# Function to add a library on linux
add_linux_libs() {
lib=$1
if ! check_lib "$lib"; then
install_packages "$lib" >/dev/null 2>&1 || true
fi
add_lib_log "$lib"
}
# Function to add a library on macOS
add_darwin_libs() {
lib=$1
if ! check_lib "$lib"; then
brew install "$lib" >/dev/null 2>&1 || true
if [[ "$lib" = *@* ]]; then
brew link --overwrite --force "$lib" >/dev/null 2>&1 || true
fi
fi
add_lib_log "$lib"
}
# Function to add required libraries
add_libs() {
all_libs=("$@")
for lib in "${all_libs[@]}"; do
if [ "$(uname -s)" = "Linux" ]; then
add_linux_libs "$lib"
else
add_darwin_libs "$lib"
fi
done
}
# Function to run command in a group
run_group() {
command=$1
log=$2
echo "$command" | sudo tee ./run_group.sh >/dev/null 2>&1
echo "::group::$log"
. ./run_group.sh
rm ./run_group.sh
echo "::endgroup::"
}
patch_extension() {
extension=$1
if [ -e "${scripts:?}"/ext/patches/"$extension".sh ]; then
# shellcheck source=.
. "${scripts:?}"/ext/patches/"$extension".sh
patch_"${extension}"
fi
}
fetch_extension() {
fetch=$1
if [ "$fetch" = "clone" ]; then
run_group "git clone -nv $url/$org/$repo /tmp/$repo-$release" "git clone"
cd /tmp/"$repo-$release" || exit 1
git checkout -q "$release"
cd "$sub_dir" || exit 1
if [ -e .gitmodules ]; then
jobs="$(grep -c "\[submodule" .gitmodules)"
run_group "git submodule update --jobs $jobs --init --recursive" "git submodule"
fi
elif [ "$fetch" = "get" ]; then
get -q -n /tmp/"$extension".tar.gz "$url/$org/$repo/archive/$release.tar.gz"
tar -xzf /tmp/"$extension".tar.gz -C /tmp
cd /tmp/"$repo"-"$release"/"$sub_dir" || exit
elif [ "$fetch" = "pecl" ]; then
source="pecl"
pecl_name=${extension/http/pecl_http}
get -q -n /tmp/"$pecl_name".tgz https://pecl.php.net/get/"$pecl_name"-"$release".tgz
tar -xzf /tmp/"$pecl_name".tgz -C /tmp
cd /tmp/"$pecl_name"-"$release" || exit
fi
}
# Function to install extension from a git repository
add_extension_from_source() {
extension="${1/pecl_/}"
url=$2
org=$3
repo=$4
release=$5
prefix=$6
fetch=${7:-clone}
slug="$extension-$release"
source="$url/$org/$repo"
libraries="$(parse_args "$extension" LIBS) $(parse_args "$extension" "$(uname -s)"_LIBS)"
opts="$(parse_args "$extension" CONFIGURE_OPTS)"
prefix_opts="$(parse_args "$extension" CONFIGURE_PREFIX_OPTS)"
suffix_opts="$(parse_args "$extension" CONFIGURE_SUFFIX_OPTS)"
sub_dir="$(parse_args "$extension" PATH)"
step_log "Setup $slug"
(
add_devtools phpize >/dev/null 2>&1
delete_extension "$extension"
fetch_extension "$fetch"
if ! [ "$(find . -maxdepth 1 -name '*.m4' -exec grep -H 'PHP_NEW_EXTENSION' {} \; | wc -l)" != "0" ]; then
add_log "${cross:?}" "$source" "$source does not have a PHP extension"
else
[[ -n "${libraries// }" ]] && run_group "add_libs $libraries" "add libraries"
patch_extension "$extension" >/dev/null 2>&1
run_group "phpize" "phpize"
run_group "sudo $prefix_opts ./configure $suffix_opts $opts" "configure"
run_group "sudo make -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)" "make"
run_group "sudo make install" "make install"
enable_extension "$extension" "$prefix"
fi
)
add_extension_log "$slug" "Installed from $source and enabled"
}

View File

@ -1,256 +1,361 @@
# Function to setup environment for self-hosted runners. # Function to log start of a operation
self_hosted_helper() { step_log() {
if ! command -v sudo >/dev/null; then message=$1
apt-get update printf "\n\033[90;1m==> \033[0m\033[37;1m%s\033[0m\n" "$message"
apt-get install -y sudo || add_log "${cross:?}" "sudo" "Could not install sudo" }
# Function to log result of a operation
add_log() {
mark=$1
subject=$2
message=$3
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" "$message"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi fi
if ! command -v apt-fast >/dev/null; then }
sudo ln -sf /usr/bin/apt-get /usr/bin/apt-fast
trap "sudo rm -f /usr/bin/apt-fast 2>/dev/null" exit # Function to backup and cleanup package lists.
cleanup_lists() {
ppa_prefix=${1-ondrej}
if [ ! -e /etc/apt/sources.list.d.save ]; then
sudo mv /etc/apt/sources.list.d /etc/apt/sources.list.d.save
sudo mkdir /etc/apt/sources.list.d
sudo mv /etc/apt/sources.list.d.save/*"${ppa_prefix}"*.list /etc/apt/sources.list.d/
trap "sudo mv /etc/apt/sources.list.d.save/*.list /etc/apt/sources.list.d/ 2>/dev/null" exit
fi fi
install_packages apt-transport-https ca-certificates curl file make jq unzip autoconf automake gcc g++ gnupg
} }
# Function to install a package # Function to add ppa:ondrej/php.
install_packages() { add_ppa() {
packages=("$@") ppa=${1:-ondrej/php}
[[ "${packages[*]}" =~ php ]] && add_ppa ondrej/php >/dev/null 2>&1 if ! apt-cache policy | grep -q "$ppa"; then
$apt_install "${packages[@]}" >/dev/null 2>&1 || (update_lists && $apt_install "${packages[@]}" >/dev/null 2>&1) cleanup_lists "$(dirname "$ppa")"
LC_ALL=C.UTF-8 sudo apt-add-repository ppa:"$ppa" -y
fi
} }
# Function to disable an extension. # Function to update the package lists.
disable_extension() { update_lists() {
extension=$1 if [ ! -e /tmp/setup_php ]; then
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "${ini_file[@]}" add_ppa ondrej/php >/dev/null 2>&1
sudo sed -Ei "/=(.*\/)?\"?$extension(.so)?$/d" "$pecl_file" cleanup_lists
sudo find "$ini_dir"/.. -name "*$extension.ini" -delete >/dev/null 2>&1 || true sudo "$debconf_fix" apt-get update >/dev/null 2>&1
echo '' | sudo tee /tmp/setup_php >/dev/null 2>&1
fi
} }
# Function to delete an extension. # Function to configure PECL
configure_pecl() {
if ! [ -e /tmp/pecl_config ]; then
if ! command -v pecl >/dev/null || ! command -v pear >/dev/null; then
add_pecl >/dev/null 2>&1
fi
for script in pear pecl; do
sudo "$script" config-set php_ini "${pecl_file:-$ini_file}" >/dev/null 2>&1
sudo "$script" channel-update "$script".php.net >/dev/null 2>&1
done
echo '' | sudo tee /tmp/pecl_config >/dev/null 2>&1
fi
}
# Function to get the PECL version
get_pecl_version() {
local extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "([0-9]+\.[0-9]+\.[0-9]+${stability}[0-9]+)")
if [ ! "$pecl_version" ]; then
pecl_version=$(echo "$response" | grep -m 1 -Eo "([0-9]+\.[0-9]+\.[0-9]+)")
fi
echo "$pecl_version"
}
# Function to install PECL extensions and accept default options
pecl_install() {
local extension=$1
yes '' | sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to enable existing extensions.
enable_extension() {
sudo find /var/lib/php/modules/"$version" -path "*disabled*$1" -delete
if ! check_extension "$1" && [ -e "$ext_dir/$1.so" ]; then
echo "$2=$ext_dir/$1.so" | sudo tee -a "$pecl_file" >/dev/null
fi
}
# Function to test if extension is loaded
check_extension() {
local extension=$1
if [ "$extension" != "mysql" ]; then
php -m | grep -i -q -w "$extension"
else
php -m | grep -i -q "$extension"
fi
}
# Function to delete extensions
delete_extension() { delete_extension() {
extension=$1 local extension=$1
disable_extension "$extension" sudo sed -Ei "/=(.*\/)?\"?$extension/d" "$ini_file"
sudo sed -Ei "/=(.*\/)?\"?$extension/d" "$pecl_file"
sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1 sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1
sudo sed -i "/Package: php$version-$extension/,/^$/d" /var/lib/dpkg/status sudo sed -i "/Package: php$version-$extension/,/^$/d" /var/lib/dpkg/status
} }
# Function to disable and delete extensions. # Function to disable and delete extensions
remove_extension() { remove_extension() {
extension=$1 local extension=$1
if check_extension "$extension"; then if [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then
if [[ ! "$version" =~ ${old_versions:?} ]] && [ -e /etc/php/"$version"/mods-available/"$extension".ini ]; then sudo phpdismod -v "$version" "$extension"
sudo phpdismod -v "$version" "$extension" >/dev/null 2>&1
fi
delete_extension "$extension"
(! check_extension "$extension" && add_log "${tick:?}" ":$extension" "Removed") ||
add_log "${cross:?}" ":$extension" "Could not remove $extension on PHP ${semver:?}"
else
delete_extension "$extension"
add_log "${tick:?}" ":$extension" "Could not find $extension on PHP $semver"
fi fi
delete_extension "$extension"
} }
# Function to add PDO extension. # Function to setup extensions
add_pdo_extension() {
pdo_ext="pdo_$1"
if check_extension "$pdo_ext"; then
add_log "${tick:?}" "$pdo_ext" "Enabled"
else
ext=$1
ext_name=$1
if [ -e "$ext_dir"/pdo.so ]; then
disable_extension pdo
echo "extension=pdo.so" | sudo tee "${ini_file[@]/php.ini/conf.d/10-pdo.ini}" >/dev/null 2>&1
fi
if [ "$ext" = "mysql" ]; then
enable_extension "mysqlnd" "extension"
ext_name='mysqli'
elif [ "$ext" = "dblib" ]; then
ext_name="sybase"
elif [ "$ext" = "firebird" ]; then
install_packages libfbclient2 >/dev/null 2>&1
enable_extension "pdo_firebird" "extension"
ext_name="interbase"
elif [ "$ext" = "sqlite" ]; then
ext="sqlite3"
ext_name="sqlite3"
fi
add_extension "$ext_name" "extension" >/dev/null 2>&1
add_extension "$pdo_ext" "extension" >/dev/null 2>&1
add_extension_log "$pdo_ext" "Enabled"
fi
}
# Function to add extensions.
add_extension() { add_extension() {
extension=$1 local extension=$1
prefix=$2 install_command=$2
prefix=$3
enable_extension "$extension" "$prefix" enable_extension "$extension" "$prefix"
if check_extension "$extension"; then if check_extension "$extension"; then
add_log "${tick:?}" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! check_extension "$extension"; then
eval "$install_command" >/dev/null 2>&1 ||
(update_lists && eval "$install_command" >/dev/null 2>&1) || pecl_install "$extension"
(check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
fi
sudo chmod 777 "$ini_file"
}
# Function to install a PECL version
add_pecl_extension() {
local extension=$1
pecl_version=$2
prefix=$3
configure_pecl
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi
enable_extension "$extension" "$prefix"
ext_version=$(php -r "echo phpversion('$extension');")
if [ "$ext_version" = "$pecl_version" ]; then
add_log "$tick" "$extension" "Enabled"
else else
if [[ "$version" =~ ${nightly_versions:?} ]]; then delete_extension "$extension"
pecl_install "$extension" (
else sudo pecl install -f "$extension-$pecl_version" >/dev/null 2>&1 &&
install_packages "php$version-$extension" || pecl_install "$extension" check_extension "$extension" &&
fi add_log "$tick" "$extension" "Installed and enabled"
add_extension_log "$extension" "Installed and enabled" ) || add_log "$cross" "$extension" "Could not install $extension-$pecl_version on PHP $semver"
fi fi
sudo chmod 777 "${ini_file[@]}"
} }
# Function to setup phpize and php-config. # Function to pre-release extensions using PECL
add_devtools() { add_unstable_extension() {
local extension=$1
stability=$2
prefix=$3
pecl_version=$(get_pecl_version "$extension" "$stability")
add_pecl_extension "$extension" "$pecl_version" "$prefix"
}
# Function to configure composer
configure_composer() {
tool_path=$1
sudo ln -sf "$tool_path" "$tool_path.phar"
php -r "try {\$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception \$e) {exit(1);}"
if [ $? -eq 1 ]; then
add_log "$cross" "composer" "Could not download composer"
exit 1;
fi
if ! [ -d "$composer_home" ]; then
sudo -u "$(id -un)" -g "$(id -gn)" mkdir -p -m=00755 "$composer_home"
else
sudo chown -R "$(id -un)":"$(id -gn)" "$composer_home"
fi
if ! [ -e "$composer_json" ]; then
echo '{}' | tee "$composer_json" >/dev/null
chmod 644 "$composer_json"
fi
composer -q config -g process-timeout 0
echo "$composer_bin" >> "$GITHUB_PATH"
if [ -n "$COMPOSER_TOKEN" ]; then
composer -q config -g github-oauth.github.com "$COMPOSER_TOKEN"
fi
}
# Function to setup a remote tool.
add_tool() {
url=$1
tool=$2
tool_path="$tool_path_dir/$tool"
if [ ! -e "$tool_path" ]; then
rm -rf "$tool_path"
fi
if [ "$tool" = "composer" ]; then
IFS="," read -r -a urls <<< "$url"
status_code=$(sudo curl -f -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[0]}") ||
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "${urls[1]}")
else
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
if [ "$status_code" != "200" ] && [[ "$url" =~ .*github.com.*releases.*latest.* ]]; then
url="${url//releases\/latest\/download/releases/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)}"
status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url")
fi
if [ "$status_code" = "200" ]; then
sudo chmod a+x "$tool_path"
if [ "$tool" = "composer" ]; then
configure_composer "$tool_path"
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path"
elif [ "$tool" = "phive" ]; then
add_extension curl "$apt_install php$version-curl" extension >/dev/null 2>&1
add_extension mbstring "$apt_install php$version-mbstring" extension >/dev/null 2>&1
add_extension xml "$apt_install php$version-xml" extension >/dev/null 2>&1
fi
add_log "$tick" "$tool" "Added"
else
add_log "$cross" "$tool" "Could not setup $tool"
[ "$tool" = "composer" ] && exit 1
fi
}
# Function to setup a tool using composer
add_composertool() {
tool=$1 tool=$1
if ! command -v "$tool$version" >/dev/null; then release=$2
install_packages "php$version-dev" "php$version-xml" prefix=$3
(
sudo rm -f "$composer_lock" >/dev/null 2>&1 || true
composer global require "$prefix$release" >/dev/null 2>&1 &&
add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool"
if [ -e "$composer_bin/composer" ]; then
sudo cp -p "$tool_path_dir/composer" "$composer_bin"
fi fi
switch_version "phpize" "php-config" if [ "$tool" = "codeception" ]; then
add_log "${tick:?}" "$tool" "Added $tool $semver" sudo ln -s "$composer_bin"/codecept "$composer_bin"/codeception
}
# Function to setup the nightly build from shivammathur/php-builder
setup_nightly() {
run_script "php-builder" "${runner:?}" "$version"
}
# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5.
setup_old_versions() {
run_script "php5-ubuntu" "$version"
}
# Function to add PECL.
add_pecl() {
add_devtools phpize >/dev/null 2>&1
if ! command -v pecl >/dev/null; then
install_packages php-pear
fi fi
configure_pecl >/dev/null 2>&1
pecl_version=$(get_tool_version "pecl" "version")
add_log "${tick:?}" "PECL" "Added PECL $pecl_version"
} }
# Function to switch versions of PHP binaries. # Function to setup phpize and php-config
switch_version() { add_devtools() {
tools=("$@") && ! (( ${#tools[@]} )) && tools+=(pear pecl php phar phar.phar php-cgi php-config phpize phpdbg) if ! [ -e "/usr/bin/phpize$version" ] || ! [ -e "/usr/bin/php-config$version" ]; then
to_wait=() update_lists && $apt_install php"$version"-dev php"$version"-xml >/dev/null 2>&1
for tool in "${tools[@]}"; do fi
if [ -e "/usr/bin/$tool$version" ]; then sudo update-alternatives --set php-config /usr/bin/php-config"$version" >/dev/null 2>&1
sudo update-alternatives --set "$tool" /usr/bin/"$tool$version" & sudo update-alternatives --set phpize /usr/bin/phpize"$version" >/dev/null 2>&1
to_wait+=($!) configure_pecl
fi }
done
wait "${to_wait[@]}" # Function to setup the nightly build from master branch
setup_master() {
curl "${curl_opts[@]}" https://github.com/shivammathur/php-builder/releases/latest/download/install.sh | bash -s "github"
} }
# Function to install packaged PHP
add_packaged_php() { add_packaged_php() {
if [ "$runner" = "self-hosted" ] || [ "${use_package_cache:-true}" = "false" ]; then if [ "${use_package_cache:-true}" = "false" ]; then
update_lists update_lists
IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")" IFS=' ' read -r -a packages <<<"$(echo "cli curl mbstring xml intl" | sed "s/[^ ]*/php$version-&/g")"
install_packages "${packages[@]}" $apt_install "${packages[@]}"
else else
run_script "php-ubuntu" "$version" curl "${curl_opts[@]}" https://github.com/shivammathur/php-ubuntu/releases/latest/download/install.sh | bash -s "$version"
fi fi
} }
# Function to update PHP. # Function to setup PECL
update_php() { add_pecl() {
initial_version=$(php_semver) add_devtools
add_packaged_php if [ ! -e /usr/bin/pecl ]; then
updated_version=$(php_semver) $apt_install php-pear >/dev/null 2>&1
if [ "$updated_version" != "$initial_version" ]; then
status="Updated to"
else
status="Switched to"
fi fi
configure_pecl
add_log "$tick" "PECL" "Added"
} }
# Function to install PHP. # Function to switch versions of PHP binaries
add_php() { switch_version() {
if [[ "$version" =~ ${nightly_versions:?} ]]; then for tool in pear pecl php phar phar.phar php-cgi php-config phpize phpdbg; do
setup_nightly if [ -e "/usr/bin/$tool$version" ]; then
elif [[ "$version" =~ ${old_versions:?} ]]; then sudo update-alternatives --set $tool /usr/bin/"$tool$version"
setup_old_versions fi
else
add_packaged_php
fi
status="Installed"
}
# Function to ini file for pear and link it to each SAPI.
link_pecl_file() {
echo '' | sudo tee "$pecl_file" >/dev/null 2>&1
for file in "${ini_file[@]}"; do
sapi_scan_dir="$(realpath -m "$(dirname "$file")")/conf.d"
[ "$sapi_scan_dir" != "$scan_dir" ] && ! [ -h "$sapi_scan_dir" ] && sudo ln -sf "$pecl_file" "$sapi_scan_dir/99-pecl.ini"
done done
} }
# Function to get extra version. # Function to get PHP version in semver format
php_extra_version() { php_semver() {
if [[ ${version:?} =~ ${nightly_versions:?} ]]; then if [ ! "$version" = "8.0" ]; then
echo " ($(cat "/etc/php/$version/COMMIT"))" 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 fi
} }
# Function to Setup PHP # Function to configure PHP
setup_php() { configure_php() {
step_log "Setup PHP" (
sudo mkdir -m 777 -p /var/run /run/php echo -e "date.timezone=UTC\nmemory_limit=-1"
if [ "$(php-config --version 2>/dev/null | cut -c 1-3)" != "$version" ]; then [[ "$version" =~ 8.0 ]] && echo -e "opcache.enable=1\nopcache.jit_buffer_size=256M\nopcache.jit=1235"
if [ ! -e "/usr/bin/php$version" ]; then [[ "$version" =~ 7.[2-4]|8.0 ]] && echo -e "xdebug.mode=coverage"
add_php >/dev/null 2>&1 ) | sudo tee -a "$pecl_file" >/dev/null
else
if [ "${update:?}" = "true" ]; then
update_php >/dev/null 2>&1
else
status="Switched to"
fi
fi
if ! [[ "$version" =~ ${old_versions:?}|${nightly_versions:?} ]]; then
switch_version >/dev/null 2>&1
fi
else
if [ "$update" = "true" ]; then
update_php >/dev/null 2>&1
else
status="Found"
fi
fi
if ! command -v php"$version" >/dev/null; then
add_log "$cross" "PHP" "Could not setup PHP $version"
exit 1
fi
semver=$(php_semver)
extra_version=$(php_extra_version)
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
ini_dir=$(php --ini | grep "(php.ini)" | sed -e "s|.*: s*||")
pecl_file="$scan_dir"/99-pecl.ini
mapfile -t ini_file < <(sudo find "$ini_dir/.." -name "php.ini" -exec readlink -m {} +)
link_pecl_file
configure_php
sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1
sudo chmod 777 "${ini_file[@]}" "$pecl_file" "${tool_path_dir:?}"
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
echo "::set-output name=php-version::$semver"
add_log "${tick:?}" "PHP" "$status PHP $semver$extra_version"
} }
# Variables # Variables
tick="✓"
cross="✗"
version=$1 version=$1
dist=$2 dist=$2
debconf_fix="DEBIAN_FRONTEND=noninteractive" debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends" apt_install="sudo $debconf_fix apt-fast install -y --no-install-recommends"
scripts="${dist}"/../src/scripts tool_path_dir="/usr/local/bin"
curl_opts=(-sL)
composer_home="$HOME/.composer"
composer_bin="$composer_home/vendor/bin"
composer_json="$composer_home/composer.json"
composer_lock="$composer_home/composer.lock"
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
. /etc/os-release # Setup PHP
# shellcheck source=. step_log "Setup PHP"
. "${scripts:?}"/ext/source.sh sudo mkdir -m 777 -p "$HOME/.composer" /var/run /run/php
. "${scripts:?}"/tools/ppa.sh . /etc/lsb-release
. "${scripts:?}"/tools/add_tools.sh
. "${scripts:?}"/common.sh if [ "$existing_version" != "$version" ]; then
read_env if [ ! -e "/usr/bin/php$version" ]; then
self_hosted_setup if [ "$version" = "8.0" ]; then
setup_php setup_master >/dev/null 2>&1
else
add_packaged_php >/dev/null 2>&1
fi
status="Installed"
else
status="Switched to"
fi
switch_version >/dev/null 2>&1
else
status="Found"
fi
if ! command -v php"$version" >/dev/null; then
add_log "$cross" "PHP" "Could not setup PHP $version"
exit 1
fi
semver=$(php_semver)
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
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*||")
pecl_file="$scan_dir"/99-pecl.ini
echo '' | sudo tee "$pecl_file" >/dev/null 2>&1
configure_php
sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1
sudo chmod 777 "$ini_file" "$pecl_file" "$tool_path_dir"
sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/"
add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -1,26 +0,0 @@
Function Add-ToolsHelper() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
$tool
)
if($tool -eq "codeception") {
Copy-Item $composer_bin\codecept.bat -Destination $composer_bin\codeception.bat
} elseif($tool -eq "composer") {
Edit-ComposerConfig $bin_dir\$tool
} elseif($tool -eq "cs2pr") {
(Get-Content $bin_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $bin_dir/cs2pr
} elseif($tool -eq "phan") {
Add-Extension fileinfo >$null 2>&1
Add-Extension ast >$null 2>&1
} elseif($tool -eq "phive") {
Add-Extension xml >$null 2>&1
} elseif($tool -eq "symfony-cli") {
Add-ToProfile $current_profile "symfony" "New-Alias symfony $bin_dir\symfony-cli.exe"
Add-ToProfile $current_profile "symfony_cli" "New-Alias symfony-cli $bin_dir\symfony-cli.exe"
} elseif($tool -match "vapor-cli") {
Copy-Item $composer_bin\vapor.bat -Destination $composer_bin\vapor-cli.bat
} elseif($tool -eq "wp-cli") {
Copy-Item $bin_dir\wp-cli.bat -Destination $bin_dir\wp.bat
}
}

View File

@ -1,20 +0,0 @@
add_tools_helper() {
tool=$1
if [ "$tool" = "codeception" ]; then
sudo ln -s "${composer_bin:?}"/codecept "${composer_bin:?}"/codeception
elif [ "$tool" = "composer" ]; then
configure_composer "${tool_path:?}"
elif [ "$tool" = "cs2pr" ]; then
sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "${tool_path:?}" 2>/dev/null ||
sudo sed -i '' 's/\r$//; s/exit(9)/exit(0)/' "${tool_path:?}"
elif [ "$tool" = "phan" ]; then
add_extension fileinfo extension >/dev/null 2>&1
add_extension ast extension >/dev/null 2>&1
elif [ "$tool" = "phive" ]; then
add_extension curl extension >/dev/null 2>&1
add_extension mbstring extension >/dev/null 2>&1
add_extension xml extension >/dev/null 2>&1
elif [[ "$tool" =~ (symfony|vapor|wp)-cli ]]; then
sudo ln -s "${tool_path:?}" "${tool_path_dir:?}"/${tool%-*}
fi
}

View File

@ -1,19 +0,0 @@
# Function to add blackfire cli.
Function Add-Blackfire() {
$arch_name ='amd64'
if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') {
$arch_name = '386'
}
$cli_version = (Invoke-RestMethod https://blackfire.io/api/v1/releases).cli
$url = "https://packages.blackfire.io/binaries/blackfire/${cli_version}/blackfire-windows_${arch_name}.zip"
Invoke-WebRequest -Uri $url -OutFile $bin_dir\blackfire.zip >$null 2>&1
Expand-Archive -Path $bin_dir\blackfire.zip -DestinationPath $bin_dir -Force >$null 2>&1
Add-ToProfile $current_profile 'blackfire' "New-Alias blackfire $bin_dir\blackfire.exe"
if ((Test-Path env:BLACKFIRE_SERVER_ID) -and (Test-Path env:BLACKFIRE_SERVER_TOKEN)) {
blackfire agent:config --server-id=$env:BLACKFIRE_SERVER_ID --server-token=$env:BLACKFIRE_SERVER_TOKEN >$null 2>&1
}
if ((Test-Path env:BLACKFIRE_CLIENT_ID) -and (Test-Path env:BLACKFIRE_CLIENT_TOKEN)) {
blackfire client:config --client-id=$env:BLACKFIRE_CLIENT_ID --client-token=$env:BLACKFIRE_CLIENT_TOKEN --ca-cert=$php_dir\ssl\cacert.pem >$null 2>&1
}
Add-Log $tick "blackfire" "Added blackfire $cli_version"
}

View File

@ -1,39 +0,0 @@
add_blackfire_linux() {
sudo mkdir -p /var/run/blackfire
add_list debian/blackfire http://packages.blackfire.io/debian https://packages.blackfire.io/gpg.key any main
install_packages blackfire
}
add_blackfire_darwin() {
sudo mkdir -p /usr/local/var/run
add_brew_tap blackfireio/homebrew-blackfire
brew install blackfire
}
blackfire_config() {
if [[ -n $BLACKFIRE_SERVER_ID ]] && [[ -n $BLACKFIRE_SERVER_TOKEN ]]; then
blackfire agent:config --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN"
if [ "$os" = "Linux" ]; then
if [ -d /run/systemd/system ]; then
sudo systemctl start blackfire-agent
else
sudo service blackfire-agent start
fi
elif [ "$os" = "Darwin" ]; then
brew services start blackfire
fi
fi
if [[ -n $BLACKFIRE_CLIENT_ID ]] && [[ -n $BLACKFIRE_CLIENT_TOKEN ]]; then
blackfire client:config --client-id="$BLACKFIRE_CLIENT_ID" --client-token="$BLACKFIRE_CLIENT_TOKEN"
fi
}
# Function to add blackfire cli.
add_blackfire() {
os="$(uname -s)"
[ "$os" = "Linux" ] && add_blackfire_linux >/dev/null 2>&1
[ "$os" = "Darwin" ] && add_blackfire_darwin >/dev/null 2>&1
blackfire_config >/dev/null 2>&1
tool_version=$(get_tool_version "blackfire" "version")
add_log "${tick:?}" "blackfire" "Added blackfire $tool_version"
}

View File

@ -1,21 +0,0 @@
Function Add-Msys2() {
$msys_location = 'C:\msys64'
if (-not(Test-Path $msys_location)) {
choco install msys2 -y >$null 2>&1
$msys_location = 'C:\tools\msys64'
}
return $msys_location
}
Function Add-Grpc_php_plugin() {
$msys_location = Add-Msys2
$logs = . $msys_location\usr\bin\bash -l -c "pacman -S --noconfirm mingw-w64-x86_64-grpc" >$null 2>&1
$grpc_version = Get-ToolVersion 'Write-Output' "$logs"
Write-Output "$msys_location\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8
Write-Output "::set-output name=grpc_php_plugin_path::$msys_location\mingw64\bin\grpc_php_plugin.exe"
Add-ToProfile $current_profile 'grpc_php_plugin' "New-Alias grpc_php_plugin $msys_location\mingw64\bin\grpc_php_plugin.exe"
Add-Log $tick "grpc_php_plugin" "Added grpc_php_plugin $grpc_version"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "grpc_php_plugin" "Click to read the grpc_php_plugin related license information"
Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/grpc/grpc/master/LICENSE).Content
Write-Output "::endgroup::"
}

View File

@ -1,58 +0,0 @@
add_bazel() {
if ! command -v bazel; then
if [ "$(uname -s)" = "Linux" ]; then
add_list bazel/apt https://storage.googleapis.com/bazel-apt https://bazel.build/bazel-release.pub.gpg stable jdk1.8
install_packages bazel
else
brew install bazel
fi
fi
}
get_grpc_tag() {
if [ "$grpc_tag" = "latest" ]; then
grpc_tag=$(get -s -n "" https://github.com/grpc/grpc/releases/latest | grep -Eo -m 1 "v[0-9]+\.[0-9]+\.[0-9]+" | head -n 1)
else
if [[ ${grpc_tag:0:1} != "v" ]] ; then grpc_tag="v$grpc_tag"; fi
status_code=$(get -v -n /tmp/grpc.tmp "https://github.com/grpc/grpc/releases/tag/$grpc_tag")
if [ "$status_code" != "200" ]; then
grpc_tag=$(get -s -n "" https://github.com/grpc/grpc/releases/latest | grep -Eo -m 1 "v[0-9]+\.[0-9]+\.[0-9]+" | head -n 1)
fi
fi
}
add_grpc_php_plugin_brew() {
brew install grpc
brew link --force --overwrite grpc >/dev/null 2>&1
grpc_tag="v$(brew info grpc | grep "grpc:" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
license_path="$(brew --prefix grpc)/LICENSE"
}
add_grpc_php_plugin_compile() {
get_grpc_tag
get -s -n "" "https://github.com/grpc/grpc/archive/$grpc_tag.tar.gz" | tar -xz -C /tmp
export DISABLE_BAZEL_WRAPPER=1
(
cd "/tmp/grpc-${grpc_tag:1}" || exit
add_bazel
./tools/bazel build src/compiler:grpc_php_plugin
sudo mv ./bazel-bin/src/compiler/grpc_php_plugin /usr/local/bin/grpc_php_plugin
sudo chmod a+x /usr/local/bin/grpc_php_plugin
license_path="/tmp/grpc-${grpc_tag:1}/LICENSE"
)
}
add_grpc_php_plugin() {
grpc_tag=$1
license_path=""
if [ "$grpc_tag" = "latest" ]; then
add_grpc_php_plugin_brew >/dev/null 2>&1
else
add_grpc_php_plugin_compile >/dev/null 2>&1
fi
echo "::set-output name=grpc_php_plugin_path::$(command -v grpc_php_plugin)"
add_log "${tick:?}" "grpc_php_plugin" "Added grpc_php_plugin ${grpc_tag:1}"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "grpc_php_plugin" "Click to read the grpc_php_plugin related license information"
cat "$license_path"
echo "::endgroup::"
}

View File

@ -1,151 +0,0 @@
# Function to try to set ubuntu or debian version.
set_base_version_id() {
[[ "$ID" =~ ubuntu|debian ]] && return;
if ! [ -d "$dist_info_dir" ]; then
sudo mkdir -p "$dist_info_dir"
get -q -n "$dist_info_dir"/os_releases.csv https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/os_releases.csv
fi
for base in ubuntu debian; do
[[ "$ID_LIKE" =~ $base ]] && ID="$base" && VERSION_ID="$(grep -hr -m 1 "$VERSION_CODENAME" /usr/share/distro-info | cut -d ',' -f 1 | cut -d ' ' -f 1)" && break
done
}
# Function to try to set ubuntu or debian codename.
set_base_version_codename() {
[[ "$ID" =~ ubuntu|debian ]] && return;
if [[ "$ID_LIKE" =~ ubuntu ]]; then
[[ -n "$UBUNTU_CODENAME" ]] && VERSION_CODENAME="$UBUNTU_CODENAME" && return;
[ -e "$upstream_lsb" ] && VERSION_CODENAME=$(grep 'CODENAME' "$upstream_lsb" | cut -d '=' -f 2) && return;
VERSION_CODENAME=$(grep -E -m1 'deb .*ubuntu.com' "$list_file" | cut -d ' ' -f 3) && VERSION_CODENAME=${VERSION_CODENAME%-*}
elif [[ "$ID_LIKE" =~ debian ]] || command -v dpkg >/dev/null; then
ID_LIKE=debian
[[ -n "$DEBIAN_CODENAME" ]] && VERSION_CODENAME="$DEBIAN_CODENAME" && return;
update_lists && VERSION_CODENAME=$(apt-cache show tzdata | grep -m 1 Provides | cut -d '-' -f 2)
fi
}
# Function to set base os details
set_base_version() {
if [ -e /tmp/os-release ]; then
. /tmp/os-release
else
set_base_version_codename
set_base_version_id
printf "ID=%s\nVERSION_ID=%s\nVERSION_CODENAME=%s\n" "$ID" "$VERSION_ID" "$VERSION_CODENAME" | tee /tmp/os-release >/dev/null 2>&1
fi
}
# Helper function to update package lists.
update_lists_helper() {
list=$1
command -v sudo >/dev/null && SUDO=sudo
if [[ -n "$list" ]]; then
${SUDO} apt-get update -o Dir::Etc::sourcelist="$list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
else
${SUDO} apt-get update
fi
}
# Function to update the package lists.
update_lists() {
local ppa=${1:-}
local ppa_search=${2:-}
if [ ! -e /tmp/setup_php ] || [[ -n $ppa && -n $ppa_search ]]; then
if [[ -n "$ppa" && -n "$ppa_search" ]]; then
list="$list_dir"/"$(basename "$(grep -lr "$ppa_search" "$list_dir")")"
elif grep -Eq '^deb ' "$list_file"; then
list="$list_file"
fi
update_lists_helper "$list" >/dev/null 2>&1
echo '' | tee /tmp/setup_php >/dev/null 2>&1
fi
}
# Function to get fingerprint from an Ubuntu PPA.
ubuntu_fingerprint() {
ppa=$1
get -s -n "" "$lp_api"/~"${ppa%/*}"/+archive/"${ppa##*/}" | jq -r '.signing_key_fingerprint'
}
# Function to get fingerprint from a Debian PPA.
debian_fingerprint() {
ppa=$1
ppa_url=$2
package_dist=$3
release_pub=/tmp/"${ppa/\//-}".gpg
get -q -n "$release_pub" "$ppa_url"/dists/"$package_dist"/Release.gpg
gpg --list-packets "$release_pub" | grep -Eo 'fpr\sv4\s.*[a-zA-Z0-9]+' | head -n 1 | cut -d ' ' -f 3
}
# Function to add a GPG key.
add_key() {
ppa=${1:-ondrej/php}
ppa_url=$2
package_dist=$3
key_source=$4
key_file=$5
key_urls=("$key_source")
if [[ "$key_source" =~ launchpad.net|debian.org|setup-php.com ]]; then
fingerprint="$("${ID}"_fingerprint "$ppa" "$ppa_url" "$package_dist")"
sks_params="op=get&options=mr&exact=on&search=0x$fingerprint"
key_urls=("${sks[@]/%/\/pks\/lookup\?"$sks_params"}")
fi
[ ! -e "$key_source" ] && get -q -n "$key_file" "${key_urls[@]}"
if [[ "$(file "$key_file")" =~ .*('Public-Key (old)'|'Secret-Key') ]]; then
sudo gpg --batch --yes --dearmor "$key_file" >/dev/null 2>&1 && sudo mv "$key_file".gpg "$key_file"
fi
}
# Function to add a sources list.
add_list() {
ppa=${1-ondrej/php}
ppa_url=${2:-"$lp_ppa/$ppa/ubuntu"}
key_source=${3:-"$ppa_url"}
package_dist=${4:-"$VERSION_CODENAME"}
branches=${5:-main}
ppa_search="deb .*$ppa_url $package_dist .*$branches"
grep -Eqr "$ppa_search" "$list_dir" && echo "Repository $ppa already exists" && return;
arch=$(dpkg --print-architecture)
[ -e "$key_source" ] && key_file=$key_source || key_file="$key_dir"/"${ppa/\//-}"-keyring.gpg
add_key "$ppa" "$ppa_url" "$package_dist" "$key_source" "$key_file"
echo "deb [arch=$arch signed-by=$key_file] $ppa_url $package_dist $branches" | sudo tee -a "$list_dir"/"${ppa/\//-}".list >/dev/null 2>&1
update_lists "$ppa" "$ppa_search"
. /etc/os-release
}
# Function to remove a PPA.
remove_list() {
ppa=${1-ondrej/php}
ppa_url=${2:-"$lp_ppa/$ppa/ubuntu"}
grep -lr "$ppa_url" "$list_dir" | xargs -n1 sudo rm -f
sudo rm -f "$key_dir"/"${ppa/\//-}"-keyring || true
}
# Function to add a PPA.
add_ppa() {
set_base_version
ppa=${1:-ondrej/php}
if [[ "$ID" = "ubuntu" || "$ID_LIKE" =~ ubuntu ]] && [[ "$ppa" =~ "ondrej/" ]]; then
add_list "$ppa"
elif [[ "$ID" = "debian" || "$ID_LIKE" =~ debian ]] && [[ "$ppa" =~ "ondrej/" ]]; then
add_list "$ppa" "$sury"/"${ppa##*/}"/ "$sury"/"${ppa##*/}"/apt.gpg
else
add_list "$ppa"
fi
. /etc/os-release
}
# Variables
list_file='/etc/apt/sources.list'
list_dir="$list_file.d"
upstream_lsb='/etc/upstream-release/lsb-release'
lp_api='https://api.launchpad.net/1.0'
lp_ppa='http://ppa.launchpad.net'
key_dir='/usr/share/keyrings'
dist_info_dir='/usr/share/distro-info'
sury='https://packages.sury.org'
sks=(
'https://keyserver.ubuntu.com'
'https://pgp.mit.edu'
'https://keys.openpgp.org'
)

View File

@ -1,38 +0,0 @@
Function Get-ProtobufTag() {
if("$protobuf_tag" -eq "latest") {
$protobuf_tag = (Invoke-RestMethod https://api.github.com/repos/protocolbuffers/protobuf/tags).Name | Where-Object { $_ -match "v\d+.\d+.\d+$" } | Select-Object -First 1
} else {
try {
[net.httpWebRequest] $request = [net.webRequest]::create("https://github.com/protocolbuffers/protobuf/releases/tag/v$protobuf_tag")
$req.Method = "HEAD"
[net.httpWebResponse] $response = $request.getResponse()
$response.Close()
$protobuf_tag = "v$protobuf_tag"
} catch {
$protobuf_tag = (Invoke-RestMethod https://api.github.com/repos/protocolbuffers/protobuf/tags).Name | Where-Object { $_ -match "v\d+.\d+.\d+$" } | Select-Object -First 1
}
}
return $protobuf_tag
}
Function Add-Protoc() {
param(
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'The PHP version to be installed')]
[ValidatePattern('^latest$|^(v?)\d+\.\d+\.\d+$')]
[string] $protobuf_tag
)
$protobuf_tag = Get-ProtobufTag
$arch_num = '64'
if(-not([Environment]::Is64BitOperatingSystem)) {
$arch_num = '32'
}
$url = "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-$($protobuf_tag -replace 'v', '')-win$arch_num.zip"
Invoke-WebRequest -Uri $url -OutFile $bin_dir\protoc.zip >$null 2>&1
Expand-Archive -Path $bin_dir\protoc.zip -DestinationPath $bin_dir\protoc -Force >$null 2>&1
Move-Item -Path $bin_dir\protoc\bin\protoc.exe -Destination $bin_dir\protoc.exe
Add-ToProfile $current_profile 'protoc' "New-Alias protoc $bin_dir\protoc.exe"
Add-Log $tick "protoc" "Added protoc $($protobuf_tag -replace 'v', '')"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information"
Write-Output (Invoke-WebRequest https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE).Content
Write-Output "::endgroup::"
}

View File

@ -1,28 +0,0 @@
get_protobuf_tag() {
if [ "$protobuf_tag" = "latest" ]; then
protobuf_tag=$(get -s -n "" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+\.[0-9]+\.[0-9]+)" | head -n 1)
else
status_code=$(get -v -n /tmp/protobuf.tmp "https://github.com/protocolbuffers/protobuf/releases/tag/v$protobuf_tag")
if [ "$status_code" = "200" ]; then
protobuf_tag="v$protobuf_tag"
else
protobuf_tag=$(get -s -n "" https://github.com/protocolbuffers/protobuf/releases/latest 2<&1 | grep -m 1 -Eo "(v[0-9]+\.[0-9]+\.[0-9]+)" | head -n 1)
fi
fi
}
add_protoc() {
protobuf_tag=$1
get_protobuf_tag
(
platform='linux'
[ "$(uname -s)" = "Darwin" ] && platform='osx'
get -q -n /tmp/protobuf.zip "https://github.com/protocolbuffers/protobuf/releases/download/$protobuf_tag/protoc-${protobuf_tag:1}-$platform-x86_64.zip"
sudo unzip /tmp/protobuf.zip -d /usr/local/
sudo chmod -R 777 /usr/local/bin/protoc /usr/local/include/google
) >/dev/null 2>&1
add_log "${tick:?}" "protoc" "Added protoc ${protobuf_tag:1}"
printf "::group::\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "protoc" "Click to read the protoc related license information"
curl "${curl_opts[@]:?}" https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE
echo "::endgroup::"
}

View File

@ -3,7 +3,7 @@ param (
[ValidateNotNull()] [ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)] [ValidateLength(1, [int]::MaxValue)]
[string] [string]
$version = '8.0', $version = '7.4',
[Parameter(Position = 1, Mandatory = $true)] [Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()] [ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)] [ValidateLength(1, [int]::MaxValue)]
@ -11,24 +11,15 @@ param (
$dist $dist
) )
# Function to log start of a operation.
Function Step-Log($message) { Function Step-Log($message) {
printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message printf "\n\033[90;1m==> \033[0m\033[37;1m%s \033[0m\n" $message
} }
# Function to log result of a operation.
Function Add-Log($mark, $subject, $message) { Function Add-Log($mark, $subject, $message) {
if ($mark -eq $tick) { $code = if ($mark -eq $cross) { "31" } else { "32" }
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $code $mark $subject $message
} else {
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message
if($env:fail_fast -eq 'true') {
exit 1;
}
}
} }
# Function to add a line to a powershell profile safely.
Function Add-ToProfile { Function Add-ToProfile {
param( param(
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -52,48 +43,19 @@ Function Add-ToProfile {
} }
} }
# Function to fetch PATH from the registry.
Function Get-PathFromRegistry {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","User") + ";" +
[System.Environment]::GetEnvironmentVariable("Path","Machine")
Add-ToProfile $current_profile 'Get-PathFromRegistry' 'Function Get-PathFromRegistry { $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "Machine") }; Get-PathFromRegistry'
}
# Function to add a location to PATH.
Function Add-Path {
param(
[string]$PathItem
)
$newPath = (Get-ItemProperty -Path 'hkcu:\Environment' -Name PATH).Path.replace("$PathItem;", '')
$newPath = $PathItem + ';' + $newPath
Set-ItemProperty -Path 'hkcu:\Environment' -Name Path -Value $newPath
Get-PathFromRegistry
}
# Function to make sure printf is in PATH.
Function Add-Printf { Function Add-Printf {
if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) { if (-not(Test-Path "C:\Program Files\Git\usr\bin\printf.exe")) {
if(Test-Path "C:\msys64\usr\bin\printf.exe") { if(Test-Path "C:\msys64\usr\bin\printf.exe") {
New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe New-Item -Path $php_dir\printf.exe -ItemType SymbolicLink -Value C:\msys64\usr\bin\printf.exe -Force > $null 2>&1
} else { } else {
Invoke-WebRequest -Uri "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$bin_dir\printf.zip" Invoke-WebRequest -UseBasicParsing -Uri "$github/shivammathur/printf/releases/latest/download/printf-x64.zip" -OutFile "$php_dir\printf.zip"
Expand-Archive -Path $bin_dir\printf.zip -DestinationPath $bin_dir -Force Expand-Archive -Path $php_dir\printf.zip -DestinationPath $php_dir -Force
} }
} else { } else {
New-Item -Path $bin_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe" New-Item -Path $php_dir\printf.exe -ItemType SymbolicLink -Value "C:\Program Files\Git\usr\bin\printf.exe" -Force > $null 2>&1
} }
} }
# Function to get a clean Powershell profile.
Function Get-CleanPSProfile {
if(-not(Test-Path -LiteralPath $profile)) {
New-Item -Path $profile -ItemType "file" -Force
}
Set-Content $current_profile -Value ''
Add-ToProfile $profile $current_profile.replace('\', '\\') ". $current_profile"
}
# Function to install a powershell package from GitHub.
Function Install-PSPackage() { Function Install-PSPackage() {
param( param(
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -105,63 +67,20 @@ Function Install-PSPackage() {
[Parameter(Position = 3, Mandatory = $true)] [Parameter(Position = 3, Mandatory = $true)]
$cmdlet $cmdlet
) )
$module_path = "$bin_dir\$psm1_path.psm1" $module_path = "$php_dir\$psm1_path.psm1"
if(-not (Test-Path $module_path -PathType Leaf)) { if(-not (Test-Path $module_path -PathType Leaf)) {
$zip_file = "$bin_dir\$package.zip" $zip_file = "$php_dir\$package.zip"
Invoke-WebRequest -Uri $url -OutFile $zip_file Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $zip_file
Expand-Archive -Path $zip_file -DestinationPath $bin_dir -Force Expand-Archive -Path $zip_file -DestinationPath $php_dir -Force
} }
Import-Module $module_path Import-Module $module_path
Add-ToProfile $current_profile "$package-search" "Import-Module $module_path" Add-ToProfile $current_profile "$package-search" "Import-Module $module_path"
if($null -eq (Get-Command $cmdlet -ErrorAction SilentlyContinue)) { if($null -eq (Get-Command $cmdlet -ErrorAction SilentlyContinue)) {
Install-Module -Name $cmdlet -Force Install-Module -Name $package -Force
} }
} }
# Function to link dependencies to PHP directory.
Function Set-ExtensionPrerequisites
{
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$deps_dir
)
$deps = Get-ChildItem -Recurse -Path $deps_dir
if ($deps.Count -ne 0) {
# Symlink dependencies instead of adding the directory to PATH ...
# as other actions change the PATH thus breaking extensions.
$deps | ForEach-Object {
New-Item -Itemtype SymbolicLink -Path $php_dir -Name $_.Name -Target $_.FullName -Force > $null 2>&1
}
} else {
Remove-Item $deps_dir -Recurse -Force
}
}
# Function to get extension pre-requisites.
# https://windows.php.net/downloads/pecl/deps
# Currently only imagick is supported using this Cmdlet.
Function Get-ExtensionPrerequisites{
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
$extensions_with_dependencies = ('imagick')
New-Item $deps_dir -Type Directory 2>&1 | Out-Null
if($extensions_with_dependencies.Contains($extension)) {
Install-PhpExtensionPrerequisite -Extension $extension -InstallPath $deps_dir -PhpPath $php_dir
}
return $deps_dir
}
# Function to add PHP extensions.
Function Add-Extension { Function Add-Extension {
Param ( Param (
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -191,21 +110,18 @@ Function Add-Extension {
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
} }
default { default {
$deps_dir = Get-ExtensionPrerequisites $extension
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
} }
} }
} }
else { else {
$deps_dir = Get-ExtensionPrerequisites $extension
$params = @{ Extension = $extension; MinimumStability = $stability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if($extension_version -ne '') { if($extension_version -ne '') {
$params["Version"] = $extension_version Install-PhpExtension -Extension $extension -Version $extension_version -MinimumStability $stability -MaximumStability $stability -Path $php_dir
} else {
Install-PhpExtension -Extension $extension -MinimumStability $stability -MaximumStability $stability -Path $php_dir
} }
Install-PhpExtension @params
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Installed and enabled" Add-Log $tick $extension "Installed and enabled"
} }
} }
@ -214,7 +130,6 @@ Function Add-Extension {
} }
} }
# Function to remove PHP extensions.
Function Remove-Extension() { Function Remove-Extension() {
Param ( Param (
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -224,21 +139,14 @@ Function Remove-Extension() {
$extension $extension
) )
if(php -m | findstr -i $extension) { if(php -m | findstr -i $extension) {
try { Disable-PhpExtension $extension $php_dir
Disable-PhpExtension $extension $php_dir }
if (Test-Path $ext_dir\php_$extension.dll) { if (Test-Path $ext_dir\php_$extension.dll) {
Remove-Item $ext_dir\php_$extension.dll Remove-Item $ext_dir\php_$extension.dll
}
Add-Log $tick ":$extension" "Removed"
} catch {
Add-Log $cross ":$extension" "Could not remove $extension on PHP $($installed.FullVersion)"
}
} else {
Add-Log $tick ":$extension" "Could not find $extension on PHP $($installed.FullVersion)"
} }
} }
# Function to configure composer.
Function Edit-ComposerConfig() { Function Edit-ComposerConfig() {
Param( Param(
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -263,29 +171,6 @@ Function Edit-ComposerConfig() {
} }
} }
# Function to extract tool version.
Function Get-ToolVersion() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
$tool,
[Parameter(Position = 1, Mandatory = $true)]
$param
)
$alp = "[a-zA-Z0-9]"
$version_regex = "[0-9]+((\.{1}$alp+)+)(\.{0})(-$alp+){0,1}"
if($tool -eq 'composer') {
if ($param -eq 'snapshot') {
$composer_version = (Select-String -Pattern "const\sBRANCH_ALIAS_VERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }) + '+' + (Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern "[a-zA-Z0-9]+" -AllMatches | ForEach-Object { $_.matches[2].Value })
} else {
$composer_version = Select-String -Pattern "const\sVERSION" -Path $bin_dir\composer -Raw | Select-String -Pattern $version_regex | ForEach-Object { $_.matches.Value }
}
Set-Variable -Name 'composer_version' -Value $composer_version -Scope Global
return "$composer_version"
}
return . $tool $param 2> $null | ForEach-Object { $_ -replace "composer $version_regex", '' } | Select-String -Pattern $version_regex | Select-Object -First 1 | ForEach-Object { $_.matches.Value }
}
# Function to add tools.
Function Add-Tool() { Function Add-Tool() {
Param ( Param (
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -293,48 +178,55 @@ Function Add-Tool() {
$url, $url,
[Parameter(Position = 1, Mandatory = $true)] [Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNull()] [ValidateNotNull()]
$tool, [ValidateLength(1, [int]::MaxValue)]
[Parameter(Position = 2, Mandatory = $true)] [string]
[ValidateNotNull()] $tool
$ver_param
) )
if (Test-Path $bin_dir\$tool) { if (Test-Path $php_dir\$tool) {
Remove-Item $bin_dir\$tool Remove-Item $php_dir\$tool
} }
if($url.Count -gt 1) { if($url.Count -gt 1) { $url = $url[0] }
$url = $url[0] if ($tool -eq "symfony") {
} Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool.exe
$tool_path = "$bin_dir\$tool" Add-ToProfile $current_profile $tool "New-Alias $tool $php_dir\$tool.exe" >$null 2>&1
if (($url | Split-Path -Extension) -eq ".exe") { } else {
$tool_path = "$tool_path.exe" try {
} Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool
try { } catch {
Invoke-WebRequest -Uri $url -OutFile $tool_path if($url -match '.*github.com.*releases.*latest.*') {
} catch { try {
if($url -match '.*github.com.*releases.*latest.*') { $url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -UseBasicParsing -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0])
try { Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $php_dir\$tool
$url = $url.replace("releases/latest/download", "releases/download/" + ([regex]::match((Invoke-WebRequest -Uri ($url.split('/release')[0] + "/releases")).Content, "([0-9]+\.[0-9]+\.[0-9]+)/" + ($url.Substring($url.LastIndexOf("/") + 1))).Groups[0].Value).split('/')[0]) } catch { }
Invoke-WebRequest -Uri $url -OutFile $tool_path }
} catch { }
} }
} }
if (((Get-ChildItem -Path $bin_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) { if (((Get-ChildItem -Path $php_dir/* | Where-Object Name -Match "^$tool(.exe|.phar)*$").Count -gt 0)) {
$bat_content = @() $bat_content = @()
$bat_content += "@ECHO off" $bat_content += "@ECHO off"
$bat_content += "setlocal DISABLEDELAYEDEXPANSION" $bat_content += "setlocal DISABLEDELAYEDEXPANSION"
$bat_content += "SET BIN_TARGET=%~dp0/" + $tool $bat_content += "SET BIN_TARGET=%~dp0/" + $tool
$bat_content += "php %BIN_TARGET% %*" $bat_content += "php %BIN_TARGET% %*"
Set-Content -Path $bin_dir\$tool.bat -Value $bat_content Set-Content -Path $php_dir\$tool.bat -Value $bat_content
Add-ToolsHelper $tool Add-ToProfile $current_profile $tool "New-Alias $tool $php_dir\$tool.bat" >$null 2>&1
Add-ToProfile $current_profile $tool "New-Alias $tool $bin_dir\$tool.bat" >$null 2>&1 if($tool -eq "composer") {
$tool_version = Get-ToolVersion $tool $ver_param Edit-ComposerConfig $php_dir\$tool
Add-Log $tick $tool "Added $tool $tool_version" } elseif($tool -eq "cs2pr") {
(Get-Content $php_dir/cs2pr).replace('exit(9)', 'exit(0)') | Set-Content $php_dir/cs2pr
} elseif($tool -eq "phan") {
Add-Extension fileinfo >$null 2>&1
Add-Extension ast >$null 2>&1
} elseif($tool -eq "phive") {
Add-Extension xml >$null 2>&1
} elseif($tool -eq "wp-cli") {
Copy-Item $php_dir\wp-cli.bat -Destination $php_dir\wp.bat
}
Add-Log $tick $tool "Added"
} else { } else {
Add-Log $cross $tool "Could not add $tool" Add-Log $cross $tool "Could not add $tool"
} }
} }
# Function to setup a tool using composer.
Function Add-Composertool() { Function Add-Composertool() {
Param ( Param (
[Parameter(Position = 0, Mandatory = $true)] [Parameter(Position = 0, Mandatory = $true)]
@ -353,30 +245,23 @@ Function Add-Composertool() {
[string] [string]
$prefix $prefix
) )
if($tool -match "prestissimo|composer-prefetcher" -and $composer_version.split('.')[0] -ne "1") {
Write-Output "::warning:: Skipping $tool, as it does not support Composer $composer_version. Specify composer:v1 in tools to use $tool"
Add-Log $cross $tool "Skipped"
Return
}
if(Test-Path $composer_lock) { if(Test-Path $composer_lock) {
Remove-Item -Path $composer_lock -Force Remove-Item -Path $composer_lock -Force
} }
(composer global require $prefix$release 2>&1 | Tee-Object -FilePath $env:APPDATA\Composer\composer.log) >$null 2>&1 composer -q global require $prefix$release 2>&1 | out-null
$json = findstr $prefix$tool $env:APPDATA\Composer\composer.json if($tool -eq "codeception") {
$log = findstr $prefix$tool $env:APPDATA\Composer\composer.log Copy-Item $composer_bin\codecept.bat -Destination $composer_bin\codeception.bat
if(Test-Path $composer_bin\composer) {
Copy-Item -Path "$bin_dir\composer" -Destination "$composer_bin\composer" -Force
} }
Add-ToolsHelper $tool if($?) {
if($json) { Add-Log $tick $tool "Added"
$tool_version = Get-ToolVersion "Write-Output" "$log"
Add-Log $tick $tool "Added $tool $tool_version"
} else { } else {
Add-Log $cross $tool "Could not setup $tool" Add-Log $cross $tool "Could not setup $tool"
} }
if(Test-Path $composer_bin\composer) {
Copy-Item -Path "$php_dir\composer" -Destination "$composer_bin\composer" -Force
}
} }
# Function to handle request to add PECL.
Function Add-Pecl() { Function Add-Pecl() {
Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows" Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
} }
@ -386,56 +271,24 @@ $tick = ([char]8730)
$cross = ([char]10007) $cross = ([char]10007)
$php_dir = 'C:\tools\php' $php_dir = 'C:\tools\php'
$ext_dir = "$php_dir\ext" $ext_dir = "$php_dir\ext"
$bin_dir = $php_dir $current_profile = "$PSHOME\Profile.ps1"
$ProgressPreference = 'SilentlyContinue'
$github = 'https://github.com' $github = 'https://github.com'
$php_builder = "$github/shivammathur/php-builder-windows"
$composer_bin = "$env:APPDATA\Composer\vendor\bin" $composer_bin = "$env:APPDATA\Composer\vendor\bin"
$composer_json = "$env:APPDATA\Composer\composer.json" $composer_json = "$env:APPDATA\Composer\composer.json"
$composer_lock = "$env:APPDATA\Composer\composer.lock" $composer_lock = "$env:APPDATA\Composer\composer.lock"
$current_profile = "$env:TEMP\setup-php.ps1"
$ProgressPreference = 'SilentlyContinue'
$jit_versions = '8.[0-9]'
$nightly_versions = '8.[1-9]'
$cert_source='CurrentUser'
$enable_extensions = ('openssl', 'curl', 'mbstring')
$arch = 'x64' $arch = 'x64'
if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') { if(-not([Environment]::Is64BitOperatingSystem) -or $version -lt '7.0') {
$arch = 'x86' $arch = 'x86'
} }
$ts = $env:PHPTS -eq 'ts' $ts = $env:PHPTS -eq 'ts'
if($env:PHPTS -ne 'ts') { if($env:PHPTS -ne 'ts') {
$env:PHPTS = 'nts' $env:PHPTS = 'nts'
} }
if($env:RUNNER -eq 'self-hosted') { if(-not(Test-Path -LiteralPath $current_profile)) {
$bin_dir = 'C:\tools\bin' New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1
$php_dir = "$php_dir$version"
$ext_dir = "$php_dir\ext"
$cert_source='Curl'
Get-CleanPSProfile >$null 2>&1
New-Item $bin_dir -Type Directory 2>&1 | Out-Null
Add-Path -PathItem $bin_dir
if($version -lt 5.6) {
Add-Log $cross "PHP" "PHP $version is not supported on self-hosted runner"
Start-Sleep 1
exit 1
}
if ((Get-InstalledModule).Name -notcontains 'VcRedist') {
Install-Module -Name VcRedist -Force
}
New-Item $php_dir -Type Directory 2>&1 | Out-Null
Add-Path -PathItem $php_dir
setx PHPROOT $php_dir >$null 2>&1
} else {
$current_profile = "$PSHOME\Profile.ps1"
if(-not(Test-Path -LiteralPath $current_profile)) {
New-Item -Path $current_profile -ItemType "file" -Force >$null 2>&1
}
} }
. $dist\..\src\scripts\tools\add_tools.ps1
Add-Printf >$null 2>&1 Add-Printf >$null 2>&1
Step-Log "Setup PhpManager" Step-Log "Setup PhpManager"
Install-PSPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" Get-Php >$null 2>&1 Install-PSPackage PhpManager PhpManager\PhpManager "$github/mlocati/powershell-phpmanager/releases/latest/download/PhpManager.zip" Get-Php >$null 2>&1
@ -449,30 +302,15 @@ if (Test-Path -LiteralPath $php_dir -PathType Container) {
} catch { } } catch { }
} }
$status = "Installed" $status = "Installed"
$extra_version = ""
if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) { if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version -replace '^(\d+(\.\d+)*).*', '$1.'))) -or $ts -ne $installed.ThreadSafe) {
if ($version -lt '7.0' -and (Get-InstalledModule).Name -notcontains 'VcRedist') { if ($version -lt '7.0' -and ($null -eq (Get-Module -ListAvailable -Name VcRedist))) {
Install-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" Get-VcList >$null 2>&1 Install-PSPackage VcRedist VcRedist-main\VcRedist\VcRedist "$github/aaronparker/VcRedist/archive/main.zip" Get-VcList >$null 2>&1
} }
try { try {
if ($version -match $nightly_versions) { Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1
Invoke-WebRequest -UseBasicParsing -Uri $php_builder/releases/latest/download/Get-PhpNightly.ps1 -OutFile $php_dir\Get-PhpNightly.ps1 > $null 2>&1
& $php_dir\Get-PhpNightly.ps1 -Architecture $arch -ThreadSafe $ts -Path $php_dir > $null 2>&1
$extra_version = " ($(Get-Content $php_dir\COMMIT))"
} else {
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force > $null 2>&1
}
} catch { } } catch { }
} else { } else {
if($version -match $jit_versions) { $status = "Found"
('opcache.enable=1', 'opcache.jit_buffer_size=256M', 'opcache.jit=1235') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
}
if($env:update -eq 'true') {
Update-Php $php_dir >$null 2>&1
$status = "Updated to"
} else {
$status = "Found"
}
} }
$installed = Get-Php -Path $php_dir $installed = Get-Php -Path $php_dir
@ -481,14 +319,8 @@ if($installed.MajorMinorVersion -ne $version) {
exit 1 exit 1
} }
('date.timezone=UTC', 'memory_limit=-1', 'xdebug.mode=coverage') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir } ('date.timezone=UTC', 'memory_limit=-1', 'xdebug.mode=coverage') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir }
if($version -lt "5.5") { Enable-PhpExtension -Extension openssl, curl, opcache, mbstring -Path $php_dir
('libeay32.dll', 'ssleay32.dll') | ForEach-Object { Invoke-WebRequest -Uri "$php_builder/releases/download/openssl-1.0.2u/$_" -OutFile $php_dir\$_ >$null 2>&1 } Update-PhpCAInfo -Path $php_dir -Source CurrentUser
} else {
$enable_extensions += ('opcache')
}
Enable-PhpExtension -Extension $enable_extensions -Path $php_dir
Update-PhpCAInfo -Path $php_dir -Source $cert_source
Copy-Item -Path $dist\..\src\configs\*.json -Destination $env:RUNNER_TOOL_CACHE Copy-Item -Path $dist\..\src\configs\*.json -Destination $env:RUNNER_TOOL_CACHE
New-Item -ItemType Directory -Path $composer_bin -Force 2>&1 | Out-Null New-Item -ItemType Directory -Path $composer_bin -Force > $null 2>&1
Write-Output "::set-output name=php-version::$($installed.FullVersion)" Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)"
Add-Log $tick "PHP" "$status PHP $($installed.FullVersion)$extra_version"

View File

@ -1,101 +1,215 @@
import * as utils from './utils'; import * as utils from './utils';
type RS = Record<string, string>;
type RSRS = Record<string, RS>;
interface IRef {
ref: string;
node_id: string;
url: string;
object: RS;
}
/** /**
* Function to get version in semver format. * Function to get command to setup tools
* *
* @param data * @param os_version
* @param suffix
*/ */
export async function getSemverVersion(data: RS): Promise<string> { export async function getCommand(
const search: string = data['version_prefix'] + data['version']; os_version: string,
const url = `https://api.github.com/repos/${data['repository']}/git/matching-refs/tags%2F${search}.`; suffix: string
const token: string = await utils.readEnv('COMPOSER_TOKEN'); ): Promise<string> {
const response: RS = await utils.fetch(url, token); switch (os_version) {
if (response.error || response.data === '[]') { case 'linux':
data['error'] = response.error ?? `No version found with prefix ${search}.`; case 'darwin':
return data['version']; return 'add_' + suffix + ' ';
} else { case 'win32':
const refs = JSON.parse(response['data']).reverse(); return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
const ref = refs.find((i: IRef) => /.*\d+.\d+.\d+$/.test(i['ref'])); default:
const tag: string = (ref || refs[0])['ref'].split('/').pop(); return await utils.log(
return tag.replace(/^v(\d)/, '$1'); 'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
} }
} }
/**
* Function to get latest version from releases.atom
*
* @param data
*/
export async function getLatestVersion(data: RS): Promise<string> {
if (!data['version'] && data['fetch_latest'] === 'false') {
return 'latest';
}
const resp: Record<string, string> = await utils.fetch(
`${data['github']}/${data['repository']}/releases.atom`
);
const releases: string[] = [
...resp['data'].matchAll(/releases\/tag\/([a-zA-Z]*)?(\d+.\d+.\d+)"/g)
].map(match => match[2]);
return (
releases
.sort((a: string, b: string) =>
a.localeCompare(b, undefined, {numeric: true})
)
.pop() || 'latest'
);
}
/** /**
* Function to get tool version * Function to get tool version
* *
* @param version * @param version
* @param data
*/ */
export async function getVersion(version: string, data: RS): Promise<string> { export async function getToolVersion(version: string): Promise<string> {
// semver_regex - https://semver.org/ // semver_regex - https://semver.org/
const semver_regex = const semver_regex =
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
const composer_regex = /^composer:(stable|preview|snapshot|[1|2])$/; const composer_regex = /^stable$|^preview$|^snapshot$|^[1|2]$/;
const constraint_regex = /[><=^~]+.*/; version = version.replace(/[><=^]*/, '').replace(/^v(\d)/, '$1');
const major_minor_regex = /^\d+(\.\d+)?$/;
data['version'] = version.replace(/v?(\d)/, '$1').replace(/\.x/, '');
switch (true) { switch (true) {
case composer_regex.test(data['release']): case composer_regex.test(version):
case semver_regex.test(data['version']): case semver_regex.test(version):
case constraint_regex.test(data['version']) && data['type'] === 'composer': return version;
return data['version'];
case major_minor_regex.test(data['version']) && data['type'] === 'composer':
data['release'] = `${data['tool']}:${data['version']}.*`;
return `${data['version']}.*`;
case data['repository'] && major_minor_regex.test(data['version']):
return await getSemverVersion(data);
default: default:
return data['version'].replace(/[><=^~]*/, ''); return 'latest';
} }
} }
/** /**
* Function to parse the release tool:version * Function to parse tool:version
* *
* @param release * @param release
* @param data
*/ */
export async function getRelease(release: string, data: RS): Promise<string> { export async function parseTool(
release = release.includes('/') ? release.split('/')[1] : release; release: string
return release.includes(':') ): Promise<{name: string; version: string}> {
? [data['tool'], release.split(':')[1]].join(':') const parts: string[] = release.split(':');
: data['tool']; const tool: string = parts[0];
const version: string | undefined = parts[1];
switch (version) {
case undefined:
return {
name: tool,
version: 'latest'
};
default:
return {
name: tool,
version: await getToolVersion(parts[1])
};
}
}
/**
* Function to get the url of tool with the given version
*
* @param tool
* @param extension
* @param version
* @param prefix
* @param version_prefix
* @param verb
*/
export async function getUri(
tool: string,
extension: string,
version: string,
prefix: string,
version_prefix: string,
verb: string
): Promise<string> {
switch (version) {
case 'latest':
return [prefix, version, verb, tool + extension]
.filter(Boolean)
.join('/');
default:
return [prefix, verb, version_prefix + version, tool + extension]
.filter(Boolean)
.join('/');
}
}
/**
* Helper function to get script to setup phive
*
* @param version
* @param php_version
* @param os_version
*/
export async function addPhive(
version: string,
php_version: string,
os_version: string
): Promise<string> {
switch (true) {
case /5\.6|7\.0/.test(php_version):
version = version.replace('latest', '0.12.1');
break;
case /7\.1/.test(php_version):
version = version.replace('latest', '0.13.5');
break;
case /7\.2/.test(php_version):
version = version.replace('latest', '0.14.5');
break;
}
switch (version) {
case 'latest':
return (
(await getCommand(os_version, 'tool')) +
'https://phar.io/releases/phive.phar phive'
);
default:
return (
(await getCommand(os_version, 'tool')) +
'https://github.com/phar-io/phive/releases/download/' +
version +
'/phive-' +
version +
'.phar phive'
);
}
}
/**
* Function to get the phar url in domain/tool-version.phar format
*
* @param domain
* @param tool
* @param prefix
* @param version
*/
export async function getPharUrl(
domain: string,
tool: string,
prefix: string,
version: string
): Promise<string> {
switch (version) {
case 'latest':
return domain + '/' + tool + '.phar';
default:
return domain + '/' + tool + '-' + prefix + version + '.phar';
}
}
/**
* Function to get the Deployer url
*
* @param version
*/
export async function getDeployerUrl(version: string): Promise<string> {
const deployer = 'https://deployer.org';
switch (version) {
case 'latest':
return deployer + '/deployer.phar';
default:
return deployer + '/releases/v' + version + '/deployer.phar';
}
}
/**
* Function to get the Deployer url
*
* @param version
* @param os_version
*/
export async function getSymfonyUri(
version: string,
os_version: string
): Promise<string> {
let filename = '';
switch (os_version) {
case 'linux':
case 'darwin':
filename = 'symfony_' + os_version + '_amd64';
break;
case 'win32':
filename = 'symfony_windows_amd64.exe';
break;
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
switch (version) {
case 'latest':
return 'releases/latest/download/' + filename;
default:
return 'releases/download/v' + version + '/' + filename;
}
} }
/** /**
@ -103,14 +217,19 @@ export async function getRelease(release: string, data: RS): Promise<string> {
* *
* @param tools_list * @param tools_list
*/ */
export async function filterList(tools_list: string[]): Promise<string[]> { export async function addComposer(tools_list: string[]): Promise<string[]> {
const regex_any = /^composer($|:.*)/; const regex_any = /^composer($|:.*)/;
const regex_valid = const regex_valid =
/^composer:?($|preview$|snapshot$|v?\d+(\.\d+)?$|v?\d+\.\d+\.\d+[\w-]*$)/; /^composer:?($|preview$|snapshot$|v?[1-2]$|v?\d+\.\d+\.\d+[\w-]*$)/;
const regex_composer1_tools =
/hirak|prestissimo|narrowspark|composer-prefetcher/;
const matches: string[] = tools_list.filter(tool => regex_valid.test(tool)); const matches: string[] = tools_list.filter(tool => regex_valid.test(tool));
let composer = 'composer'; let composer = 'composer';
tools_list = tools_list.filter(tool => !regex_any.test(tool)); tools_list = tools_list.filter(tool => !regex_any.test(tool));
switch (true) { switch (true) {
case regex_composer1_tools.test(tools_list.join(' ')):
composer = 'composer:1';
break;
case matches[0] == undefined: case matches[0] == undefined:
break; break;
default: default:
@ -122,356 +241,122 @@ export async function filterList(tools_list: string[]): Promise<string[]> {
} }
/** /**
* Function to get the url of tool with the given version * Function to get composer URL for a given version
* *
* @param data * @param version
*/ */
export async function getUrl(data: RS): Promise<string> { export async function getComposerUrl(
if (data['version'] === 'latest') { version: string,
return [ php_version: string
data['domain'], ): Promise<string> {
data['repository'], let cache_url = `https://github.com/shivammathur/composer-cache/releases/latest/download/composer-${php_version}-${version.replace(
data['prefix'], 'latest',
data['version'], 'stable'
data['verb'], )}.phar`;
data['tool'] + data['extension'] switch (true) {
] case /^snapshot$/.test(version):
.filter(Boolean) return `${cache_url},https://getcomposer.org/composer.phar`;
.join('/'); case /^preview$|^[1-2]$/.test(version):
} else { return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
return [ case /^\d+\.\d+\.\d+[\w-]*$/.test(version):
data['domain'], cache_url = `https://github.com/composer/composer/releases/download/${version}/composer.phar`;
data['repository'], return `${cache_url},https://getcomposer.org/composer-${version}.phar`;
data['prefix'], default:
data['verb'], return `${cache_url},https://getcomposer.org/composer-stable.phar`;
data['version_prefix'] + data['version'],
data['tool'] + data['extension']
]
.filter(Boolean)
.join('/');
} }
} }
/** /**
* Function to get the phar url in domain/tool-version.phar format * Function to get Tools list after cleanup
* *
* @param data * @param tools_csv
*/ */
export async function getPharUrl(data: RS): Promise<string> { export async function getCleanedToolsList(
if (data['version'] === 'latest') { tools_csv: string
return data['domain'] + '/' + data['tool'] + '.phar'; ): Promise<string[]> {
} else { let tools_list: string[] = await utils.CSVArray(tools_csv);
return ( tools_list = await addComposer(tools_list);
data['domain'] + tools_list = tools_list
'/' + .map(function (extension: string) {
data['tool'] + return extension
'-' + .trim()
data['version_prefix'] + .replace(
data['version'] + /codeception\/|hirak\/|robmorgan\/|narrowspark\/automatic-/,
'.phar' ''
); );
} })
.filter(Boolean);
return [...new Set(tools_list)];
} }
/** /**
* Helper function to get script to setup a tool using a phar url * Helper function to get script to setup a tool using a phar url
* *
* @param data * @param tool
* @param url
* @param os_version
*/ */
export async function addArchive(data: RS): Promise<string> { export async function addArchive(
return ( tool: string,
(await utils.getCommand(data['os_version'], 'tool')) + url: string,
(await utils.joins(data['url'], data['tool'], data['version_parameter'])) os_version: string
); ): Promise<string> {
return (await getCommand(os_version, 'tool')) + url + ' ' + tool;
}
/**
* Function to get the script to setup php-config and phpize
*
* @param tool
* @param os_version
*/
export async function addDevTools(
tool: string,
os_version: string
): Promise<string> {
switch (os_version) {
case 'linux':
return (
'add_devtools' +
'\n' +
(await utils.addLog('$tick', tool, 'Added', 'linux'))
);
case 'darwin':
return await utils.addLog('$tick', tool, 'Added', 'darwin');
case 'win32':
return await utils.addLog(
'$cross',
tool,
tool + ' is not a windows tool',
'win32'
);
default:
return await utils.log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
} }
/** /**
* Helper function to get script to setup a tool using composer * Helper function to get script to setup a tool using composer
* *
* @param data * @param tool
*/
export async function addPackage(data: RS): Promise<string> {
const command = await utils.getCommand(data['os_version'], 'composertool');
const parts: string[] = data['repository'].split('/');
return command + parts[1] + ' ' + data['release'] + ' ' + parts[0] + '/';
}
/**
* Function to add blackfire-player
*
* @param data
*/
export async function addBlackfirePlayer(data: RS): Promise<string> {
if (
/5\.[5-6]|7\.0/.test(data['php_version']) &&
data['version'] == 'latest'
) {
data['version'] = '1.9.3';
}
data['url'] = await getPharUrl(data);
return addArchive(data);
}
/**
* Function to add composer
*
* @param data
*/
export async function addComposer(data: RS): Promise<string> {
const github = data['github'];
const getcomposer = data['domain'];
let cache_url = `${github}/shivammathur/composer-cache/releases/latest/download/composer-${data[
'version'
].replace('latest', 'stable')}.phar`;
let source_url = `${getcomposer}/composer.phar`;
switch (true) {
case /^snapshot$/.test(data['version']):
break;
case /^preview$|^[1-2]$/.test(data['version']):
source_url = `${getcomposer}/composer-${data['version']}.phar`;
break;
case /^\d+\.\d+\.\d+[\w-]*$/.test(data['version']):
cache_url = `${github}/${data['repository']}/releases/download/${data['version']}/composer.phar`;
source_url = `${getcomposer}/composer-${data['version']}.phar`;
break;
default:
source_url = `${getcomposer}/composer-stable.phar`;
}
const use_cache: boolean = (await utils.readEnv('NO_TOOLS_CACHE')) !== 'true';
data['url'] = use_cache ? `${cache_url},${source_url}` : source_url;
data['version_parameter'] = data['version'];
return await addArchive(data);
}
/**
* Function to add Deployer
*
* @param data
*/
export async function addDeployer(data: RS): Promise<string> {
if (data['version'] === 'latest') {
data['url'] = data['domain'] + '/deployer.phar';
} else {
data['url'] =
data['domain'] + '/releases/v' + data['version'] + '/deployer.phar';
}
return await addArchive(data);
}
/**
* Function to add php-config and phpize
*
* @param data
*/
export async function addDevTools(data: RS): Promise<string> {
switch (data['os_version']) {
case 'linux':
case 'darwin':
return 'add_devtools ' + data['tool'];
case 'win32':
return await utils.addLog(
'$tick',
data['tool'],
data['tool'] + ' is not a windows tool',
'win32'
);
default:
return await utils.log(
'Platform ' + data['os_version'] + ' is not supported',
data['os_version'],
'error'
);
}
}
/**
* Function to add PECL
*
* @param data
*/
export async function addPECL(data: RS): Promise<string> {
return await utils.getCommand(data['os_version'], 'pecl');
}
/**
* Function to add Phing
*
* @param data
*/
export async function addPhing(data: RS): Promise<string> {
data['url'] =
data['domain'] + '/get/phing-' + data['version'] + data['extension'];
return await addArchive(data);
}
/**
* Helper function to add Phive
*
* @param data
*/
export async function addPhive(data: RS): Promise<string> {
switch (true) {
case /5\.[3-5]/.test(data['php_version']):
return await utils.addLog(
'$cross',
'phive',
'Phive is not supported on PHP ' + data['php_version'],
data['os_version']
);
case /5\.6|7\.0/.test(data['php_version']):
data['version'] = data['version'].replace('latest', '0.12.1');
break;
case /7\.1/.test(data['php_version']):
data['version'] = data['version'].replace('latest', '0.13.5');
break;
case /7\.2/.test(data['php_version']):
data['version'] = data['version'].replace('latest', '0.14.5');
break;
}
if (data['version'] === 'latest') {
data['domain'] = data['domain'] + '/releases';
} else {
data['domain'] = [
data['github'],
data['repository'],
'releases/download',
data['version']
].join('/');
}
data['url'] = await getPharUrl(data);
return await addArchive(data);
}
/**
* Function to add PHPUnit and related tools
*
* @param data
*/
export async function addPHPUnitTools(data: RS): Promise<string> {
data['url'] = await getPharUrl(data);
return await addArchive(data);
}
/**
* Function to add Symfony
*
* @param data
*/
export async function addSymfony(data: RS): Promise<string> {
let filename: string;
switch (data['os_version']) {
case 'linux':
case 'darwin':
filename = 'symfony_' + data['os_version'] + '_amd64';
break;
case 'win32':
filename = 'symfony_windows_amd64.exe';
break;
default:
return await utils.log(
'Platform ' + data['os_version'] + ' is not supported',
data['os_version'],
'error'
);
}
if (data['version'] === 'latest') {
data['uri'] = ['releases/latest/download', filename].join('/');
} else {
data['uri'] = ['releases/download', 'v' + data['version'], filename].join(
'/'
);
}
data['url'] = [data['domain'], data['repository'], data['uri']].join('/');
return await addArchive(data);
}
/**
* Function to add WP-CLI
*
* @param data
*/
export async function addWPCLI(data: RS): Promise<string> {
if (data['version'] === 'latest') {
data['uri'] = 'wp-cli/builds/blob/gh-pages/phar/wp-cli.phar?raw=true';
data['url'] = [data['domain'], data['uri']].join('/');
} else {
data['extension'] = '-' + data['version'] + data['extension'];
data['url'] = await getUrl(data);
}
return await addArchive(data);
}
/**
* Function to get information about a tool
*
* @param release * @param release
* @param php_version * @param prefix
* @param os_version * @param os_version
*/ */
export async function getData( export async function addPackage(
tool: string,
release: string, release: string,
php_version: string, prefix: string,
os_version: string os_version: string
): Promise<RS> { ): Promise<string> {
const json_file: string = await utils.readFile('tools.json', 'src/configs'); const tool_command = await getCommand(os_version, 'composertool');
const json_objects: RSRS = JSON.parse(json_file); return tool_command + tool + ' ' + release + ' ' + prefix;
release = release.replace(/\s+/g, '');
const parts: string[] = release.split(':');
const tool = parts[0];
const version = parts[1];
let data: RS;
if (Object.keys(json_objects).includes(tool)) {
data = json_objects[tool];
data['tool'] = tool;
} else {
const key: string | undefined = Object.keys(json_objects).find(
(key: string) => {
return json_objects[key]['alias'] == tool;
}
);
if (key) {
data = json_objects[key];
data['tool'] = key;
} else {
data = {
tool: tool.split('/')[1],
repository: tool,
type: 'composer'
};
data = !tool.includes('/') ? {tool: tool} : data;
}
}
data['github'] = 'https://github.com';
data['domain'] ??= data['github'];
data['extension'] ??= '.phar';
data['os_version'] = os_version;
data['php_version'] = php_version;
data['prefix'] = data['github'] === data['domain'] ? 'releases' : '';
data['verb'] = data['github'] === data['domain'] ? 'download' : '';
data['fetch_latest'] ??= 'false';
data['version_parameter'] = JSON.stringify(data['version_parameter']) || '';
data['version_prefix'] ??= '';
data['release'] = await getRelease(release, data);
data['version'] = version
? await getVersion(version, data)
: await getLatestVersion(data);
return data;
} }
export const functionRecord: Record<string, (data: RS) => Promise<string>> = {
composer: addComposer,
deployer: addDeployer,
dev_tools: addDevTools,
phive: addPhive,
blackfire_player: addBlackfirePlayer,
pecl: addPECL,
phing: addPhing,
phpunit: addPHPUnitTools,
phpcpd: addPHPUnitTools,
symfony: addSymfony,
wp_cli: addWPCLI
};
/** /**
* Setup tools * Setup tools
* *
@ -484,51 +369,103 @@ export async function addTools(
php_version: string, php_version: string,
os_version: string os_version: string
): Promise<string> { ): Promise<string> {
let script = '\n'; let script = '\n' + (await utils.stepLog('Setup Tools', os_version));
if (tools_csv === 'none') { const tools_list: Array<string> = await getCleanedToolsList(tools_csv);
return '';
} else {
script += await utils.stepLog('Setup Tools', os_version);
}
const tools_list = await filterList(await utils.CSVArray(tools_csv));
await utils.asyncForEach(tools_list, async function (release: string) { await utils.asyncForEach(tools_list, async function (release: string) {
const data: RS = await getData(release, php_version, os_version); const tool_data: {name: string; version: string} = await parseTool(release);
const tool: string = tool_data.name;
const version: string = tool_data.version;
const github = 'https://github.com/';
let uri: string = await getUri(
tool,
'.phar',
version,
'releases',
'',
'download'
);
script += '\n'; script += '\n';
switch (true) { let url = '';
case data['error'] !== undefined: switch (tool) {
script += await utils.addLog( case 'cs2pr':
'$cross', uri = await getUri(tool, '', version, 'releases', '', 'download');
data['tool'], url = github + 'staabm/annotate-pull-request-from-checkstyle/' + uri;
data['error'], script += await addArchive(tool, url, os_version);
data['os_version'] break;
case 'php-cs-fixer':
uri = await getUri(tool, '.phar', version, 'releases', 'v', 'download');
url = github + 'FriendsOfPHP/PHP-CS-Fixer/' + uri;
script += await addArchive(tool, url, os_version);
break;
case 'phpcs':
case 'phpcbf':
url = github + 'squizlabs/PHP_CodeSniffer/' + uri;
script += await addArchive(tool, url, os_version);
break;
case 'phive':
script += await addPhive(version, php_version, os_version);
break;
case 'phpstan':
url = github + 'phpstan/phpstan/' + uri;
script += await addArchive(tool, url, os_version);
break;
case 'phpmd':
url = github + 'phpmd/phpmd/' + uri;
script += await addArchive(tool, url, os_version);
break;
case 'psalm':
url = github + 'vimeo/psalm/' + uri;
script += await addArchive(tool, url, os_version);
break;
case 'composer':
url = await getComposerUrl(version, php_version);
script += await addArchive('composer', url, os_version);
break;
case 'codeception':
script += await addPackage(tool, release, 'codeception/', os_version);
break;
case 'phpcpd':
case 'phpunit':
url = await getPharUrl('https://phar.phpunit.de', tool, '', version);
script += await addArchive(tool, url, os_version);
break;
case 'deployer':
url = await getDeployerUrl(version);
script += await addArchive(tool, url, os_version);
break;
case 'phinx':
script += await addPackage(tool, release, 'robmorgan/', os_version);
break;
case 'prestissimo':
script += await addPackage(tool, release, 'hirak/', os_version);
break;
case 'composer-prefetcher':
script += await addPackage(
tool,
release,
'narrowspark/automatic-',
os_version
); );
break; break;
case 'phar' === data['type']: case 'pecl':
data['url'] = await getUrl(data); script += await getCommand(os_version, 'pecl');
script += await addArchive(data);
break; break;
case 'composer' === data['type']: case 'php-config':
script += await addPackage(data); case 'phpize':
script += await addDevTools(tool, os_version);
break; break;
case 'custom-package' === data['type']: case 'symfony':
script += await utils.customPackage( case 'symfony-cli':
data['tool'].split('-')[0], uri = await getSymfonyUri(version, os_version);
'tools', url = github + 'symfony/cli/' + uri;
data['version'], script += await addArchive('symfony', url, os_version);
data['os_version']
);
break;
case 'custom-function' === data['type']:
script += await functionRecord[data['function']](data);
break;
case /^none$/.test(data['tool']):
break; break;
default: default:
script += await utils.addLog( script += await utils.addLog(
'$cross', '$cross',
data['tool'], tool,
'Tool ' + data['tool'] + ' is not supported', 'Tool ' + tool + ' is not supported',
data['os_version'] os_version
); );
break; break;
} }

View File

@ -1,8 +1,7 @@
import {IncomingMessage, OutgoingHttpHeaders} from 'http'; import {IncomingMessage} from 'http';
import * as fs from 'fs'; import * as fs from 'fs';
import * as https from 'https'; import * as https from 'https';
import * as path from 'path'; import * as path from 'path';
import * as url from 'url';
import * as core from '@actions/core'; import * as core from '@actions/core';
/** /**
@ -50,60 +49,32 @@ export async function getInput(
/** /**
* Function to fetch an URL * Function to fetch an URL
* *
* @param input_url * @param url
* @param auth_token
*/ */
export async function fetch( export async function fetch(url: string): Promise<string> {
input_url: string, const fetch_promise: Promise<string> = new Promise(resolve => {
auth_token?: string const req = https.get(url, (res: IncomingMessage) => {
): Promise<Record<string, string>> { res.setEncoding('utf8');
const fetch_promise: Promise<Record<string, string>> = new Promise( let body = '';
resolve => { res.on('data', chunk => (body += chunk));
const url_object: url.UrlObject = new url.URL(input_url); res.on('end', () => resolve(body));
const headers: OutgoingHttpHeaders = { });
'User-Agent': `Mozilla/5.0 (${process.platform} ${process.arch}) setup-php` req.end();
}; });
if (auth_token) {
headers.authorization = 'Bearer ' + auth_token;
}
const options: https.RequestOptions = {
hostname: url_object.hostname,
path: url_object.pathname,
headers: headers
};
const req = https.get(options, (res: IncomingMessage) => {
if (res.statusCode != 200) {
resolve({error: `${res.statusCode}: ${res.statusMessage}`});
} else {
let body = '';
res.setEncoding('utf8');
res.on('data', chunk => (body += chunk));
res.on('end', () => resolve({data: `${body}`}));
}
});
req.end();
}
);
return await fetch_promise; return await fetch_promise;
} }
/** Function to get manifest URL
*
*/
export async function getManifestURL(): Promise<string> {
return 'https://raw.githubusercontent.com/shivammathur/setup-php/develop/src/configs/php-versions.json';
}
/** /**
* Function to parse PHP version. * Function to parse PHP version.
* *
* @param version * @param version
*/ */
export async function parseVersion(version: string): Promise<string> { export async function parseVersion(version: string): Promise<string> {
const manifest = await getManifestURL(); const manifest =
'https://raw.githubusercontent.com/shivammathur/setup-php/releases/v1/src/configs/php-versions.json';
switch (true) { switch (true) {
case /^(latest|\d+\.x)$/.test(version): case /^(latest|\d+\.x)$/.test(version):
return JSON.parse((await fetch(manifest))['data'])[version]; return JSON.parse(await fetch(manifest))[version];
default: default:
switch (true) { switch (true) {
case version.length > 1: case version.length > 1:
@ -239,14 +210,10 @@ export async function addLog(
* Read the scripts * Read the scripts
* *
* @param filename * @param filename
* @param directory
*/ */
export async function readFile( export async function readScript(filename: string): Promise<string> {
filename: string,
directory: string
): Promise<string> {
return fs.readFileSync( return fs.readFileSync(
path.join(__dirname, '../' + directory, filename), path.join(__dirname, '../src/scripts/' + filename),
'utf8' 'utf8'
); );
} }
@ -283,9 +250,6 @@ export async function extensionArray(
return extension_csv return extension_csv
.split(',') .split(',')
.map(function (extension: string) { .map(function (extension: string) {
if (/.+-.+\/.+@.+/.test(extension)) {
return extension;
}
return extension return extension
.trim() .trim()
.toLowerCase() .toLowerCase()
@ -353,148 +317,3 @@ export async function suppressOutput(os_version: string): Promise<string> {
); );
} }
} }
/**
* Function to get script to log unsupported extensions.
*
* @param extension
* @param version
* @param os_version
*/
export async function getUnsupportedLog(
extension: string,
version: string,
os_version: string
): Promise<string> {
return (
'\n' +
(await addLog(
'$cross',
extension,
[extension, 'is not supported on PHP', version].join(' '),
os_version
)) +
'\n'
);
}
/**
* Function to get command to setup tools
*
* @param os_version
* @param suffix
*/
export async function getCommand(
os_version: string,
suffix: string
): Promise<string> {
switch (os_version) {
case 'linux':
case 'darwin':
return 'add_' + suffix + ' ';
case 'win32':
return 'Add-' + suffix.charAt(0).toUpperCase() + suffix.slice(1) + ' ';
default:
return await log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}
/**
* Function to join strings with space
*
* @param str
*/
export async function joins(...str: string[]): Promise<string> {
return [...str].join(' ');
}
/**
* Function to get script extensions
*
* @param os_version
*/
export async function scriptExtension(os_version: string): Promise<string> {
switch (os_version) {
case 'win32':
return '.ps1';
case 'linux':
case 'darwin':
return '.sh';
default:
return await log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}
/**
* Function to get script tool
*
* @param os_version
*/
export async function scriptTool(os_version: string): Promise<string> {
switch (os_version) {
case 'win32':
return 'pwsh';
case 'linux':
case 'darwin':
return 'bash';
default:
return await log(
'Platform ' + os_version + ' is not supported',
os_version,
'error'
);
}
}
/**
* Function to get script to add tools with custom support.
*
* @param pkg
* @param type
* @param version
* @param os_version
*/
export async function customPackage(
pkg: string,
type: string,
version: string,
os_version: string
): Promise<string> {
const pkg_name: string = pkg.replace(/\d+|(pdo|pecl)[_-]/, '');
const script_extension: string = await scriptExtension(os_version);
const script: string = path.join(
__dirname,
'../src/scripts/' + type + '/' + pkg_name + script_extension
);
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
* @param prefix
*/
export async function parseExtensionSource(
extension: string,
prefix: string
): Promise<string> {
// Groups: extension, domain url, org, repo, release
const regex = /(\w+)-(.+:\/\/.+(?:[.:].+)+\/)?([\w.-]+)\/([\w.-]+)@(.+)/;
const matches = regex.exec(extension) as RegExpExecArray;
matches[2] = matches[2] ? matches[2].slice(0, -1) : 'https://github.com';
return await joins(
'\nadd_extension_from_source',
...matches.splice(1, matches.length),
prefix
);
}

View File

@ -1,5 +1,6 @@
{ {
"compilerOptions": { "compilerOptions": {
"declaration": true,
"esModuleInterop": true, "esModuleInterop": true,
"lib": [ "lib": [
"ES2020" "ES2020"
@ -15,4 +16,4 @@
"target": "ES2019" "target": "ES2019"
}, },
"exclude": ["__tests__", "lib", "node_modules"] "exclude": ["__tests__", "lib", "node_modules"]
} }