Include appstreamcli in ancillary files check
[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 ##
33
34 cd "$1" || exit 1
35
36 if [ ! -d ".git" ] || [ ! -d "src" ] || [ ! -f "geeqie.1" ]
37 then
38         printf '%s\n' "This is not a Geeqie project folder"
39         exit 1
40 fi
41
42 exit_status=0
43
44 # Script files must have the file extension .sh  or
45 # be symlinked as so - for doxygen
46 while read -r file
47 do
48         #~ check_sh
49         result=$(file "$file" | grep "POSIX shell script")
50
51         if [ -n "$result" ]
52         then
53                 base_with_sh=$(basename "$file")
54                 base_without_sh=$(basename "$file" .sh)
55
56                 if [ "$base_with_sh" = "$base_without_sh" ]
57                 then
58                         if [ ! -f "$file.sh" ]
59                         then
60                                 printf "ERROR; Executable script does not have a .sh extension: %s\n" "$file"
61                                 exit_status=1
62                         fi
63                 fi
64         fi
65 done << EOF
66 $(find "$1/plugins" "$1/src" "$1/scripts" -type f -executable)
67 EOF
68
69 # Check if all options are in the disabled checks
70 while read -r line
71 do
72         if [ -n "$line" ]
73         then
74                 res=$(grep "$line" "$1/scripts/test-all.sh")
75                 if [ -z "$res" ]
76                 then
77                         printf "ERROR; Option no disabled check in ./scripts/test-all.sh: %s\n" "$line"
78                         exit_status=1
79                 fi
80         fi
81 done << EOF
82 $(awk 'BEGIN {FS="\047"} /option/ { if (substr($2,0,2) != "gq") { print $2 } }' meson_options.txt)
83 EOF
84
85 # Check if all options are in the disabled checks
86 while read -r line
87 do
88         if [ -n "$line" ]
89         then
90                 res=$(grep "\-D$line=disabled" "$1/.github/workflows/check-build-actions.yml")
91                 if [ -z "$res" ]
92                 then
93                         printf "ERROR; Option no disabled check in .github/workflows/check-build-actions.yml: %s\n" "$line"
94                         exit_status=1
95                 fi
96         fi
97 done << EOF
98 $(awk 'BEGIN {FS="\047"} /option/ { if (substr($2,0,2) != "gq") { print $2 } }' meson_options.txt)
99 EOF
100
101 # Markdown lint
102 # Runs as a GitHub Action
103 if [ -z "$GITHUB_WORKSPACE" ]
104 then
105         if [ -z "$(command -v mdl)" ]
106         then
107                 printf "ERROR: mdl is not installed"
108                 exit_status=1
109         else
110                 while read -r line
111                 do
112                         if [ -n "$line" ]
113                         then
114                                 if [ "${line#*": MD"}" != "$line" ]
115                                 then
116                                         printf "ERROR; Markdown lint error in: %s\n" "$line"
117                                         exit_status=1
118                                 fi
119                         fi
120                 done << EOF
121 $(find . -not -path "*/.*" -name "*.md" -exec mdl --no-verbose --config .mdlrc {} \;)
122 EOF
123         fi
124 fi
125
126 # Shellcheck lint
127 # Runs as a GitHub Action
128 if [ -z "$GITHUB_WORKSPACE" ]
129 then
130         if [ -z "$(command -v shellcheck)" ]
131         then
132                 printf "ERROR: shellcheck is not installed"
133                 exit_status=1
134         else
135                 while read -r line
136                 do
137                         if [ -n "$line" ]
138                         then
139                                 shellcheck_error=$(shellcheck "$line" 2>&1)
140                                 if [ -n "$shellcheck_error" ]
141                                 then
142                                         printf "ERROR; shellcheck error in: %s\n" "$shellcheck_error"
143                                         exit_status=1
144                                 fi
145                         fi
146                 done << EOF
147 $(find . -name "*.sh")
148 EOF
149         fi
150 fi
151
152 # gtk-builder ui lint - should not check the menu.ui files
153 if [ -z "$(command -v gtk-builder-tool)" ]
154 then
155         printf "ERROR: gtk-builder-tool is not installed"
156         exit_status=1
157 else
158         while read -r line
159         do
160                 if [ -n "$line" ]
161                 then
162                         if [ "${line#*"menu"}" = "$line" ]
163                         then
164                                 if [ -z "$GITHUB_WORKSPACE" ]
165                                 then
166                                         builder_error=$(gtk-builder-tool validate "$line" 2>&1)
167                                         if [ -n "$builder_error" ]
168                                         then
169                                                 printf "ERROR; gtk-builder-tool error in: %s\n" "$builder_error"
170                                                 exit_status=1
171                                         fi
172                                 else
173                                         builder_error=$(xvfb-run --auto-servernum gtk-builder-tool validate "$line" 2>&1)
174                                         if [ -n "$builder_error" ]
175                                         then
176                                                 printf "ERROR; gtk-builder-tool error in: %s\n" "$builder_error"
177                                                 exit_status=1
178                                         fi
179                                 fi
180                         fi
181                 fi
182         done << EOF
183 $(find $! -name "*.ui")
184 EOF
185 fi
186
187 # Desktop files lint
188 if [ -z "$(command -v desktop-file-validate)" ]
189 then
190         printf "ERROR: desktop-file-validate is not installed"
191         exit_status=1
192 else
193         while read -r line
194         do
195                 if [ -n "$line" ]
196                 then
197                         desktop_file=$(basename "$line" ".in")
198                         ln --symbolic "$line" "$1/$desktop_file"
199                         result=$(desktop-file-validate "$1/$desktop_file")
200
201                         rm "$1/$desktop_file"
202                         if [ -n "$result" ]
203                         then
204                                 printf "ERROR; desktop-file-validate error in: %s %s\n" "$line" "$result"
205                                 exit_status=1
206                         fi
207                 fi
208         done << EOF
209 $(find . -name "*.desktop.in")
210 EOF
211 fi
212
213 # Appdata lint
214 if [ -z "$(command -v appstreamcli)" ]
215 then
216         printf "ERROR: appstreamcli is not installed"
217         exit_status=1
218 else
219         if ! result=$(appstreamcli validate org.geeqie.Geeqie.appdata.xml.in --pedantic --explain)
220         then
221                 exit_status=1
222                 status="Error"
223         else
224                 line_count=$(echo "$result" | wc --lines)
225
226                 if [ "$line_count" -gt 1 ]
227                 then
228                         status="Warning"
229                 else
230                         status="Passed"
231                 fi
232         fi
233
234         printf "%s: appstreamcli in org.geeqie.Geeqie.appdata.xml.in: \n%s\n" "$status" "$result"
235 fi
236
237 exit "$exit_status"