forked from taginfo/taginfo-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_changes
executable file
·83 lines (75 loc) · 3.1 KB
/
test_changes
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
#!/bin/bash
## @license GPLv3 <https://www.gnu.org/licenses/gpl-3.0.html>
## @author Copyright (C) 2015 Robin Schneider <[email protected]>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
latest_upstream_master_commit_hash="$(curl --silent https://api.github.com/repos/taginfo/taginfo-projects/git/refs/heads/master | jq --raw-output '.object.sha')"
## For testing.
# latest_upstream_master_commit_hash="9dadc7f1a98e30ae0d4d2a18e37c4452d55fb792"
exit_code=0
ansi_color_red='\033[1;31m'
ansi_color_green='\033[1;32m'
ansi_color_reset='\033[0m'
## Check if sorted {{{
LC_ALL=C sort --unique project_list.txt > project_list_sorted.txt
git --no-pager diff --color-words --no-index project_list.txt project_list_sorted.txt
if [ $? == 0 ]
then
echo -e "${ansi_color_green}- project_list.txt is sorted${ansi_color_reset}"
else
echo -e "${ansi_color_red}- project_list.txt not is sorted${ansi_color_reset}" 1>&2
echo "You might want to run:" 1>&2
echo " cp project_list_sorted.txt project_list.txt" 1>&2
exit_code=$((exit_code+1))
fi
## }}}
git diff "${latest_upstream_master_commit_hash}..HEAD" --color=always -- project_list.txt \
| perl -wlne 'print $1 if /^\e\[32m\+\e\[m\e\[32m(.*)\e\[m$/' > project_list_diff.txt
while read id url
do
echo "- Testing $id: $url"
if [[ $id =~ ^[a-z][a-z0-9_]+$ ]]
then
echo -e "${ansi_color_green}-- ID is valid${ansi_color_reset}"
else
echo -e "${ansi_color_red}-- ID is not valid${ansi_color_reset}" 1>&2
exit_code=$((exit_code+1))
fi
## Ensure that the output files does not yet exist.
tempdir="$(mktemp --directory)"
curl --silent "$url" --output "$tempdir/taginfo.json"
if [ $? == 0 ]
then
echo -e "${ansi_color_green}-- taginfo.json can be retrieved${ansi_color_reset}"
jq '.' "$tempdir/taginfo.json" > /dev/null
if [ $? == 0 ]
then
echo -e "${ansi_color_green}-- taginfo.json is valid JSON${ansi_color_reset}"
else
echo "" 1>&2
echo -e "${ansi_color_red}-- taginfo.json is not valid JSON${ansi_color_reset}" 1>&2
exit_code=$((exit_code+1))
fi
else
echo -e "${ansi_color_red}-- taginfo.json file can not be retrieved.${ansi_color_reset}" 1>&2
exit_code=$((exit_code+1))
fi
done < project_list_diff.txt
if [ $exit_code == 0 ]
then
echo -e "\n${ansi_color_green}Problem count: $exit_code${ansi_color_reset}"
else
echo -e "\n${ansi_color_red}Problem count: $exit_code${ansi_color_reset}" 1>&2
fi
exit "$exit_code"