development workflow tools for open-source php libraries

86
Development Workflow Tools for Open-Source PHP Libraries Greg Anderson @greg_1_anderson

Upload: pantheon

Post on 07-Apr-2017

110 views

Category:

Technology


0 download

TRANSCRIPT

Development Workflow Tools for Open-Source PHP Libraries Greg Anderson @greg_1_anderson

Drupal Site

Drupal Module

Re-usable PHP Library

http://robo.li/framework/

{

"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

REPEAT

HOWEVER, we also need:

● Collaboration● Reproducibility● Analysis of

○ Test coverage○ Code Quality○ Open Source License Compliance

● Documentation

https://xkcd.com/1205/

Collaborate with other engineers across multiple branches.Keep a record of all work done. Integrate With All Of The Things.

Run tests andother tasks.

Calculate test coverage.

Analyze code complexity.

Track dependency versions and licenses.

Package manager for composer.

Publish documentation site from markdown.

http://dilbert.com/strip/1996-01-31

○○

○○○

https://github.com

$ git clone … working-copy

$ cd working-copy

$ git checkout -b mywork

$ git add -A .

$ git commit -m "Awesomesauce."

$ git push origin mywork

https://github.com/matiassingers/awesome-readme

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

○○

https://packagist.org

{ "name": "consolidation/bootstrap", "description": "Locate and bootstrap components ...", "autoload":{ "psr-4":{ "Consolidation\\Bootstrap\\": "src" } }, "require": { "php": ">=5.5.0", "psr/log": "~1.0", "symfony/console": "~2.5|~3.0" }, "extra": { "branch-alias": { "dev-master": "1.x-dev" } }}

https://packagist.org/search/?type=drupal-drush

https://poser.pugx.org

○○

○ phpunit.xml.dist○○ composer install --prefer dist

○○○ composer.lock○ Provide scripts to run tests locally

https://travis-ci.org

<phpunit bootstrap="vendor/autoload.php" colors="true"> <testsuites> <testsuite name="annotation-command"> <directory prefix="test" suffix=".php">tests</directory> </testsuite> </testsuites></phpunit>

$ composer require squizlabs/php_codesniffer

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

branches: # Only test the master branch and SemVer tags. only: - master - /^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+.*$/

sudo: false

cache: directories: - $HOME/.composer/cache

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/

Define a box.json file to define phar contents, then run:

$ composer require kherge/box$ vendor/bin/box build .

{ "alias": "robo.phar", "chmod": "0755", "compactors": ["Herrera\\Box\\Compactor\\Php"], "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

# 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/

{ "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" ] }}

Paste in badge image URLs any place HTML can be rendered (e.g. wiki pages) to create summary pages.

○○

https://coveralls.io

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

$ brew install php70-xdebug$ composer require satooshi/php-coveralls

after_success: - travis_retry php vendor/bin/coveralls -v

○○○○○

https://scrutinizer-ci.com

https://scrutinizer-ci.com/docs/integration/chrome-extension

○○

○○

https://www.versioneye.com

{ "name": "consolidation/annotated-command", "description": "Initialize Symfony Console commands …", "license": "MIT", "authors": [ { "name": "Greg Anderson", "email": "[email protected]" } ],

… }

$ composer licensesName: consolidation/roboVersion: 1.x-devLicenses: MITDependencies:

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)

https://poser.pugx.orghttps://…#tab-licenses

[![License](https://poser.pugx.org/ORG/PROJECT/license.png)](https://www.versioneye.com/user/projects/ID#tab-licenses)

○○

https://readthedocs.org

http://outputformatters.readthedocs.io/en/latest

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

○○

https://pages.github.com

Install Sami$ curl --output $HOME/bin/sami.phar http://get.sensiolabs.org/sami.phar

In .travis.ymlafter_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

https://lcache.github.io/lcache/api/master