Skip to content

[Bundles] Update best practices to use Symfony Flex and do not favor any CI tool #14505

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

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 55 additions & 69 deletions bundles/best_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,73 +171,59 @@ Continuous Integration

Testing bundle code continuously, including all its commits and pull requests,
is a good practice called Continuous Integration. There are several services
providing this feature for free for open source projects. The most popular
service for Symfony bundles is called `Travis CI`_.

Here is the recommended configuration file (``.travis.yml``) for Symfony bundles,
which test the two latest :doc:`LTS versions </contributing/community/releases>`
of Symfony and the latest beta release:

.. code-block:: yaml

language: php

cache:
directories:
- $HOME/.composer/cache/files
- $HOME/symfony-bridge/.phpunit

env:
global:
- PHPUNIT_FLAGS="-v"
- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"

matrix:
fast_finish: true
include:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="max[self]=0"
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="max[self]=0"

# Test the latest stable release
- php: 7.1
- php: 7.2
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

# Test LTS versions. This makes sure we do not use Symfony packages with version greater
# than 2 or 3 respectively. Read more at https://github.com/symfony/lts
- php: 7.2
env: DEPENDENCIES="symfony/lts:^2"
- php: 7.2
env: DEPENDENCIES="symfony/lts:^3"

# Latest commit to master
- php: 7.2
env: STABILITY="dev"

allow_failures:
# Dev-master is allowed to fail.
- env: STABILITY="dev"

before_install:
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;

install:
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
- ./vendor/bin/simple-phpunit install

script:
- composer validate --strict --no-check-lock
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS

Consider using the `Travis cron`_ tool to make sure your project is built even if
there are no new pull requests or commits.
providing this feature for free for open source projects, like `GitHub Actions`_
and `Travis CI`_.

A bundle should at least test:

* The lower bound of their dependencies (by running ``composer update --prefer-lowest``);
* The supported PHP versions;
* All supported major Symfony versions (e.g. both ``3.x`` and ``4.x`` if
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* All supported major Symfony versions (e.g. both ``3.x`` and ``4.x`` if
* All supported major Symfony versions (e.g. both ``4.x`` and ``5.x`` if

support is claimed for both).

Thus, a bundle support PHP 7.3, 7.4 and 8.0, and Symfony 3.4 and 4.x should
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it still worth documenting v3.4?

Also for the travis config file, is it possible to use the langage toggle config feature php/xml/yaml but instead use it for toggling between for example github actions, travis, etc ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Thus, a bundle support PHP 7.3, 7.4 and 8.0, and Symfony 3.4 and 4.x should
Thus, a bundle supporting PHP 7.3, 7.4 and 8.0, and Symfony 3.4, 4.x and 5.x should

listing explicit versions is prone to be outdated after a while, but i think this is about the example, so getting outdated is ok.

have at least this test matrix:

=========== =============== ===================
PHP version Symfony version Composer flags
=========== =============== ===================
7.3 ``3.*`` ``--prefer-lowest``
7.4 ``4.*``
8.0 ``4.*``
=========== =============== ===================

.. tip::

The tests should be run with the ``SYMFONY_DEPRECATIONS_HELPER``
env variable set to ``max[direct]=0``. This ensures no code in the
bundle uses deprecated features directly.

The lowest dependency tests can be run with this variable set to
``disabled=1``.

Require a Specific Symfony Version
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can use the special ``SYMFONY_REQUIRE`` environment variable together
with Symfony Flex to install a specific Symfony version:

.. code-block:: bash

# this requires Symfony 5.x for all Symfony packages
export SYMFONY_REQUIRE=5.*

# install Symfony Flex in the CI environment
composer global require --no-progress --no-scripts --no-plugins symfony/flex

# install the dependencies (using --prefer-dist and --no-progress is
# recommended to have a better output and faster download time)
composer update --prefer-dist --no-progress

.. caution::

If you want to cache your Composer dependencies, **do not** cache the
``vendor/`` directory as this has side-effects. Instead cache
``$HOME/.composer/cache/files``.

Installation
------------
Expand Down Expand Up @@ -529,5 +515,5 @@ Learn more
.. _`Packagist`: https://packagist.org/
.. _`choose any license`: https://choosealicense.com/
.. _`valid license identifier`: https://spdx.org/licenses/
.. _`Travis CI`: https://travis-ci.org/
.. _`Travis cron`: https://docs.travis-ci.com/user/cron-jobs/
.. _`GitHub Actions`: https://docs.github.com/en/free-pro-team@latest/actions
.. _`Travis CI`: https://docs.travis-ci.com/