fuelPHP、jenkins、php_codesniffer連携
fuelPHP、jenkins、php_codesniffer連携
fuelPHPのコード規約のチェックを自動化しつつ、結果をグラフで 見えるようにする。
http://oscasierra.net/2013/05/jenkins-to-redhat/
ここを参考にansibleのplaybookは以下のような感じ
antとPHP_CodeSnifferも入れてる
tasks:
- name: install java
yum: name=java-1.7.0-openjdk.x86_64 state=installed
- name: install ant
yum: name=ant state=installed
- name: jenkins repo install
shell: wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
- name: jenkins repo install
shell: rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
- name: install jenkins
yum: name=jenkins state=installed
- name: jenkins enabled
service: name=jenkins state=running enabled=yes
- name: install PHP_CodeSniffer
shell: pear install PHP_CodeSniffer
fuelPHPのコーディング規約をインストール
git clone https://github.com/eviweb/fuelphp-phpcs.git
mv fuelphp-phpcs/Standards/FuelPHP/ /usr/share/pear/PHP/CodeSniffer/Standards/
コマンドラインで実行は以下の通り
実行場所はプロジェクト直下
phpcs --standard=FuelPHP --extensions=php --ignore=hoge1.php,hoge2.php fuel/app/classes
--ignoreに除外ファイルを指定できる。
対象ディレクトリはapp/classesのみとした。
詳細をみたい場合は、-v
この場合はfuel/app/classes以下のパスも指定するのが吉
jenkinsで新規ジョブ作成
フリースタイルを選択
ソースコード管理に使用しているsubversionのアドレスを入力
ビルドantを追加、ビルドファイルはbuild.xmlとした。
プロジェクト直下にbuild.xmlを作成
<?xml version="1.0" encoding="UTF-8"?>
<project name="hogehoge project" default="build">
<target name="build" depends="phpcs"/>
<target name="phpcs"
description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing.">
<exec executable="/usr/bin/phpcs">
<arg value="--report=checkstyle" />
<arg value="--report-checkstyle=checkstyle.xml" />
<arg value="--standard=FuelPHP" />
<arg value="--extensions=php" />
<arg value="--ignore=hoge1.php,hoge2.php" />
<arg value="${basedir}/fuel/app/classes/" />
</exec>
</target>
</project>
jenkinsの管理画面からcheckstyleプラグインをインストール
ビルド後の処理にCheckstyle警告の集計を追加
checkstyle.xmlを指定
これでジョブにphp_codesnifferの結果がグラフ化されるはず。
phpunitも入れてるが、その設定は後程。