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
Closed

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Nov 19, 2017

After a lot of discussions with people at Symfony con I came up with a "perfect" travis file.

See php-http/client-common#90 (comment) for info.
Btw, should I make a table explaining what we really test? (Like on the client-common PR)

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this. I have two quick questions:

  1. Shouldn't we recommend to use PHPUnit Bridge here instead of just PHPUnit?

  2. Is it really necessary to create so many test jobs? Specifically, this looks like too much:

             - php: 5.5
             - php: 5.6
             - php: 7.0
             - php: 7.1
             - php: 7.2

Thanks!

- $TEST_COMMAND



Copy link
Member

Choose a reason for hiding this comment

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

few extra lines here

- php: 7.2
env: DEPENDENCIES="symfony/lts:v2"
- php: 7.2
env: DEPENDENCIES="symfony/lts:v3"
Copy link
Member

@dunglas dunglas Nov 20, 2017

Choose a reason for hiding this comment

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

Shouldn't we also add "symfony/lts": "^4@dev" to ensure that it works when using only 4.x packages (it's the default when using symfony/skeleton)?

Copy link
Member

Choose a reason for hiding this comment

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

normal jobs will already cover this, as 4.x will be the latest version anyway.

"symfony/lts": "^4@dev" will not forbid using a 3.x component anyway. It will only forbid using a 5.x one. The version 4 of the LTS package will be useless until we reach the 4.4 era (which is why it won't be stable until that time either)

include:
# Minimum supported PHP and Symfony version
- php: 5.5
env: DEPENDENCIES="minimum" COVERAGE=true TEST_COMMAND="phpunit --coverage-text"
Copy link
Member

@dunglas dunglas Nov 20, 2017

Choose a reason for hiding this comment

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

--prefer-stable --prefer-lowest should be tested with the latest version of PHP instead of the oldest (as done in Symfony), because most problems occur especially in this case (running old code on a cutting edge runtime).


# Latest beta release
- php: 7.2
env: DEPENDENCIES="beta"
Copy link
Member

Choose a reason for hiding this comment

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

people should rather test latest dev than latest beta. Most libraries don't release beta releases (Twig for instance will not have a beta release before the stable one). The goal of this job is to catch incompatibilities with future releases as early as possible.
This job is not only about Symfony itself, but also about other libraries they depend on.

@@ -476,3 +539,4 @@ Learn more
.. _`Packagist`: https://packagist.org/
.. _`choose any license`: http://choosealicense.com/
.. _`valid license identifier`: https://spdx.org/licenses/
.. _`Travis CI`: travis-ci.org
Copy link
Member

Choose a reason for hiding this comment

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

use https://travis-ci.org (btw, I think the current link would be broken, as it would be a relative link, and so would stay on symfony.com)

install:
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
Copy link
Member

Choose a reason for hiding this comment

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

travis_retry is useless IMO:

  • the download endpoints of Github are reliable now (4 years ago, they would fail randomly)
  • if the dependency resolution itself fails, retrying will only make the output less readable (due to displaying the failure 3 times). It will not allow it to succeed.

- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction

script:
- $TEST_COMMAND
Copy link
Member

Choose a reason for hiding this comment

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

for shared bundle, I would recommend another test command as well, which I started adding recently (FOSUserBundle does not have it yet, but KnpMenuBundle does. See KnpLabs/KnpMenuBundle#351 for the reasoning):

composer validate --strict --no-check-lock

- $HOME/.composer/cache/files
env:
global:
- TEST_COMMAND="phpunit"
Copy link
Member

Choose a reason for hiding this comment

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

Using phpunit as test command on Travis tends to create issue depending on your supported PHP versions: PHP 7 comes with PHPUnit 6, while PHP 5.3 images (for bundles still supporting it) come with a 4.8 version before the introduction of the namespaced classes.


A popular way to test open source bundles is by using `Travis CI`_. A good practice
is to support at least the two latest LTS versions of symfony. One should also test
test latest beta release. Here is a recommended configuration file (``.travis.yml``).
Copy link
Member

Choose a reason for hiding this comment

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

I would put a few other recommendations for their CI setup:

  • have a dev requirement on the symfony/phpunit-bridge "^3.3 || ^4" and run it in strict mode (which is the default), so that any usage of a deprecated API is catched. The only job where I'm allowing weak mode is the lowest job (because then, a version of your dependency may trigger a deprecation just because it went older than the release using the new API, which might be very hard to avoid in this job if it is a transitive dependency)
  • recommend enabling a Travis cron if your repository is not very active, so that failures on the unstable jobs due to an upstream change have a chance to occur before this change becomes stable. If the repo is very active, this is useless (because some activity-related build will also catch it), but most bundles are far less active than Symfony and will benefit from it (I generally use a monthly cron, but you could make it a weekly one instead)

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds like an excellent idea to me (and was not aware thats possible). often, i notice such problems when somebody does a small contribution or even provides a trivial typo fix, and then wonder why that makes the build break. so far i manually restarted master to be sure, but that would automate that away and we would be aware of problems earlier.

weekly sounds like a good rate to me.

- php: 7.2
env: DEPENDENCIES="symfony/lts:v2"
- php: 7.2
env: DEPENDENCIES="symfony/lts:v3"
Copy link
Member

Choose a reason for hiding this comment

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

normal jobs will already cover this, as 4.x will be the latest version anyway.

"symfony/lts": "^4@dev" will not forbid using a 3.x component anyway. It will only forbid using a 5.x one. The version 4 of the LTS package will be useless until we reach the 4.4 era (which is why it won't be stable until that time either)

@stof
Copy link
Member

stof commented Nov 21, 2017

@javiereguiluz testing all PHP versions supported by your bundle is a must-have IMO (PHP is bad at following semver, so you cannot only test the low and high ones).

Btw, this gives me another recommendation: always have a job for the lowest PHP minor version you support. If you cannot have CI for it, you must remove it from your composer.json instead (so that Composer installs an older tested release instead of thinking the new untested release is fine).

@stof
Copy link
Member

stof commented Nov 24, 2017

@Nyholm can you finish this PR ?

@stof
Copy link
Member

stof commented Nov 24, 2017

Status: needs work

@Nyholm
Copy link
Member Author

Nyholm commented Nov 24, 2017

Yes. I will finish it this weekend. Thank you for all the feedback!

Copy link
Contributor

@theofidry theofidry left a comment

Choose a reason for hiding this comment

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

👍 for it

.. 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.

- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we drop 5.5-7.0?

@Nyholm
Copy link
Member Author

Nyholm commented Nov 25, 2017

Thank you for all the feedback. I've made some updates accordingly.

I will test this travis.yaml file in a php-http/client-common to see the changes "in the wild"

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

great idea!

is it correct to make the example with php 7.0, 7.1 and 7.2? or should we add 5.6 to the example because of the older symfony LTS versions?

fast_finish: true
include:
# Minimum supported PHP and Symfony version
- php: 7.2
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be 7.0 ? or is the comment wrong?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wrong comment. Thank you


# Test LTS versions
- php: 7.2
env: DEPENDENCIES="symfony/lts:^2"
Copy link
Contributor

Choose a reason for hiding this comment

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

is there somewhere a bit more documentation about the effect of the lts package so that we could link to that? people might be confused by this when there is no explanation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment

- if [ "$DEPENDENCIES" = "dev" ]; then composer config minimum-stability dev; fi;
- if [[ $DEPENDENCIES == *"/"* ]]; then composer require --no-update $DEPENDENCIES; fi;

install:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget to add vendor/bin/simple-phpunit install here (as you did on httplug) to have the installation output be collapsed by default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

------

A popular way to test open source bundles is by using `Travis CI`_. A good practice
is to support at least the two latest LTS versions of symfony. One should also test
Copy link
Member

Choose a reason for hiding this comment

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

Symfony

include:
# Minimum supported Symfony version
- php: 7.2
env: DEPENDENCIES="minimum" COVERAGE=true TEST_COMMAND="phpunit --coverage-text" SYMFONY_DEPRECATIONS_HELPER="weak"
Copy link
Member

Choose a reason for hiding this comment

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

Why phpunit here and not ./vendor/bin/simple-phpunit?

- php: 7.1
- php: 7.2

# Test LTS versions. This makes sure we do not use symfony packages with version greater
Copy link
Member

Choose a reason for hiding this comment

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

Symfony :)


allow_failures:
# Latest beta is allowed to fail.
- php: 7.2
Copy link
Member

Choose a reason for hiding this comment

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

I would omit the PHP version to not have to change two places when a new PHP version is tested (which is likely to be forgotten)

before_install:
- composer require --no-update "symfony/phpunit-bridge:^3.3 || ^4"
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if [ "$DEPENDENCIES" = "minimum" ]; then COMPOSER_FLAGS="--prefer-stable --prefer-lowest"; fi;
Copy link
Member

Choose a reason for hiding this comment

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

Why not set $COMPOSER_FLAGS directly above instead?

- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if [ "$DEPENDENCIES" = "minimum" ]; then COMPOSER_FLAGS="--prefer-stable --prefer-lowest"; fi;
- if [ "$DEPENDENCIES" = "dev" ]; then composer config minimum-stability dev; fi;
- if [[ $DEPENDENCIES == *"/"* ]]; then composer require --no-update $DEPENDENCIES; fi;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's not use $DEPENDENCIES for two different things, but use two variables instead.

- composer validate --strict --no-check-lock
- $TEST_COMMAND

When configuring travis you should also enable `Travis cron`_ to make sure your
Copy link
Member

Choose a reason for hiding this comment

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

"Travis CI" instead of "travis"?

@Nyholm
Copy link
Member Author

Nyholm commented Nov 29, 2017

I've made some updates, I need to check if this works properly.

Does it look good at least?


allow_failures:
# Latest beta is allowed to fail.
- php: 7.2
Copy link
Member

Choose a reason for hiding this comment

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

I would still remove the PHP version here

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I missed that.

env: STABILITY="dev"

allow_failures:
# Latest beta is allowed to fail.
Copy link
Member

Choose a reason for hiding this comment

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

in fact, we are not testing beta versions

fast_finish: true
include:
# Minimum supported Symfony version with the latest PHP version
- env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="./vendor/bin/simple-phpunit --coverage-text" SYMFONY_DEPRECATIONS_HELPER="weak"
Copy link
Member

Choose a reason for hiding this comment

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

I recommand to put the coverage on a recent version instead of the lowest one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you

@Nyholm
Copy link
Member Author

Nyholm commented Jan 13, 2018

@javiereguiluz and @weaverryan. Im done with this PR now (as I can tell from the reviews). I think it is ready to merge.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

@Nyholm thanks! This is really nice and definitely useful for many people.

I made some rewords to focus on the general idea ("continuous integration") instead of the specific service used today to achieve that (Travis).

@Nyholm
Copy link
Member Author

Nyholm commented Jan 13, 2018

Thank you!

@javiereguiluz javiereguiluz added this to the 4.0 milestone Jan 13, 2018
@javiereguiluz
Copy link
Member

This is finally merged! Thanks Tobias.

javiereguiluz added a commit that referenced this pull request Jan 15, 2018
…luz)

This PR was submitted for the master branch but it was merged into the 4.0 branch instead (closes #8701).

Discussion
----------

Added a good example of a travis file

After a lot of discussions with people at Symfony con I came up with a "perfect" travis file.

See php-http/client-common#90 (comment) for info.
Btw, should I make a table explaining what we really test? (Like on the client-common PR)

Commits
-------

93bdb86 Rewords
4bd8e65 Minor updates
bc9a43f use ./ before vendor
ae322b7 typo
1017897 Using better cache syntax
36ca90b Using PHPUNIT_FLAGS
18e4a18 Added back php-versions
05bf09d Moved coverage to PHP 7.2 with latest deps
bfdd064 Fixed minor things
3e2b876 Fixed typos and created more variables
a62bcb7 Added comment and install simple-phpunit deps
65f91df Use tilde or composer validate will never pass
179abb0 Updated according to feedback
a281604 Typo
2418834 Added a good example travis file
@dbu
Copy link
Contributor

dbu commented Jan 15, 2018

awesome!

how to get to this page in the navigation? search finds it, but the "Bundles" point in the navigation does not find it: https://symfony.com/doc/bundles/ . and its not in https://symfony.com/doc/current/best_practices/index.html ...

@javiereguiluz
Copy link
Member

@dbu in the sidebar navigation menu, click on the "Bundles" option (https://symfony.com/doc/current/bundles.html) and at the bottom of it you'll find all the related articles, including this one: https://symfony.com/doc/current/bundles/best_practices.html.

And the contents of this pull request are already available: https://symfony.com/doc/current/bundles/best_practices.html#continuous-integration

@dbu
Copy link
Contributor

dbu commented Jan 15, 2018

yeah i noticed its available :-)

i did not click on the guide for bundles, but on "Symfony Bundles" which is a list of existing bundles. maybe that list should have an intro that says this is about existing bundles you can use in your projects, and link to the guide for when you want to write your own bundle.

i don't find the source for https://symfony.com/doc/bundles/ in the symfony-docs repository however, otherwise i would have proposed something.

@Nyholm Nyholm deleted the travis branch January 15, 2018 09:21
dbu pushed a commit to rokka-io/rokka-client-bundle that referenced this pull request Jan 16, 2020
- class alias must be defined after the class is defined
- explicit public declaration on services for compatibility between sf 3 and 4
- use conditional config deprecation for api secret
- better travis according to symfony/symfony-docs#8701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.