<?xml version="1.0" encoding="UTF-8" ?>
<project name="DB draw" default="help" phingVersion="3">
<property name="dc.project-name" value="db-draw"/>
<property name="db.host" value="mysql"/>
<target name="setup" depends="composer:install,dc:up,dc:ip"/>
<target name="qa" depends="composer:validate,composer:normalize,cs:fix,phpstan:analyze,phpunit:run"/>
<target name="dc:up" description="Launch containers">
<exec executable="docker-compose" passthru="true" checkreturn="true">
<arg line="--project-name ${dc.project-name}"/>
<arg value="up"/>
<arg value="--detach"/>
<arg value="--remove-orphans"/>
</exec>
</target>
<target name="dc:stop" description="Stop docker containers">
<exec executable="docker-compose" passthru="true">
<arg line="--project-name ${dc.project-name}"/>
<arg value="stop"/>
</exec>
</target>
<target name="dc:down" description="Take down containers, networks, images, and volumes">
<exec executable="docker-compose" passthru="true">
<arg line="--project-name ${dc.project-name}"/>
<arg value="down"/>
<arg value="--volumes"/>
<arg value="--remove-orphans"/>
<arg value="--rmi=local"/>
</exec>
</target>
<target name="dc:ip" description="Reveal containers ip addresses">
<property name="dc.format"
value="--format='{{ .Name }}{{"\t"}}{{range .NetworkSettings.Networks}}{{.IPAddress}}{{"\t"}}{{end}}'"/>
<exec executable="docker" checkreturn="true" passthru="true">
<arg value="inspect"/>
<arg line="${dc.format}"/>
<arg value="${dc.project-name}_php_1"/>
<arg value="${dc.project-name}_mysql_1"/>
</exec>
</target>
<target name="dc:shell" description="Tunnel to container">
<exec executable="docker" passthru="true">
<arg value="exec"/>
<arg value="-it"/>
<arg value="${dc.project-name}_php_1"/>
<arg value="/bin/bash"/>
</exec>
</target>
<target name="qa:remote" description="Run tests on docker container">
<exec executable="docker" passthru="true" checkreturn="true">
<arg value="exec"/>
<arg value="${dc.project-name}_php_1"/>
<arg line="phing -longtargets qa"/>
</exec>
</target>
<target name="phpstan:analyze" description="Analyze code at max level">
<exec executable="vendor/bin/phpstan" passthru="true" checkreturn="true">
<arg value="--ansi"/>
<arg value="--no-interaction"/>
<arg value="--level=max"/>
<arg value="analyze"/>
<arg value="--no-progress"/>
<arg path="src"/>
</exec>
<exec executable="vendor/bin/phpstan" passthru="true" checkreturn="true">
<arg value="clear-result-cache"/>
</exec>
</target>
<target name="composer:validate" description="Validate composer.json">
<composer command="validate">
<arg value="--ansi"/>
</composer>
</target>
<target name="composer:normalize" description="Normalize composer.json">
<composer command="normalize">
<arg value="--ansi"/>
</composer>
</target>
<target name="composer:install" description="Install Composer dependencies">
<composer command="install">
<arg value="--no-interaction"/>
<arg value="--prefer-dist"/>
<arg value="--no-progress"/>
<arg value="--ansi"/>
</composer>
</target>
<target name="plantuml:convert" description="Convert puml to png">
<exec executable="plantuml" checkreturn="true" passthru="true">
<arg value="-tpng"/>
<arg value="-nometadata"/>
<arg file="resources/output/*.puml"/>
</exec>
</target>
<target name="phpunit:run" description="Run PHPUnit tests" depends="db:wait-for-database">
<exec executable="vendor/bin/phpunit" passthru="true" checkreturn="true">
<env key="DB_HOST" value="${db.host}"/>
<arg line="--colors=always"/>
</exec>
</target>
<target name="db:wait-for-database" description="Wait until DB is up and running">
<waitfor timeoutproperty="db.timeout" maxwait="30" maxwaitunit="second">
<pdosqlexec url="mysql:host=${db.host};dbname=db-draw;port=3306"
userid="groot" password="groot"/>
</waitfor>
<fail if="db.timeout">Cannot reach database.</fail>
</target>
<target name="help">
<uptodate property="uptodate.build" srcfile="build.xml" targetfile="docs/images/build.png"/>
<if>
<not>
<isset property="uptodate.build"/>
</not>
<then>
<visualizer format="png" destination="docs/images"/>
</then>
</if>
<exec executable="xdg-open" spawn="true">
<arg file="docs/images/build.png"/>
</exec>
</target>
<target name="cs:fix" description="Fix code style">
<exec executable="vendor/bin/php-cs-fixer" passthru="true" checkreturn="true">
<arg value="fix"/>
</exec>
</target>
</project>
|