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

Expose installed PHP version as environment variable #470

Closed
ruudk opened this issue Jun 29, 2021 · 3 comments
Closed

Expose installed PHP version as environment variable #470

ruudk opened this issue Jun 29, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@ruudk
Copy link

ruudk commented Jun 29, 2021

Describe the feature
It would be really helpful if the selected & installed php version would be exposed as an environment variable. This can then be used to construct caching keys.

Version
2.11.0

Underlying issue
I use the following YAML config to install PHP:

env:
      PHP_VERSION: 8
jobs:
# ...
        steps:
# ...
            -   name: Setup PHP
                uses: shivammathur/setup-php@2.11.0
                with:
                    php-version: ${{ env.PHP_VERSION }}
            -   name: Cache cache directory for phpstan/phpstan
                uses: actions/cache@v2.1.6
                with:
                    path: var/phpstan
                    key: ${{ runner.os }}-php-${{ env.PHP_VERSION }}-phpstan-${{ hashFiles('composer.json', 'composer.lock', 'phpstan.neon', 'phpstan-baseline.neon') }}-
                    restore-keys: ${{ runner.os }}-php-${{ env.PHP_VERSION }}-phpstan-

The action automatically installs the latest version when specifying 8 as input version. This is great.

==> Setup PHP
✓ PHP Found PHP 8.0.7

But now my cache key is always bound to 8 instead of the actual version.

Describe alternatives
Of course, I could run php -v command and export the version to the env var myself to solve this.

But I do believe more people will encounter this and that it would be great if the action would support it.

Are you willing to submit a PR?
If you can point me to where to apply this I would.

@ruudk ruudk added the enhancement New feature or request label Jun 29, 2021
@shivammathur
Copy link
Owner

For using the semver PHP version in actions/cache keys, you will need steps outputs from setup-php.
https://github.com/actions/toolkit/blob/main/docs/commands.md#set-outputs
But using semver would clear the cache for each new PHP patch version, is that the intended consequence? If yes, I will add this in the next release.

On a side note instead of 8, you should specify '8.0' (with quotes) for PHP 8.0 or latest if you always want the latest stable version.
https://github.com/shivammathur/setup-php#php-version-required

@ruudk
Copy link
Author

ruudk commented Jun 29, 2021

But using semver would clear the cache for each new PHP patch version, is that the intended consequence? If yes, I will add this in the next release.

That's my intent indeed. When a major, minor or patch version of PHP is released, miss the cache and run without cache.

@shivammathur shivammathur added the awaiting-release Added/Fixed and tested, awaiting release label Jul 10, 2021
@shivammathur
Copy link
Owner

@ruudk
Added in 2.12.0
https://github.com/shivammathur/setup-php#php-version

- name: Setup PHP
  id: setup-php
  uses: shivammathur/setup-php@v2
  with:
    php-version: '7.4'

- name: Print PHP version
  run: echo ${{ steps.setup-php.outputs.php-version }}

@shivammathur shivammathur removed the awaiting-release Added/Fixed and tested, awaiting release label Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
setup-php-tasks
  
Awaiting triage
Development

No branches or pull requests

2 participants