forked from SURFnet/grouphub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-pre-commit.xml
145 lines (128 loc) · 6.13 KB
/
build-pre-commit.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?xml version="1.0" encoding="UTF-8"?>
<project name="Grouphub API-pre-commit" default="build">
<target name="build"
depends="prepare-environment,php-lint,phpmd,phpcs,phpunit"/>
<target name="prepare-environment" depends="set-test-tree-location,get-changeset">
<echo message="OK"/>
</target>
<target name="get-changeset"
depends="get-changeset.php,get-changeset.php-spacesep,get-changeset.php-commasep"/>
<target name="get-changeset.php" depends="set-test-tree-location" unless="changeset.php.executed">
<property name="changeset.php.executed" value="true"/>
<!-- Get changeset separated by newline -->
<exec executable="${basedir}/bin/qa-tools" outputProperty="changeset.php.newlinesep">
<arg line="changeset:pre-commit --filter-path=src --filter-ext=php"/>
</exec>
<!-- Check if changeset contains values -->
<condition property="changeset.php.notempty">
<not>
<equals arg1="${changeset.php.newlinesep}" arg2="" trim="true"/>
</not>
</condition>
</target>
<!-- Assign changeset absolute filenames to property and quote filenames -->
<target name="get-changeset.php-absolute.newlinesep" depends="get-changeset.php" if="changeset.php.notempty">
<loadresource property="changeset.php.absolute.newlinesep">
<propertyresource name="changeset.php.newlinesep"/>
<filterchain>
<tokenfilter>
<linetokenizer/>
<replaceregex pattern="^" replace='"${test-tree-location}/'/>
<replaceregex pattern="$" replace='"'/>
</tokenfilter>
</filterchain>
</loadresource>
</target>
<!-- Assign changeset relative and quote filenames -->
<target name="get-changeset.php-relative.newlinesep" depends="get-changeset.php" if="changeset.php.notempty">
<loadresource property="changeset.php.relative.newlinesep">
<propertyresource name="changeset.php.newlinesep"/>
<filterchain>
<tokenfilter>
<linetokenizer/>
<replaceregex pattern="^" replace='"'/>
<replaceregex pattern="$" replace='"'/>
</tokenfilter>
</filterchain>
</loadresource>
</target>
<!-- Convert newline separated to space separated -->
<target name="get-changeset.php-spacesep" depends="get-changeset.php-relative.newlinesep,get-changeset.php-absolute.newlinesep"
if="changeset.php.notempty">
<loadresource property="changeset.php.relative.spacesep">
<propertyresource name="changeset.php.relative.newlinesep"/>
<filterchain>
<tokenfilter delimoutput=" "/>
</filterchain>
</loadresource>
<loadresource property="changeset.php.absolute.spacesep">
<propertyresource name="changeset.php.absolute.newlinesep"/>
<filterchain>
<tokenfilter delimoutput=" "/>
</filterchain>
</loadresource>
</target>
<!-- Convert newline separated to comma separated -->
<target name="get-changeset.php-commasep" depends="get-changeset.php-relative.newlinesep,get-changeset.php-absolute.newlinesep"
if="changeset.php.notempty">
<loadresource property="changeset.php.relative.commasep">
<propertyresource name="changeset.php.relative.newlinesep"/>
<filterchain>
<tokenfilter delimoutput=","/>
</filterchain>
</loadresource>
<loadresource property="changeset.php.absolute.commasep">
<propertyresource name="changeset.php.absolute.newlinesep"/>
<filterchain>
<tokenfilter delimoutput=","/>
</filterchain>
</loadresource>
</target>
<target name="set-test-tree-location">
<condition value="${working-dir}" else="${basedir}" property="test-tree-location">
<isset property="working-dir"/>
</condition>
</target>
<target name="php-lint" depends="get-changeset.php-absolute.newlinesep" if="changeset.php.notempty">
<exec executable="sh" failonerror="true">
<arg value="-c"/>
<arg value="echo '${changeset.php.absolute.newlinesep}' | xargs -n 1 -P 4 php -l 1>/dev/null"/>
</exec>
<echo message="OK"/>
</target>
<target name="phpmd" depends="get-changeset.php-commasep" if="changeset.php.notempty">
<exec executable="${test-tree-location}/bin/phpmd" failonerror="true">
<arg line="${changeset.php.absolute.commasep} text ${test-tree-location}/phpmd-pre-commit.xml"/>
</exec>
<echo message="OK"/>
</target>
<target name="phpcs" depends="get-changeset.php-spacesep" if="changeset.php.notempty">
<exec executable="${test-tree-location}/bin/phpcs" failonerror="true">
<arg value="--standard=${test-tree-location}/phpcs.xml"/>
<arg value="--warning-severity=0"/> <!-- Don't show warnings-->
<arg value="--extensions=php"/>
<arg value="--report=full"/>
<arg line="${changeset.php.absolute.spacesep}"/>
</exec>
<echo message="OK"/>
</target>
<!--
PHPUnit always runs, regardless of there being changes in PHP src.
This is because other changes, e.g. config, can also break tests
-->
<target name="phpunit" depends="set-test-tree-location">
<exec outputproperty="phpunit-output-raw" resultproperty="phpunit-exitcode"
executable="${test-tree-location}/bin/phpunit" failonerror="false">
<arg line="--configuration=${test-tree-location}/app/phpunit.xml.dist --stop-on-failure"/>
</exec>
<condition property="phpunit-output" value="${phpunit-output-raw}" else="OK">
<isfailure code="${phpunit-exitcode}"/>
</condition>
<echo message="${phpunit-output}"/>
<fail message="PHPUnit failed">
<condition>
<isfailure code="${phpunit-exitcode}"/>
</condition>
</fail>
</target>
</project>