-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Conversation
There was a problem hiding this 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:
-
Shouldn't we recommend to use PHPUnit Bridge here instead of just PHPUnit?
-
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!
bundles/best_practices.rst
Outdated
- $TEST_COMMAND | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few extra lines here
bundles/best_practices.rst
Outdated
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:v2" | ||
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:v3" |
There was a problem hiding this comment.
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
)?
There was a problem hiding this comment.
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)
bundles/best_practices.rst
Outdated
include: | ||
# Minimum supported PHP and Symfony version | ||
- php: 5.5 | ||
env: DEPENDENCIES="minimum" COVERAGE=true TEST_COMMAND="phpunit --coverage-text" |
There was a problem hiding this comment.
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).
bundles/best_practices.rst
Outdated
|
||
# Latest beta release | ||
- php: 7.2 | ||
env: DEPENDENCIES="beta" |
There was a problem hiding this comment.
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.
bundles/best_practices.rst
Outdated
@@ -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 |
There was a problem hiding this comment.
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)
bundles/best_practices.rst
Outdated
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 |
There was a problem hiding this comment.
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.
bundles/best_practices.rst
Outdated
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction | ||
|
||
script: | ||
- $TEST_COMMAND |
There was a problem hiding this comment.
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
bundles/best_practices.rst
Outdated
- $HOME/.composer/cache/files | ||
env: | ||
global: | ||
- TEST_COMMAND="phpunit" |
There was a problem hiding this comment.
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.
bundles/best_practices.rst
Outdated
|
||
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``). |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
bundles/best_practices.rst
Outdated
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:v2" | ||
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:v3" |
There was a problem hiding this comment.
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)
@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). |
@Nyholm can you finish this PR ? |
Status: needs work |
Yes. I will finish it this weekend. Thank you for all the feedback! |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
bundles/best_practices.rst
Outdated
- php: 5.5 | ||
- php: 5.6 | ||
- php: 7.0 | ||
- php: 7.1 |
There was a problem hiding this comment.
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?
Thank you for all the feedback. I've made some updates accordingly. I will test this travis.yaml file in a |
There was a problem hiding this 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?
bundles/best_practices.rst
Outdated
fast_finish: true | ||
include: | ||
# Minimum supported PHP and Symfony version | ||
- php: 7.2 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong comment. Thank you
bundles/best_practices.rst
Outdated
|
||
# Test LTS versions | ||
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:^2" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment
bundles/best_practices.rst
Outdated
- if [ "$DEPENDENCIES" = "dev" ]; then composer config minimum-stability dev; fi; | ||
- if [[ $DEPENDENCIES == *"/"* ]]; then composer require --no-update $DEPENDENCIES; fi; | ||
|
||
install: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
bundles/best_practices.rst
Outdated
------ | ||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symfony
bundles/best_practices.rst
Outdated
include: | ||
# Minimum supported Symfony version | ||
- php: 7.2 | ||
env: DEPENDENCIES="minimum" COVERAGE=true TEST_COMMAND="phpunit --coverage-text" SYMFONY_DEPRECATIONS_HELPER="weak" |
There was a problem hiding this comment.
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
?
bundles/best_practices.rst
Outdated
- php: 7.1 | ||
- php: 7.2 | ||
|
||
# Test LTS versions. This makes sure we do not use symfony packages with version greater |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symfony :)
bundles/best_practices.rst
Outdated
|
||
allow_failures: | ||
# Latest beta is allowed to fail. | ||
- php: 7.2 |
There was a problem hiding this comment.
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)
bundles/best_practices.rst
Outdated
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; |
There was a problem hiding this comment.
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?
bundles/best_practices.rst
Outdated
- 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; |
There was a problem hiding this comment.
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.
bundles/best_practices.rst
Outdated
- composer validate --strict --no-check-lock | ||
- $TEST_COMMAND | ||
|
||
When configuring travis you should also enable `Travis cron`_ to make sure your |
There was a problem hiding this comment.
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"?
I've made some updates, I need to check if this works properly. Does it look good at least? |
bundles/best_practices.rst
Outdated
|
||
allow_failures: | ||
# Latest beta is allowed to fail. | ||
- php: 7.2 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I missed that.
bundles/best_practices.rst
Outdated
env: STABILITY="dev" | ||
|
||
allow_failures: | ||
# Latest beta is allowed to fail. |
There was a problem hiding this comment.
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
bundles/best_practices.rst
Outdated
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
@javiereguiluz and @weaverryan. Im done with this PR now (as I can tell from the reviews). I think it is ready to merge. |
There was a problem hiding this 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).
Thank you! |
This is finally merged! Thanks Tobias. |
…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
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 ... |
@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 |
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. |
- 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
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)