LoginSignup
3
2

More than 5 years have passed since last update.

CircleCI2.0でphanを回す

Last updated at Posted at 2018-09-05

はじめに

人生って大変ですね。プログラマ辞めてワルキューレに入りたいです。

Laravel でphanを回すって記事はそこそこあるし、 師tadsanのデカルチャーな記事 など当たれば phan について大体わかると思いますが、 CircleCI 2.0 と組み合わせるとなると全然見当たらなかったので頑張りました。

phanphpunit をCIで回すと快適に夜眠れるので安心して眠ることができるので回すことをおすすめします。

コード抜粋

version: 2
jobs:
  build:
    docker:
      - image: circleci/php:7.1-node-browsers
      - image: circleci/mysql:5.7
    environment:
      - APP_DEBUG: true
    working_directory: ~/repo
    steps:
      - checkout
      - run: sudo apt-get install -y libzip-dev libpng-dev libsqlite3-dev
      - run: sudo docker-php-ext-install pdo_mysql zip
      - run:
          name: Install php-ast
          command: |
            cd ~
            git clone https://github.com/nikic/php-ast
            cd php-ast
            phpize
            ./configure
            make
            sudo make install
            echo -e "extension=ast.so" | sudo tee /usr/local/etc/php/php.ini > /dev/null
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "composer.json" }}
          - v1-dependencies-
      - run: cd ~/repo
      - run: composer install -n --prefer-dist
      - save_cache:
          paths:
            - ./vendor
          key: v1-dependencies-{{ checksum "composer.json" }}
      - run: composer phan
workflows:
  version: 2
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: /^develop$|^staging$/

雑に解説

phpCircleCI 側が用意してくれてるdockerを使えば楽チンに入りました楽勝!
name: Install php-ast の部分がめんどくさかったです。phan には php-ast extensionが必要なのですが、良いやり方がなかったのでとりあえず make して php.iniextension=ast.so を追加するように書きました。

docker image を作ってる方もいらっしゃいますが、なるべく circleci が提供してる docker image に合わせたかったのでこういう風にしました。

おわり

もっといいやり方、ここちげーよ、などあればコメントください。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2