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

PHPで始めるGitHub Actions

y_ahiru
January 27, 2021

PHPで始めるGitHub Actions

第27回ゆるはち.it で発表したスライドです
https://yuruhachi-it.connpass.com/event/200703/

その他参考リンク
- koriym/Koriym.PhpSkeleton: CI ready PHP project skeleton https://github.com/koriym/Koriym.PhpSkeleton
- dorny/paths-filter: Conditionally run actions based on files modified by PR, feature branch or pushed commits https://github.com/dorny/paths-filter
- mheap/phpunit-matcher-action: Add annotations to your PHPUnit tests when running under Github Actions https://github.com/mheap/phpunit-matcher-action
- shivammathur/setup-php: GitHub action to setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer... https://github.com/shivammathur/setup-php
- actions/cache: Cache dependencies and build outputs in GitHub Actions https://github.com/actions/cache
- styfle/cancel-workflow-action: ⏹️ GitHub Action to cancel previous running workflows on push https://github.com/styfle/cancel-workflow-action
- sebastianbergmann/phpunit: The PHP Unit Testing framework. https://github.com/sebastianbergmann/phpunit/
- phpstan/phpstan: PHP Static Analysis Tool - discover bugs in your code without running it! https://github.com/phpstan/phpstan
- vimeo/psalm: A static analysis tool for finding errors in PHP applications https://github.com/vimeo/psalm
- FriendsOfPHP/PHP-CS-Fixer: A tool to automatically fix PHP Coding Standards issues https://github.com/FriendsOfPHP/PHP-CS-Fixer
- infection/infection: AST based PHP Mutation Testing Framework https://github.com/infection/infection
- nektos/act: Run your GitHub Actions locally 🚀 https://github.com/nektos/act

y_ahiru

January 27, 2021
Tweet

More Decks by y_ahiru

Other Decks in Programming

Transcript

  1. - uses: dorny/[email protected] id: changed with: list-files: shell filters: |

    php: # 正規表現が使える - '**/*.php' without_delete: # 新規作成/ 編集されたファイルのみみたいな指定もできる - added|modified: '*.php' - name: Run php-cs-fixer run: | vendor/bin/php-cs-fixer fix \ --dry-run \ ${{ steps.changed.outputs.without_delete_files }}
  2. actions/cache 任意のファイル/ディレクトリをキャッシュして、ジョブ間で使い回しができるやつ。 CIを⾼速化したいときに役に⽴つ。 - name: Get Composer Cache Directory id:

    composer-cache-dir run: | echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Restore composer cache id: composer-cache uses: actions/cache@v2 with: path: ${{ steps.composer-cache-dir.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }} restore-keys: | ${{ runner.os }}-composer-
  3. PHPUnit デファクトスタンダードなテスティングフレームワーク shivammathur/setup-php を使っている場合 - name: Setup problem matchers for

    PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit tests run: vendor/bin/phpunit shivammathur/setup-php を使っていない場合は mheap/phpunit-matcher-action@v1 を使う - name: Configure phpunit-matcher uses: mheap/phpunit-matcher-action@v1 - name: Run PHPUnit tests run: vendor/bin/phpunit
  4. PHPStan 0.12.32 以上の場合 何もしなくてもOK。明⽰的にやる場合は --error-format=github を⾜してあげる - name: Run phpstan

    run: vendor/bin/phpstan analyse --error-format=github 0.12.32 未満の場合 staabm/annotate-pull-request-from-checkstyle を使う - name: Run phpstan run: vendor/bin/phpstan analyse --error-format=checkstyle --no-progress | cs2pr
  5. psalm 3.8.4 以上の場合 --output-format=github を⾜してあげる - name: Run psalm run:

    vendor/bin/psalm --output-format=github 3.8.4 未満の場合 staabm/annotate-pull-request-from-checkstyle を使う - name: Run psalm run: vendor/bin/psalm --output-format=checkstyle --no-progress | cs2pr