Include xmllint checks
[geeqie.git] / scripts / test-ancillary-files.sh
1 #!/bin/sh
2 #**********************************************************************
3 # Copyright (C) 2024 - The Geeqie Team
4 #
5 # Author: Colin Clark
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #**********************************************************************
21
22 ## @file
23 ## @brief Perform validity checks on project ancillary files
24 ##
25 ## $1 Root of project sources
26 ##
27 ## Perform validity checks on project ancillary files:
28 ## appdata
29 ## desktop
30 ## scripts
31 ## ui
32 ## xml
33 ##
34
35 cd "$1" || exit 1
36
37 if [ ! -d "src" ] || [ ! -f "geeqie.1" ]
38 then
39         printf '%s\n' "This is not a Geeqie project folder"
40         exit 1
41 fi
42
43 exit_status=0
44
45 # Script files must have the file extension .sh  or
46 # be symlinked as so - for doxygen
47 while read -r file
48 do
49         #~ check_sh
50         result=$(file "$file" | grep "POSIX shell script")
51
52         if [ -n "$result" ]
53         then
54                 base_with_sh=$(basename "$file")
55                 base_without_sh=$(basename "$file" .sh)
56
57                 if [ "$base_with_sh" = "$base_without_sh" ]
58                 then
59                         if [ ! -f "$file.sh" ]
60                         then
61                                 printf "ERROR; Executable script does not have a .sh extension: %s\n" "$file"
62                                 exit_status=1
63                         fi
64                 fi
65         fi
66 done << EOF
67 $(find "$1/plugins" "$1/src" "$1/scripts" -type f -executable)
68 EOF
69
70 # Check if all options are in the disabled checks
71 while read -r line
72 do
73         if [ -n "$line" ]
74         then
75                 res=$(grep "$line" "$1/scripts/test-all.sh")
76                 if [ -z "$res" ]
77                 then
78                         printf "ERROR; Option no disabled check in ./scripts/test-all.sh: %s\n" "$line"
79                         exit_status=1
80                 fi
81         fi
82 done << EOF
83 $(awk 'BEGIN {FS="\047"} /option/ { if (substr($2,0,2) != "gq") { print $2 } }' meson_options.txt)
84 EOF
85
86 # Check if all options are in the disabled checks in a GitHub run
87 # Directory .github is not in the source tar
88 if [ -d ".github" ]
89 then
90         while read -r line
91         do
92                 if [ -n "$line" ]
93                 then
94                         res=$(grep "\-D$line=disabled" "$1/.github/workflows/check-build-actions.yml")
95                         if [ -z "$res" ]
96                         then
97                                 printf "ERROR; Option no disabled check in .github/workflows/check-build-actions.yml: %s\n" "$line"
98                                 exit_status=1
99                         fi
100                 fi
101         done << EOF
102 $(awk 'BEGIN {FS="\047"} /option/ { if (substr($2,0,2) != "gq") { print $2 } }' meson_options.txt)
103 EOF
104 fi
105
106 # Markdown lint
107 # Runs as a GitHub Action
108 if [ -z "$GITHUB_WORKSPACE" ]
109 then
110         if [ -z "$(command -v mdl)" ]
111         then
112                 printf "ERROR: mdl is not installed"
113                 exit_status=1
114         else
115                 while read -r line
116                 do
117                         if [ -n "$line" ]
118                         then
119                                 if [ "${line#*": MD"}" != "$line" ]
120                                 then
121                                         printf "ERROR; Markdown lint error in: %s\n" "$line"
122                                         exit_status=1
123                                 fi
124                         fi
125                 done << EOF
126 $(find . -not -path "*/.*" -name "*.md" -exec mdl --no-verbose --config .mdlrc {} \;)
127 EOF
128         fi
129 fi
130
131 # Shellcheck lint
132 # Runs as a GitHub Action
133 if [ -z "$GITHUB_WORKSPACE" ]
134 then
135         if [ -z "$(command -v shellcheck)" ]
136         then
137                 printf "ERROR: shellcheck is not installed"
138                 exit_status=1
139         else
140                 while read -r line
141                 do
142                         if [ -n "$line" ]
143                         then
144                                 shellcheck_error=$(shellcheck "$line" 2>&1)
145                                 if [ -n "$shellcheck_error" ]
146                                 then
147                                         printf "ERROR; shellcheck error in: %s\n" "$shellcheck_error"
148                                         exit_status=1
149                                 fi
150                         fi
151                 done << EOF
152 $(find . -name "*.sh")
153 EOF
154         fi
155 fi
156
157 # gtk-builder ui lint - should not check the menu.ui files
158 if [ -z "$(command -v gtk-builder-tool)" ]
159 then
160         printf "ERROR: gtk-builder-tool is not installed"
161         exit_status=1
162 else
163         while read -r line
164         do
165                 if [ -n "$line" ]
166                 then
167                         if [ "${line#*"menu"}" = "$line" ]
168                         then
169                                 if [ -z "$GITHUB_WORKSPACE" ]
170                                 then
171                                         builder_error=$(gtk-builder-tool validate "$line" 2>&1)
172                                         if [ -n "$builder_error" ]
173                                         then
174                                                 printf "ERROR; gtk-builder-tool error in: %s\n" "$builder_error"
175                                                 exit_status=1
176                                         fi
177                                 else
178                                         builder_error=$(xvfb-run --auto-servernum gtk-builder-tool validate "$line" 2>&1)
179                                         if [ -n "$builder_error" ]
180                                         then
181                                                 printf "ERROR; gtk-builder-tool error in: %s\n" "$builder_error"
182                                                 exit_status=1
183                                         fi
184                                 fi
185                         fi
186                 fi
187         done << EOF
188 $(find $! -name "*.ui")
189 EOF
190 fi
191
192 # Desktop files lint
193 if [ -z "$(command -v desktop-file-validate)" ]
194 then
195         printf "ERROR: desktop-file-validate is not installed"
196         exit_status=1
197 else
198         while read -r line
199         do
200                 if [ -n "$line" ]
201                 then
202                         desktop_file=$(basename "$line" ".in")
203                         ln --symbolic "$line" "$1/$desktop_file"
204                         result=$(desktop-file-validate "$1/$desktop_file")
205
206                         rm "$1/$desktop_file"
207                         if [ -n "$result" ]
208                         then
209                                 printf "ERROR; desktop-file-validate error in: %s %s\n" "$line" "$result"
210                                 exit_status=1
211                         fi
212                 fi
213         done << EOF
214 $(find . -name "*.desktop.in")
215 EOF
216 fi
217
218 # Appdata lint
219 if [ -z "$(command -v appstreamcli)" ]
220 then
221         printf "ERROR: appstreamcli is not installed"
222         exit_status=1
223 else
224         if ! result=$(appstreamcli validate org.geeqie.Geeqie.appdata.xml.in --pedantic --explain)
225         then
226                 exit_status=1
227                 status="Error"
228         else
229                 line_count=$(echo "$result" | wc --lines)
230
231                 if [ "$line_count" -gt 1 ]
232                 then
233                         status="Warning"
234                 else
235                         status="Passed"
236                 fi
237         fi
238
239         printf "%s: appstreamcli in org.geeqie.Geeqie.appdata.xml.in: \n%s\n" "$status" "$result"
240 fi
241
242 # xml files lint
243 if [ -z "$(command -v xmllint)" ]
244 then
245         printf "ERROR: xmllint is not installed"
246         exit_status=1
247 else
248         while read -r line
249         do
250                 if [ -n "$line" ]
251                 then
252                         if ! xmllint --quiet --nowarning "$line" > /dev/null
253                         then
254                                 printf "ERROR: xmllint error in: %s\n" "$line"
255                                 exit_status=1
256                         fi
257                 fi
258         done << EOF
259 $(find ./doc/docbook -name "*.xml")
260 EOF
261 fi
262
263 exit "$exit_status"