Skip to content

Commit 07d67ac

Browse files
committed
ci: add metadata blocks properties file check
As creating the properties files for metadata blocks is a tedious manual process, this script ensures in CI everything is present. It adds to checking for duplicates.
1 parent 3806b9c commit 07d67ac

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/check_property_files.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
pull_request:
44
#paths:
55
# - "**/*.properties"
6+
# - "scripts/api/data/metadatablocks/*"
67
jobs:
78
duplicate_keys:
89
name: Duplicate Keys
@@ -32,3 +33,56 @@ jobs:
3233
if [ "$FAIL" -eq 1 ]; then
3334
exit 1
3435
fi
36+
37+
metadata_blocks_properties:
38+
name: Metadata Blocks Properties
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v3
42+
- name: Run metadata block properties verification script
43+
shell: bash
44+
run: |
45+
for MDB in $(find scripts/api/data/metadatablocks -name '*.tsv'); do
46+
BLOCK_NAME=$(sed -n "2p" "$MDB" | cut -f2)
47+
BLOCK_DISPLAYNAME=$(sed -n "2p" "$MDB" | cut -f4)
48+
PROPERTIES_FILE="src/main/java/propertyFiles/$BLOCK_NAME.properties"
49+
50+
# Check correct file exists
51+
if [ ! -r "$PROPERTIES_FILE" ]; then
52+
echo "::error::Missing properties file for metadata block '$BLOCK_NAME', expected at '$PROPERTIES_FILE'"
53+
continue
54+
fi
55+
56+
# Check metadata block properties exist and are equal to TSV source
57+
if ! grep -a -q -e "^metadatablock.name=$BLOCK_NAME$" "$PROPERTIES_FILE"; then
58+
echo "::error::Missing 'metadatablock.name=$BLOCK_NAME' or different from TSV source"
59+
fi
60+
if ! grep -a -q -e "^metadatablock.displayName=$BLOCK_DISPLAYNAME$" "$PROPERTIES_FILE"; then
61+
echo "::error::Missing 'metadatablock.displayName=$BLOCK_DISPLAYNAME' or different from TSV source"
62+
fi
63+
if ! grep -a -q -e "^metadatablock.displayFacet=" "$PROPERTIES_FILE"; then
64+
echo "::error::Missing 'metadatablock.displayFacet=...'"
65+
fi
66+
67+
# Check dataset fields
68+
for FIELD in $(grep -a -A1000 "^#datasetField" "$MDB" | tail -n+2 | grep -a -B1000 "^#controlledVocabulary" | head -n-1 | cut -f2); do
69+
for ENTRY in title description watermark; do
70+
if ! grep -a -q -e "^datasetfieldtype.$FIELD.$ENTRY=" "$PROPERTIES_FILE"; then
71+
echo "::error::Missing key 'datasetfieldtype.$FIELD.$ENTRY=...'"
72+
fi
73+
done
74+
done
75+
76+
# Check CV entries
77+
grep -a -A1000 "^#controlledVocabulary" "$MDB" | tail -n+2 |
78+
{
79+
while read LINE; do
80+
FIELD_NAME=$(echo "$LINE" | cut -f1)
81+
# TODO: needs to replace UTF-8 chars with nearest ascii here!
82+
FIELD_VALUE=$(echo "$LINE" | cut -f2 | tr '[:upper:]' '[:lower:]' | tr " " "_")
83+
if ! grep -q -a -e "^controlledvocabulary.$FIELD_NAME.$FIELD_VALUE=" "$PROPERTIES_FILE"; then
84+
echo "::error::Missing key 'controlledvocabulary.$FIELD_NAME.$FIELD_VALUE=...'"
85+
fi
86+
done
87+
};
88+
done

0 commit comments

Comments
 (0)