Skip to content

Added a good example of a travis file #8701

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

Closed
wants to merge 15 commits into from
76 changes: 76 additions & 0 deletions bundles/best_practices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,80 @@ the ``Tests/`` directory. Tests should follow the following principles:
A test suite must not contain ``AllTests.php`` scripts, but must rely on the
existence of a ``phpunit.xml.dist`` file.

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
sudo: false
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC sudo is no longer required

Copy link
Member Author

Choose a reason for hiding this comment

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

I did some searching just now. I cannot find any references to this.. Can you provide a link?

Copy link
Contributor

Choose a reason for hiding this comment

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

Before sudo was enabled by default and there was a deprecation for a while stating if you want sudo you need to explicitly require it. You can see here that if you do need sudo, you should put sudo: required. Might be worth to double check what the actual default is though

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, Same page says:

Container-based with sudo: false

When specifying sudo: false, Travis CI runs each build in a container on a shared host via Docker. The container contents are a pristine copy of the Docker image, as guaranteed by Docker itself.

The advantage of running with sudo: false is dramatically reduced time between commit push to GitHub and the start of a job on Travis CI, which works especially well when one’s average job duration is under 3 minutes.

NOTE: The allowed list of packages that may be installed varies between Precise and Trusty, with the Precise list being considerably larger at the time of this writing. If the packages you need are not yet available on Trusty, it is recommended that you either target dist: precise or sudo: required depending on your needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends on the build distribution, see here. Newer builds, or builds explicitly using dist: trusty will ignore the sudo: setting.

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="weak"
- php: 7.0
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"

# Test the latest stable release
- php: 7.0
- 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:
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
- ./vendor/bin/simple-phpunit install

script:
- composer validate --strict --no-check-lock
Copy link
Contributor

Choose a reason for hiding this comment

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

whats the point of this? wouldn't composer update fail if the composer.json is invalid which is run before anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

afaik the --strict makes this fail even if there are just warnings (e.g. composer.json is not suitable for publishing, alphabetical order of dependencies etc)

- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS

Consider using `Travis cron`_ too to make sure your project is built even if
there are no new pull requests or commits.

Installation
------------

Expand Down Expand Up @@ -476,3 +550,5 @@ Learn more
.. _`Packagist`: https://packagist.org/
.. _`choose any license`: http://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/