Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Development Workflow Tools for Open-Source PHP Libraries

787 visualizaciones

Publicado el

Having a fine-tuned continuous integration environment is extremely valuable, even for small projects. Today, there is a wide variety of standalone projects and online Software-As-A-Service offerings that can super-streamline your everyday development tasks that can help you get your projects up and running like a pro. In this session, we'll look at how you can get the most out of:
* GitHub source code repository
* Packagist package manager for Composer
* Travis CI continuous integration service
* Coveralls code coverage service
* Scrutinizer static analysis service
* Box2 phar builder
* Sami api documentation generator
* ReadTheDocs online documentation reader service
* Composer scripts and projects for running local tests and builds After mastering these tools, you will be able to quickly set up a new php library project and use it in your Drupal modules.

Session presented at Stanford Drupal Camp: https://drupalcamp.stanford.edu/development-workflow-tools-open-source-php-libraries

Publicado en: Tecnología
  • Sé el primero en comentar

Development Workflow Tools for Open-Source PHP Libraries

  1. 1. Development Workflow Tools for Open-Source PHP Libraries Greg Anderson @greg_1_anderson
  2. 2. Drupal Site Drupal Module Re-usable PHP Library
  3. 3. http://robo.li/framework/
  4. 4. { "name": "drupal/lcache", "description": "LCache module.", "type": "drupal-module", "license": "GPLv2", "require": { "lcache/lcache": "0.3.*" } } ● Add a minimal composer.json to module ● Use Composer to manage Drupal site ○ drupal-composer/drupal-project
  5. 5. REPEAT
  6. 6. HOWEVER, we also need: ● Collaboration ● Reproducibility ● Analysis of ○ Test coverage ○ Code Quality ○ Open Source License Compliance ● Documentation
  7. 7. https://xkcd.com/1205/
  8. 8. Collaborate with other engineers across multiple branches. Keep a record of all work done. Integrate With All Of The Things. Run tests and other tasks. Calculate test coverage. Analyze code complexity. Track dependency versions and licenses. Package manager for composer. Publish documentation site from markdown.
  9. 9. ● ● ● http://dilbert.com/strip/1996-01-31
  10. 10. ● ○ ○ ● ○ ○ ○ ● https://github.com
  11. 11. $ git clone … working-copy $ cd working-copy $ git checkout -b mywork $ git add -A . $ git commit -m "Awesomesauce." $ git push origin mywork
  12. 12. https://github.com/matiassingers/awesome-readme ● ● ● ● ● ● ●
  13. 13. ### Steps to reproduce What did you do? ### Expected behavior Tell us what should happen ### Actual behavior Tell us what happens instead ### Overview This pull request: - [ ] Fixes a bug - [ ] Adds a feature - [ ] Breaks backwards compat - [ ] Has tests covering changes ### Description Any additional information. .github/pull_request_template.md.github/issue_template.md
  14. 14. ● ○ ● ○ ○ https://packagist.org
  15. 15. { "name": "consolidation/bootstrap", "description": "Locate and bootstrap components ...", "autoload":{ "psr-4":{ "ConsolidationBootstrap": "src" } }, "require": { "php": ">=5.5.0", "psr/log": "~1.0", "symfony/console": "~2.5|~3.0" }, "extra": { "branch-alias": { "dev-master": "1.x-dev" } } }
  16. 16. https://packagist.org/search/?type=drupal-drush
  17. 17. https://poser.pugx.org
  18. 18. ● ○ ○ ● ○ phpunit.xml.dist ○ ○ composer install --prefer dist ○ ○ ○ composer.lock ○ Provide scripts to run tests locally https://travis-ci.org
  19. 19. <phpunit bootstrap="vendor/autoload.php" colors="true"> <testsuites> <testsuite name="annotation-command"> <directory prefix="test" suffix=".php">tests</directory> </testsuite> </testsuites> </phpunit>
  20. 20. $ composer require squizlabs/php_codesniffer
  21. 21. language: php php: - 7.0 - 5.6 - 5.5 - 5.4 before_script: - composer install --prefer-dist script: - vendor/bin/phpunit - vendor/bin/phpcs --standard=PSR2 -n src
  22. 22. branches: # Only test the master branch and SemVer tags. only: - master - /^[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.*$/
  23. 23. sudo: false cache: directories: - $HOME/.composer/cache
  24. 24. matrix: include: - php: 7.0 env: deps=highest - php: 5.6 - php: 5.5 - php: 5.4 env: deps=lowest before_script: - if [ -z "$deps" ]; then composer install --prefer-dist; fi; - if [ "$deps" = "lowest" ]; then composer update --prefer-dist --prefer-lowest -n; fi; - if [ "$deps" = "highest" ]; then composer update --prefer-dist -n; fi; https://blog.wyrihaximus.net/2015/06/test-lowest-current-and-highest-possible-on-travis/
  25. 25. Define a box.json file to define phar contents, then run: $ composer require kherge/box $ vendor/bin/box build .
  26. 26. { "alias": "robo.phar", "chmod": "0755", "compactors": ["HerreraBoxCompactorPhp"], "directories": ["src"], "files": ["RoboFile.php"], "finder": [ { "name": [ "*.php", "*.exe", "GeneratedWrapper.tmpl" ], "exclude": [ "test", "tests", "Test", "Tests", "Tester" ], "in": "vendor" } ], "git-commit": "git-commit", "git-version": "git-version", "output": "robo.phar", "main": "robo", "stub": true } https://github.com/consolidation/Robo/pull/411
  27. 27. # Prior to a deploy, build a fresh robo.phar before_deploy: - vendor/bin/box build . deploy: provider: releases api_key: secure: REPLACE_WITH_OAUTH_TOKEN file: robo.phar skip_cleanup: true on: tags: true https://help.github.com/articles/creating-an-access-token-for-command-line-use/
  28. 28. { "name": "consolidation/annotated-command", "scripts": { "phar": "vendor/bin/box build .", "cs": "phpcs --standard=PSR2 -n src", "cbf": "phpcbf --standard=PSR2 -n src", "unit": "SHELL_INTERACTIVE=true phpunit --colors=always", "test": [ "@unit", "@cs" ] } }
  29. 29. Paste in badge image URLs any place HTML can be rendered (e.g. wiki pages) to create summary pages.
  30. 30. ● ○ ○ ● ○ https://coveralls.io
  31. 31. <phpunit bootstrap="vendor/autoload.php" colors="true"> … <logging> <!-- <log type="coverage-html" target="build/logs/coverage" lowUpperBound="35" highLowerBound="70"/> --> <log type="coverage-clover" target="build/logs/clover.xml"/> </logging> <filter> <whitelist processUncoveredFilesFromWhitelist="true"> <directory suffix=".php">src</directory> </whitelist> </filter> </phpunit>
  32. 32. $ brew install php70-xdebug $ composer require satooshi/php-coveralls
  33. 33. after_success: - travis_retry php vendor/bin/coveralls -v
  34. 34. ● ○ ○ ● ○ ○ ○ ○ ○ https://scrutinizer-ci.com
  35. 35. https://scrutinizer-ci.com/docs/integration/chrome-extension
  36. 36. ● ○ ○ ● ○ ○ https://www.versioneye.com
  37. 37. { "name": "consolidation/annotated-command", "description": "Initialize Symfony Console commands …", "license": "MIT", "authors": [ { "name": "Greg Anderson", "email": "greg.1.anderson@greenknowe.org" } ], … }
  38. 38. $ composer licenses Name: consolidation/robo Version: 1.x-dev Licenses: MIT Dependencies: Name Version License consolidation/annotated-command 2.4.3 MIT consolidation/log 1.0.3 MIT consolidation/output-formatters 3.1.7 MIT container-interop/container-interop 1.2.0 MIT guzzle/guzzle v3.8.1 MIT guzzlehttp/psr7 1.4.1 MIT jakubledl/dissect v1.0.1 unlicense league/container 2.3.0 MIT myclabs/deep-copy 1.6.0 MIT patchwork/jsqueeze v2.0.5 (Apache-2.0 or GPL-2.0)
  39. 39. https://poser.pugx.orghttps://…#tab-licenses [![License](https://poser.pugx.org/ORG/PROJECT/license.png)](https://www.versioneye.com/user/projects/ID#tab-licenses)
  40. 40. ● ○ ● ○ ○ https://readthedocs.org
  41. 41. http://outputformatters.readthedocs.io/en/latest
  42. 42. $ composer require victorjonsson/markdowndocs $ vendor/bin/phpdoc-md phpdoc-md generate src > docs/api.md $ git add docs/api.md $ git commit -m "Add API documentation." OH NO! It’s not automated! ● ReadTheDocs is a python service; it can’t run php. ● Can’t easily build from Travis and commit back to the repository, as that would create a separate commit (not part of the release, might cause another test run, etc.)
  43. 43. ● ○ ○ ● https://pages.github.com
  44. 44. ● ○ ● ○ ● ○
  45. 45. Install Sami $ curl --output $HOME/bin/sami.phar http://get.sensiolabs.org/sami.phar In .travis.yml after_success: # Publish updated API documentation on every push to the master branch - git config --global user.email $GITHUB_USER_EMAIL - git config --global user.name "Travis LCache Documentation Bot" - sami.phar --ansi update sami-config.php - git clone --branch=gh-pages https://${TOKEN}@github.com/org/proj work - rm -rf work/api - cp -R docs/api work/api - cd work - git add -A api - git commit -m "API docs from $TRAVIS_BUILD_NUMBER/$TRAVIS_COMMIT" - git push
  46. 46. https://lcache.github.io/lcache/api/master

×