Skip to content

Commit e503ce3

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

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
name: Update JSON Date and Push Changes
1+
name: Update JSON Date in PR
22

33
on:
4+
schedule:
5+
- cron: '0 0,6,12,18 * * *' # Viermal täglich (Mitternacht, 6 Uhr, 12 Uhr, 18 Uhr UTC)
46
pull_request:
57
branches:
6-
- main
8+
- main # Der PR muss gegen den Main-Branch geöffnet werden
79

810
jobs:
9-
update-json:
11+
update-json-date:
1012
runs-on: ubuntu-latest
11-
1213
steps:
13-
- name: Checkout code
14+
- name: Checkout PR branch
1415
uses: actions/checkout@v4
1516
with:
16-
ref: ${{ github.head_ref }}
17+
ref: ${{ github.head_ref }} # Den PR-Branch auschecken
1718

1819
- name: Set up authentication
1920
env:
@@ -24,17 +25,20 @@ jobs:
2425
git config --global credential.helper 'store'
2526
echo "https://json-updater-bot:[email protected]" > ~/.git-credentials
2627
27-
- name: Modify JSON files
28+
- name: Check and modify JSON files
2829
run: |
2930
TODAY=$(date -u +%Y-%m-%d)
31+
# Überprüfen, ob JSON-Dateien vorhanden sind und das Datum setzen
3032
for json_file in $(find . -name "*.json"); do
3133
if jq -e 'type == "object"' "$json_file" > /dev/null 2>&1; then
32-
jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file"
34+
current_date=$(jq -r '.date_created' "$json_file")
35+
if [ "$current_date" != "$TODAY" ]; then
36+
jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file"
37+
git add "$json_file"
38+
fi
3339
fi
3440
done
3541
36-
- name: Commit changes
42+
- name: Commit changes if necessary
3743
run: |
38-
git add *.json
39-
git commit -m "Update date_created to $TODAY" || echo "No changes to commit"
40-
git push origin ${{ github.head_ref }} # Push direkt in den PR-Branch
44+
git diff --quiet || (git commit -m "Update date_created to $TODAY" && git push origin ${{ github.head_ref }})

0 commit comments

Comments
 (0)