ramsey / composer-install

:gift: A GitHub Action to streamline installation of PHP dependencies with Composer.
MIT License
233 stars 32 forks source link

Misleading error message when validate_composer fails due to missing HOME/COMPOSER_HOME #250

Open mdio opened 1 year ago

mdio commented 1 year ago

Description

If neither HOME nor COMPOSER_HOME env vars are set, validate_composer will exit with non-zero but the error message is redirected to /dev/null. I had to fork the repo, remove the output redirection to see the issue:

Error: The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly

My suggestion would be to either add a check for HOME/COMPOSER_HOME being set and adding a targeted error message if not or to show the output of composer validate in case it fails.

The latter would also help with future issues composer validate might have.

Steps to reproduce

  1. Ensure composer.json is valid by running composer validate locally.
  2. Run composer-install in an env where HOME/COMPOSER_HOME are not set (e.g. in a self-hosted runner or maybe by unsetting them via env: [HOME: '', COMPOSER_HOME: ''])
  3. See the action fail.

Expected behavior

composer-install finishes successfully.

Output

Run ${GITHUB_ACTION_PATH}/bin/composer_paths.sh \
Error: The composer.json file at './composer.json' does not validate; run 'composer validate' to check for errors
Error: Process completed with exit code 1.

Environment details

Additional context

Complete tests.yaml

name: tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  tests:
    strategy:
      matrix:
        php-versions: ['8.0', '8.1', '8.2']
        dependency-versions: ['lowest', 'highest']

    runs-on: [ self-hosted ]

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php-versions }}

    - name: Cache Composer packages
      id: composer-cache
      uses: actions/cache@v3
      with:
        path: vendor
        key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
        restore-keys: |
          ${{ runner.os }}-php-

    - name: Install dependencies
      uses: researchgate/composer-install@v2
      with:
        dependency-versions: ${{ matrix.dependency-versions }}

    - name: Run test suite
      run: vendor/bin/phpunit
ramsey commented 1 year ago

Thank you for the very good description on how to reproduce. I'll look into this.