1- name : Auto Update JSON-Dateien (new files only)
1+ name : Auto Update JSON-Date
22
33on :
44 push :
@@ -25,30 +25,30 @@ jobs:
2525 - name : Checkout repository
2626 uses : actions/checkout@v4
2727 with :
28- fetch-depth : 0 # Full history to check commit timestamps
28+ fetch-depth : 0 # Full history for proper detection
2929
3030 - name : Set up Git
3131 run : |
3232 git config --global user.name "GitHub Actions"
3333 git config --global user.email "github-actions[bot]@users.noreply.github.com"
3434
35- - name : Find newly created JSON files from today
36- id : find_new_json
35+ - name : Find JSON files with incorrect date_created
36+ id : find_wrong_json
3737 run : |
3838 TODAY=$(date -u +"%Y-%m-%d")
39- git fetch origin main --depth=1
40- LATEST_COMMIT=$(git rev-parse origin/main)
39+ > incorrect_json_files.txt
4140
42- > new_json_files.txt
41+ for FILE in json/*.json; do
42+ if [[ -f "$FILE" ]]; then
43+ DATE_IN_JSON=$(jq -r '.date_created' "$FILE" 2>/dev/null || echo "")
4344
44- for FILE in $(git diff --diff-filter=A --name-only $LATEST_COMMIT -- json/); do
45- COMMIT_DATE=$(git log --format=%cI -- "$FILE" | tail -n 1 | cut -dT -f1)
46- if [[ "$COMMIT_DATE" == "$TODAY" ]]; then
47- echo "$FILE" >> new_json_files.txt
45+ if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then
46+ echo "$FILE" >> incorrect_json_files.txt
47+ fi
4848 fi
4949 done
5050
51- if [[ -s new_json_files .txt ]]; then
51+ if [[ -s incorrect_json_files .txt ]]; then
5252 echo "CHANGED=true" >> $GITHUB_ENV
5353 else
5454 echo "CHANGED=false" >> $GITHUB_ENV
@@ -57,21 +57,21 @@ jobs:
5757 - name : Run update script
5858 if : env.CHANGED == 'true'
5959 run : |
60- chmod +x .github/scripts/update-json.sh
60+ chmod +x .github/workflows/ scripts/update-json.sh
6161 while read -r FILE; do
62- .github/scripts/update-json.sh "$FILE"
63- done < new_json_files .txt
62+ .github/workflows/ scripts/update-json.sh "$FILE"
63+ done < incorrect_json_files .txt
6464
6565 - name : Commit and create PR if changes exist
6666 if : env.CHANGED == 'true'
6767 run : |
6868 git add json/*.json
69- git commit -m "Auto-update date_created in new JSON files"
70- git checkout -b pr-update -json-dates
71- git push origin pr-update -json-dates --force
72- gh pr create --title "[core] Auto-update new JSON files " \
73- --body "This PR is auto-generated to update the `date_created` field in newly created JSON files." \
74- --head pr-update -json-dates \
69+ git commit -m "Auto-update date_created in incorrect JSON files"
70+ git checkout -b pr-fix -json-dates
71+ git push origin pr-fix -json-dates --force
72+ gh pr create --title "[core] Fix incorrect JSON date_created fields " \
73+ --body "This PR is auto-generated to fix incorrect `date_created` fields in JSON files." \
74+ --head pr-fix -json-dates \
7575 --base main \
7676 --label "automated pr"
7777 env :
8282 env :
8383 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
8484 run : |
85- PR_NUMBER=$(gh pr list --head "pr-update -json-dates" --json number --jq '.[].number')
85+ PR_NUMBER=$(gh pr list --head "pr-fix -json-dates" --json number --jq '.[].number')
8686 if [ -n "$PR_NUMBER" ]; then
8787 gh pr review $PR_NUMBER --approve
8888 fi
0 commit comments