Skip to content

Commit bf89a03

Browse files
authored
Update check_and_update_json_date.yml
1 parent e503ce3 commit bf89a03

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

.github/workflows/check_and_update_json_date.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,23 @@ jobs:
2828
- name: Check and modify JSON files
2929
run: |
3030
TODAY=$(date -u +%Y-%m-%d)
31-
# Überprüfen, ob JSON-Dateien vorhanden sind und das Datum setzen
31+
32+
# Durchsuchen der Verzeichnisse nach JSON-Dateien
3233
for json_file in $(find . -name "*.json"); do
33-
if jq -e 'type == "object"' "$json_file" > /dev/null 2>&1; then
34-
current_date=$(jq -r '.date_created' "$json_file")
34+
if python3 -c "import json, sys; print(json.load(sys.stdin).get('date_created'))" < "$json_file" &>/dev/null; then
35+
current_date=$(python3 -c "import json, sys; data=json.load(sys.stdin); print(data.get('date_created'))" < "$json_file")
3536
if [ "$current_date" != "$TODAY" ]; then
36-
jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file"
37+
python3 -c "
38+
import json
39+
import sys
40+
41+
# Lade die JSON-Datei
42+
with open('$json_file', 'r+') as file:
43+
data = json.load(file)
44+
data['date_created'] = '$TODAY' # Setze das 'date_created' auf das heutige Datum
45+
file.seek(0)
46+
json.dump(data, file, indent=4)
47+
file.truncate() # Truncate file to remove any extra content"
3748
git add "$json_file"
3849
fi
3950
fi

0 commit comments

Comments
 (0)