2

I'm trying to get my unit-tests to run via GitHub Actions on a pull_request.

I can see the actions running when I update my PR but the PHP version doesn't update when it tries to composer install my project.

Command: composer install --no-interaction --no-suggest --no-progress
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php ~7.3.0 but your PHP version (7.4.10) does not satisfy that requirement.

I've tried multiple different workflow files, and this was the one that gave me the most control, but it still seems to be running on php 7.4.

name: Run Tests

on:
  pull_request:
    branches:
      - master

jobs:
  build:
    runs-on: ${{ matrix.operating-system }}
    strategy:
      matrix:
        operating-system: [ubuntu-latest]
        php-versions: ['7.3']

    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.php-versions }}
      - uses: php-actions/composer@v2
      - uses: php-actions/phpunit@v8

Finally, here is the snippet from my composer json that shows the constraint:

"require": {
    "php": "~7.3.0",
    "guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
    "phpunit/phpunit": "^8"
}
4
  • Can also confirm that the shivammathur/setup-php@v2 step is running first, and responds with : PHP Switched to PHP 7.3.22 Commented Sep 19, 2020 at 3:28
  • What makes you think that a completely different action (like php-actions/composer@v2) knows which PHP version to use? As far as I see, it uses a different container Commented Sep 19, 2020 at 11:47
  • It does? I'm kind of new to github actions. I thought the build set the container, and the steps all ran on the build. Why would composer need to spin up a new container? How would that even work if checkout is what checks out your repo, and you wanted to composer install on your container. What would the point of a composer@v2 action be if it starts a new container and does.... what with it exactly? Commented Sep 19, 2020 at 19:26
  • If you write this up as an answer, i'll mark it as complete. I was able to run composer directly rather through an action thanks to your suggestion. Seems a little limiting of the package owners to force a version of PHP when composer has the ability to fix a version! I didn't realise each step was it's own container! Commented Sep 19, 2020 at 20:01

1 Answer 1

1

You can force the PHP version for the composer action by adding in your .github/workflows/YOURACTION.yaml

  - name: Build Composer
    uses: php-actions/composer@v5
    with:
      ssh_key: ${{ secrets.ssh_key }}
      ssh_key_pub: ${{ secrets.ssh_key_pub }}
      php_version: 7.2

Notice I did it on the Composer step and not on the shivammathur/setup-php@v2 Try removing this step all together, u might not need it at all.

See more here: https://github.com/marketplace/actions/composer-php-actions

Sign up to request clarification or add additional context in comments.

1 Comment

This is a new feature that the module owner put in fairly recently. I spoke with him on reddit a few months ago and he confirmed you can now do this! Great news :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.