Send stacktrace data also to a /tmp file
[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 "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 in a GitHub run
86 # Directory .github is not in the source tar
87 if [ -d ".github" ]
88 then
89         while read -r line
90         do
91                 if [ -n "$line" ]
92                 then
93                         res=$(grep "\-D$line=disabled" "$1/.github/workflows/check-build-actions.yml")
94                         if [ -z "$res" ]
95                         then
96                                 printf "ERROR; Option no disabled check in .github/workflows/check-build-actions.yml: %s\n" "$line"
97                                 exit_status=1
98                         fi
99                 fi
100         done << EOF
101 $(awk 'BEGIN {FS="\047"} /option/ { if (substr($2,0,2) != "gq") { print $2 } }' meson_options.txt)
102 EOF
103 fi
104
105 # Markdown lint
106 # Runs as a GitHub Action
107 if [ -z "$GITHUB_WORKSPACE" ]
108 then
109         if [ -z "$(command -v mdl)" ]
110         then
111                 printf "ERROR: mdl is not installed"
112                 exit_status=1
113         else
114                 while read -r line
115                 do
116                         if [ -n "$line" ]
117                         then
118                                 if [ "${line#*": MD"}" != "$line" ]
119                                 then
120                                         printf "ERROR; Markdown lint error in: %s\n" "$line"
121                                         exit_status=1
122                                 fi
123                         fi
124                 done << EOF
125 $(find . -not -path "*/.*" -name "*.md" -exec mdl --no-verbose --config .mdlrc {} \;)
126 EOF
127         fi
128 fi
129
130 # Shellcheck lint
131 # Runs as a GitHub Action
132 if [ -z "$GITHUB_WORKSPACE" ]
133 then
134         if [ -z "$(command -v shellcheck)" ]
135         then
136                 printf "ERROR: shellcheck is not installed"
137                 exit_status=1
138         else
139                 while read -r line
140                 do
141                         if [ -n "$line" ]
142                         then
143                                 shellcheck_error=$(shellcheck "$line" 2>&1)
144                                 if [ -n "$shellcheck_error" ]
145                                 then
146                                         printf "ERROR; shellcheck error in: %s\n" "$shellcheck_error"
147                                         exit_status=1
148                                 fi
149                         fi
150                 done << EOF
151 $(find . -name "*.sh")
152 EOF
153         fi
154 fi
155
156 # gtk-builder ui lint - should not check the menu.ui files
157 if [ -z "$(command -v gtk-builder-tool)" ]
158 then
159         printf "ERROR: gtk-builder-tool is not installed"
160         exit_status=1
161 else
162         while read -r line
163         do
164                 if [ -n "$line" ]
165                 then
166                         if [ "${line#*"menu"}" = "$line" ]
167                         then
168                                 if [ -z "$GITHUB_WORKSPACE" ]
169                                 then
170                                         builder_error=$(gtk-builder-tool validate "$line" 2>&1)
171                                         if [ -n "$builder_error" ]
172                                         then
173                                                 printf "ERROR; gtk-builder-tool error in: %s\n" "$builder_error"
174                                                 exit_status=1
175                                         fi
176                                 else
177                                         builder_error=$(xvfb-run --auto-servernum gtk-builder-tool validate "$line" 2>&1)
178                                         if [ -n "$builder_error" ]
179                                         then
180                                                 printf "ERROR; gtk-builder-tool error in: %s\n" "$builder_error"
181                                                 exit_status=1
182                                         fi
183                                 fi
184                         fi
185                 fi
186         done << EOF
187 $(find $! -name "*.ui")
188 EOF
189 fi
190
191 # Desktop files lint
192 if [ -z "$(command -v desktop-file-validate)" ]
193 then
194         printf "ERROR: desktop-file-validate is not installed"
195         exit_status=1
196 else
197         while read -r line
198         do
199                 if [ -n "$line" ]
200                 then
201                         desktop_file=$(basename "$line" ".in")
202                         ln --symbolic "$line" "$1/$desktop_file"
203                         result=$(desktop-file-validate "$1/$desktop_file")
204
205                         rm "$1/$desktop_file"
206                         if [ -n "$result" ]
207                         then
208                                 printf "ERROR; desktop-file-validate error in: %s %s\n" "$line" "$result"
209                                 exit_status=1
210                         fi
211                 fi
212         done << EOF
213 $(find . -name "*.desktop.in")
214 EOF
215 fi
216
217 # Appdata lint
218 if [ -z "$(command -v appstreamcli)" ]
219 then
220         printf "ERROR: appstreamcli is not installed"
221         exit_status=1
222 else
223         if ! result=$(appstreamcli validate org.geeqie.Geeqie.appdata.xml.in --pedantic --explain)
224         then
225                 exit_status=1
226                 status="Error"
227         else
228                 line_count=$(echo "$result" | wc --lines)
229
230                 if [ "$line_count" -gt 1 ]
231                 then
232                         status="Warning"
233                 else
234                         status="Passed"
235                 fi
236         fi
237
238         printf "%s: appstreamcli in org.geeqie.Geeqie.appdata.xml.in: \n%s\n" "$status" "$result"
239 fi
240
241 exit "$exit_status"