Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add details on using other Github Actions to parse composer.json #751

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
- [Self Hosted Setup](#self-hosted-setup)
- [Local Testing Setup](#local-testing-setup)
- [JIT Configuration](#jit-configuration)
- [Dynamic Settings from Composer](#dynamic-settings-from-composer)
- [Cache Extensions](#cache-extensions)
- [Cache Composer Dependencies](#cache-composer-dependencies)
- [GitHub Composer Authentication](#github-composer-authentication)
Expand Down Expand Up @@ -727,6 +728,55 @@ For example to enable JIT in `tracing` mode with buffer size of `64 MB`.
ini-values: opcache.enable_cli=1, opcache.jit=tracing, opcache.jit_buffer_size=64M
```

### Dynamic Settings from Composer

If you would like to automatically keep setup-php in sync with PHP versions or required extensions listed in your composer.json, you can use other actions from the Github Actions ecosystem to easily parse your composer.json file.

- To set the PHP version for setup-php using [Composer's "platform" configuration setting](https://getcomposer.org/doc/06-config.md#platform), parse the version out of the composer.json using an action combination such as:
```yaml
- uses: actions/checkout@v3
- name: Get required PHP version
uses: sergeysova/jq-action@v2
id: php_version
with:
cmd: |
jq '.config.platform.php' composer.json -r
- name: Setup PHP runtime
uses: shivammathur/setup-php@v2
with:
php-version: "${{ steps.php_version.outputs.value }}"
```
- To set the PHP version for setup-php to the first PHP version listed in your composer.json "require" section, parse the value with an actions combination such as:
```yaml
- uses: actions/checkout@v3
- name: Get required PHP version
uses: sergeysova/jq-action@v2
id: php_version
with:
cmd: |
jq '.require.php | gsub("\\s.*$";"") | gsub("[^0-9\\.]";"")' composer.json -r
- name: Setup PHP runtime
uses: shivammathur/setup-php@v2
with:
php-version: "${{ steps.php_version.outputs.value }}"
```
- Similarly, you can get a list of required PHP extensions from composer.json with:
```yaml
- uses: actions/checkout@v3
- name: Get required PHP extensions
uses: sergeysova/jq-action@v2
id: php_extensions
with:
cmd: |
jq '.require | to_entries | map(select(.key | match("ext-";"i"))) | map(.key) | @csv | gsub("ext-";"")' composer.json -r
- name: Setup PHP runtime
uses: shivammathur/setup-php@v2
with:
extensions: "${{ steps.php_extensions.outputs.value }}"
```
- To set up multiple PHP versions in a range supported by your project, the [Composer PHP Versions in range
](https://github.com/marketplace/actions/composer-php-versions-in-range) can create a matrix of supported versions which can be used by setup-php.

### Cache Extensions

You can cache PHP extensions using `shivammathur/cache-extensions` and `action/cache` GitHub Actions. Extensions which take very long to set up when cached are available in the next workflow run and are enabled directly. This reduces the workflow execution time.
Expand Down