diff --git a/.github/workflows/scripts/update-json.sh b/.github/workflows/scripts/update-json.sh new file mode 100644 index 00000000..df1ae26f --- /dev/null +++ b/.github/workflows/scripts/update-json.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +FILE=$1 +TODAY=$(date -u +"%Y-%m-%d") + +if [[ -z "$FILE" ]]; then + echo "No file specified. Exiting." + exit 1 +fi + +if [[ ! -f "$FILE" ]]; then + echo "File $FILE not found. Exiting." + exit 1 +fi + +DATE_IN_JSON=$(jq -r '.date_created' "$FILE" 2>/dev/null || echo "") + +if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then + echo "Updating $FILE: $DATE_IN_JSON -> $TODAY" + jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE" +else + echo "No update needed." +fi