Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Living with Open Source responsibility - PHP Serbia 2021

Living with Open Source responsibility - PHP Serbia 2021

Mario Blazek

August 26, 2021
Tweet

More Decks by Mario Blazek

Other Decks in Programming

Transcript

  1. About me • Mario Blažek • Senior Backend Developer @QAgency

    • Lead Backend Developer @jenz.app • Married with children • Believes in Open Source • Zagreb PHP Meetup organizer (ZgPHP) • Chief Fire Officer
  2. Day 0 • You have a piece of code that

    solves your problem • Want to reuse it • Want to make it open-source • Street cred
  3. Tests • PHPUnit - https:/ /phpunit.de/ • PHPSpec - http:/

    /www.phpspec.net/ • Kahlan - https:/ /kahlan.github.io/ • Peridot - https:/ /peridot-php.github.io/ • Pest - https:/ /pestphp.com/
  4. Code quality tools • PHP Code Style Fixer - php-cs-fixer

    • PHP Static Analysis Tool - PHPStan • Reconstruction tool - rector • Static Analysis Tool - psalm
  5. PHP CS Fixer • https:/ /github.com/FriendsOfPHP/PHP-CS-Fixer • Coding Standards Fixer

    • Tool fixes your code to follow standards • .php_cs
  6. Reconstruction tool - rector • https:/ /getrector.org/ • Provides automated

    way to upgrade and refactor code • Plugin system with “rectors” • More than 450 available • Example: Migration from PHPUnit 4 to PHPUnit 8 in seconds • rector.php
  7. And some more • Infection PHP - https:/ /infection.github.io/ •

    PHP Insights - https:/ /phpinsights.com/ • Deptrac - https:/ /github.com/qossmic/deptrac • PHP Mess Detector - https:/ /phpmd.org/
  8. Travis CI • (Was) De facto standard for GitHub based

    repositories • Losing traction since they decided to shutdown travis-ci.org • .travis.yml
  9. .travis.yml language: php cache: directories: - vendor - $HOME/.composer/cache matrix:

    fast_finish: true include: - php: 7.2 - php: 7.3 branches: only: - master before_install: - phpenv config-add travis.php.ini install: - travis_wait composer install script: - ./vendor/bin/phpunit -d memory_limit=-1 --colors -c phpunit.xml --coverage-clover=coverage.xml notification: email: false git: depth: 30 sudo: false after_script: - wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover after_success: - bash <(curl -s https://codecov.io/bash)
  10. GitHub Actions • Provided by GitHub • Free for all

    public repositories • .github/workflows/*.yml
  11. An example workflow name: Static analysis on: push: branches: -

    'master' - '[0-9].[0-9]+' pull_request: ~ jobs: static-analysis: name: ${{ matrix.script }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: script: ['phpstan', 'phpstan-tests', 'psalm'] steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: php-version: '8.0' coverage: none # Install Flex as a global dependency to enable usage of extra.symfony.require # while keeping Flex recipes from applying - run: composer global require --no-scripts symfony/flex - run: composer config extra.symfony.require ~5.2.0 - run: composer update --prefer-dist - run: composer ${{ matrix.script }}
  12. Scrutinizer CI • Paid, but free for open-source projects •

    Supports code analysis • Code coverage, CI/CD, etc • .scrutinizer.yml
  13. codecov.io • PHPUnit’s code coverage on steroids • Can’t generate

    code coverage on its own • Other tools need to upload code coverage report • codecov.yml
  14. Documentation • Improves the overall package quality • Showcases the

    best practices • Don’t force developers finding their own way into your package • • Document installation procedure, upgrade guides, configuration, use cases and extension points
  15. Documentation • Markdown files • https:/ /readthedocs.org/ • https:/ /docusaurus.io/

    • https:/ /www.mkdocs.org/ • https:/ /www.gitbook.com/
  16. Licensing • Choose a proper license • An open source

    license protects contributors and users • Businesses and savvy developers won’t touch a project without this protection • Apache, MIT, GPLv3 • https:/ /spdx.org/licenses/ • https:/ /choosealicense.com/licenses/
  17. WTFPL license • Do What the Fuck You Want to

    Public License • Very permissive
  18. Versioning and releases • Define the Public API • Try

    to comply with semantic versioning principles • https:/ /semver.org/ • Think about Git strategy
  19. Changelog • Is a MUST • Changelog != a list

    of commits • https:/ /keepachangelog.com/en/1.0.0/ # Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [1.0.0] - 2017-06-20 ### Added - New visual identity by [@tylerfortune8](https://github.com/tylerfortune8). - Version navigation. - Links to latest released version in previous versions. ### Changed - Start using "changelog" over "change log" since it's the common usage. - Fix phrasing and spelling in German translation. ### Removed - Section about "changelog" vs "CHANGELOG". ## [0.3.0] - 2015-12-03 ### Added - RU translation from [@aishek](https://github.com/aishek). ## [0.2.0] - 2015-10-06 ### Changed - Remove exclusionary mentions of "open source" since this project can benefit both "open" and "closed" source projects equally. ## [0.1.0] - 2015-10-06 ### Added - Answer "Should you ever rewrite a change log?". ### Changed - Improve argument against commit logs. - Start following [SemVer](https://semver.org) properly. ## [0.0.8] - 2015-02-17 ### Changed - Update year to match in every README example.
  20. We are ready to go “live” • Publish your package

    to https:/ /packagist.org/ • And now the real work begins • Be responsible, collaborate
  21. Summary • Do small steps • Lack of time •

    Try to devote 1-2 hours a week • Appreciate the feedback • Rewarding experience • Ignore mean people