shivammathur / setup-php

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.
https://setup-php.com
MIT License
2.91k stars 340 forks source link

GitHub-hosted Windows runners can't read environment variables defined in workflow file #759

Closed svenluijten closed 1 year ago

svenluijten commented 1 year ago

Describe the bug When using a Windows runner to setup PHP, it does not expand environment variables. Instead, it passes the name of the variable as a string through to extensions.

I've reproduced the issue here (run with debug logging enabled) so you can see what happens. I'll gladly assist in any way I can to get this resolved.

Version

Runners

Operating systems

Windows (latest, at time of submitting issue)

PHP versions

Supposedly all, but tested on 8.1 and 8.2.

To Reproduce

https://github.com/svenluijten/setup-php-issue/blob/main/.github/workflows/run.yml. Pasted below for posterity. I've verified all three different syntaxes as valid, as it works on macos-latest as well as ubuntu-latest. The GitHub documentation also states that this is possible.

Workflow file ```yml name: Run on: [push] env: GLOBAL_PHP_EXTENSIONS: mbstring, fileinfo jobs: run-with-global-env: name: Using global env runs-on: windows-latest steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: php-version: 8.2 extensions: $GLOBAL_PHP_EXTENSIONS coverage: none - name: Install dependencies run: composer install run-with-local-env: name: Using local env runs-on: windows-latest env: LOCAL_PHP_EXTENSIONS: mbstring, fileinfo steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: php-version: 8.2 extensions: $LOCAL_PHP_EXTENSIONS coverage: none - name: Install dependencies run: composer install run-without-env: name: Without env var runs-on: windows-latest steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 with: php-version: 8.2 extensions: mbstring, fileinfo coverage: none - name: Install dependencies run: composer install ```

Expected behavior I expect the mbstring and fileinfo extensions to be loaded.

Screenshots/Logs

##[debug]Evaluating condition for step: 'Run shivammathur/setup-php@v2'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Run shivammathur/setup-php@v2
##[debug]Loading inputs
##[debug]Loading env
Run shivammathur/setup-php@v2
"C:\Program Files\PowerShell\7\pwsh.exe" D:\a\_actions\shivammathur\setup-php\v2\src\scripts\run.ps1

==> Setup PhpManager 
√ PhpManager Installed 

==> Setup PHP 
√ PHP Found PHP 8.2.9 

==> Setup Extensions 
Add-Extension: D:\a\_actions\shivammathur\setup-php\v2\src\scripts\run.ps1:4
Line |
   4 |  Add-Extension $global_php_extensions
     |                ~~~~~~~~~~~~~~~~~~~~~~
     | Cannot validate argument on parameter 'extension'. The character length (0) of the argument is too short.
     | Specify an argument with a length that is greater than or equal to "1", and then try the command again.

==> Setup Tools 
√ composer Added composer 2.5.8 

==> Setup Coverage 
√ none Disabled Xdebug and PCOV 

==> #StandWithUkraine 
√ read-more https://setup-php.com/support-ukraine 
##[debug]Node Action run completed with exit code 0
##[debug]OPENSSL_CONF='C:\Program Files\Common Files\SSL\openssl.cnf'
##[debug]COMPOSER_PROCESS_TIMEOUT='0'
##[debug]COMPOSER_NO_INTERACTION='1'
##[debug]COMPOSER_NO_AUDIT='1'
##[debug]Set output php-version = 8.2.9
##[debug]Finishing: Run shivammathur/setup-php@v2

The above is copied from my reproduction repository.

Additional context I'm actually unsure if this is an issue with setup-php specifically, or if it is more of a GitHub-issue with their Windows runners. Some pointers would be helpful 🙂

Are you willing to submit a PR? I'll help any way I can, but I am not intimately familiar with the inner workings of GitHub Actions (let alone PowerShell, which the setup script for Windows runners is written in.

shivammathur commented 1 year ago

Please use ${{ env.GLOBAL_PHP_EXTENSIONS }} and ${{ env.LOCAL_PHP_EXTENSIONS }}, then it will pass the actual env value.

Ref: https://docs.github.com/en/actions/learn-github-actions/variables#using-the-env-context-to-access-environment-variable-values

svenluijten commented 1 year ago

Well that's confusing that it only breaks in Windows runners! But yep, that seems to have fixed the issue. Thanks for the (insanely!) quick response @shivammathur! 😄