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