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

Use the ramsey/composer-install action to install dependencies #16

Merged
merged 1 commit into from
Dec 7, 2020
Merged

Use the ramsey/composer-install action to install dependencies #16

merged 1 commit into from
Dec 7, 2020

Conversation

nicwortel
Copy link
Contributor

While migrating doctrine/data-fixtures from Travis CI to GitHub Actions (doctrine/data-fixtures#353), looking for an elegant way to add a job with the lowest dependency versions I came across the composer-install action made by @ramsey.

This action makes it easy to choose between installing locked versions (composer install), highest versions (composer update), and lowest versions (composer update --prefer-lowest). The --no-interaction, --no-progress, and --ansi flags are automatically added to the command. It also handles caching of dependencies to improve build times.

In other words, something like this:

      - name: "Cache dependencies installed with composer"
        uses: "actions/cache@v2"
        with:
          path: "~/.composer/cache"
          key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
          restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

      - name: "Install dependencies with composer"
        run: "composer update --no-interaction --no-progress --no-suggest"
        if: "${{ matrix.dependencies == 'highest' }}"

      - name: "Install lowest possible dependencies with composer"
        run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-lowest"
        if: "${{ matrix.dependencies == 'lowest' }}"

can be rewritten to this:

      - name: "Install dependencies with composer"
        uses: "ramsey/composer-install@v1"
        with:
          dependency-versions: "${{ matrix.dependencies }}"
          composer-options: "--prefer-dist --no-suggest"

I believe this greatly improves the readability and maintainability of GitHub Actions workflows in the Doctrine organization.

As suggested by @greg0ire I'm opening this PR to discuss the usage of this GitHub Action on an organization level.

This reusable action installs and caches Composer dependencies. The
--no-interaction, --no-progress, and --ansi flags are added automatically.
It can also handle installing highes (composer update) or lowest (composer
update --prefer-lowest) versions of dependencies.

See https://github.com/marketplace/actions/install-composer-dependencies.
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests of the action seem to cover the replaced steps.

@greg0ire greg0ire merged commit af0dc37 into doctrine:main Dec 7, 2020
@greg0ire
Copy link
Member

greg0ire commented Dec 7, 2020

Thanks @nicwortel, I think you can go ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants