forked from COMCIFS/dictionary_check_action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·171 lines (147 loc) · 5.19 KB
/
entrypoint.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash -l
set -ue
apt-get update
# Install 'subversion' since it is needed to retrieve the cod-tools package
apt-get -y install subversion
# Install 'moreutils' since it contain the 'sponge' program
apt-get -y install moreutils
# Install 'git' since it is needed to retrieve the imported dictionaries
apt-get -y install git
# Make a sparse check out a fixed 'cod-tools' revision
COD_TOOLS_DIR=cod-tools
COD_TOOLS_REV=10042
mkdir ${COD_TOOLS_DIR}
cd ${COD_TOOLS_DIR}
svn co -r ${COD_TOOLS_REV} \
--depth immediates \
svn://www.crystallography.net/cod-tools/trunk .
svn up -r ${COD_TOOLS_REV} \
--set-depth infinity \
dependencies makefiles scripts src
# Install 'cod-tools' dependencies
apt-get -y install sudo
./dependencies/Ubuntu-22.04/build.sh
./dependencies/Ubuntu-22.04/run.sh
# Patch the Makefile and run custom build commands
# to avoid time-intensive tests
perl -pi -e 's/^(include \${DIFF_DEPEND})$/#$1/' \
makefiles/Makefile-perl-multiscript-tests
make "$(pwd)"/src/lib/perl5/COD/CIF/Parser/Bison.pm
make "$(pwd)"/src/lib/perl5/COD/CIF/Parser/Yapp.pm
make ./src/lib/perl5/COD/ToolsVersion.pm
PERL5LIB=$(pwd)/src/lib/perl5${PERL5LIB:+:${PERL5LIB}}
export PERL5LIB
# shellcheck disable=SC2123
PATH=$(pwd)/scripts${PATH:+:${PATH}}
export PATH
cd ..
# Prepare dictionaries and template files that may be
# required to properly validate other dictionaries
TMP_DIR=$(mktemp -d)
# Prepare the DDLm reference dictionary and the CIF_CORE dictionary.
#
# If these dictionaries are part of the checked GitHub repository,
# then the local copies should be used to ensure self-consistency,
# e.g. the latest version of the reference dictionary should validate
# against itself. This scenario will most likely only occur in the
# COMCIFS/cif_core repository.
#
# If these dictionaries are not part of the checked GitHub repository,
# then the latest available version from the COMCIFS/cif_core repository
# should be retrieved.
DDLM_REFERENCE_DIC=./ddl.dic
if [ ! -f "${DDLM_REFERENCE_DIC}" ]
then
git clone https://github.com/COMCIFS/cif_core.git "${TMP_DIR}"/cif_core
DDLM_REFERENCE_DIC="${TMP_DIR}"/cif_core/ddl.dic
# Specify the location of imported files (e.g. "templ_attr.cif")
COD_TOOLS_DDLM_IMPORT_PATH="${TMP_DIR}"/cif_core
fi
export COD_TOOLS_DDLM_IMPORT_PATH
# run the checks
shopt -s nullglob
# Check dictionaries for stylistic and semantic issues
OUT_FILE="${TMP_DIR}/cif_ddlm_dic_check.out"
ERR_FILE="${TMP_DIR}/cif_ddlm_dic_check.err"
for file in ./*.dic
do
# Run the checks and report fatal errors
cif_ddlm_dic_check "$file" > "${OUT_FILE}" 2> "${ERR_FILE}" || (
echo "Execution of the 'cif_ddlm_dic_check' script failed with" \
"the following errors:"
cat "${ERR_FILE}"
rm -rf "${TMP_DIR}"
exit 1
)
# Filter and report error messages
#~ grep "${ERR_FILE}" -v \
#~ -e "ignored message A" \
#~ -e "ignored message B" |
#~ sponge "${ERR_FILE}"
if [ -s "${ERR_FILE}" ]
then
echo "Dictionary check generated the following non-fatal errors:"
cat "${ERR_FILE}"
fi
# Filter and report output messages
#~ grep "${OUT_FILE}" -v \
#~ -e "ignored message A" \
#~ -e "ignored message B" |
#~ sponge "${OUT_FILE}"
if [ -s "${OUT_FILE}" ]
then
echo "Dictionary check detected the following irregularities:";
cat "${OUT_FILE}"
rm -rf "${TMP_DIR}"
exit 1
fi
done
# Validate dictionaries against the DDLm reference dictionary
OUT_FILE="${TMP_DIR}/ddlm_validate.out"
ERR_FILE="${TMP_DIR}/ddlm_validate.err"
for file in ./*.dic
do
ddlm_validate \
--follow-iucr-style-guide \
--dictionaries "${DDLM_REFERENCE_DIC}" \
"$file" > "${OUT_FILE}" 2> "${ERR_FILE}" || (
echo "Execution of the 'ddlm_validate' script failed with" \
"the following errors:"
cat "${ERR_FILE}"
rm -rf "${TMP_DIR}"
exit 1
)
# Filter and report error messages
#~ grep "${ERR_FILE}" -E -v \
#~ -e "ignored message A" \
#~ -e "regular expression matching ignored message B .*?" |
#~ sponge "${ERR_FILE}"
# Suppress warnings about dictionary attributes with the 'inherited'
# type until this functionality gets properly implemented.
grep "${ERR_FILE}" -v \
-e "content type 'inherited' is not recognised" |
sponge "${ERR_FILE}"
if [ -s "${ERR_FILE}" ]
then
echo "Dictionary validation generated the following non-fatal errors:"
cat "${ERR_FILE}"
fi
# Filter and report output messages
#~ grep "${OUT_FILE}" -E -v \
#~ -e "ignored message A" \
#~ -e "regular expression matching ignored message B .*?" |
#~ sponge "${OUT_FILE}"
# Suppress warnings about missing dictionary DOI for now
# (see discussion in https://github.com/COMCIFS/cif_core/pull/428).
grep "${OUT_FILE}" -v \
-e "data item '_dictionary.doi' is recommended" |
sponge "${OUT_FILE}"
if [ -s "${OUT_FILE}" ]
then
echo "Dictionary validation detected the following validation issues:";
cat "${OUT_FILE}"
rm -rf "${TMP_DIR}"
exit 1
fi
done
rm -rf "${TMP_DIR}"