Skip to content

Commit 41c4b11

Browse files
authored
Update check_and_update_json_date.yml
1 parent bf89a03 commit 41c4b11

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed
Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,32 @@
1-
name: Update JSON Date in PR
1+
name: Update Date Created 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)
64
pull_request:
7-
branches:
8-
- main # Der PR muss gegen den Main-Branch geöffnet werden
5+
paths:
6+
- '*.json'
7+
types: [opened, synchronize]
98

109
jobs:
11-
update-json-date:
10+
update-date:
1211
runs-on: ubuntu-latest
12+
1313
steps:
1414
- name: Checkout PR branch
1515
uses: actions/checkout@v4
1616
with:
17-
ref: ${{ github.head_ref }} # Den PR-Branch auschecken
17+
ref: ${{ github.head_ref }}
1818

19-
- name: Set up authentication
20-
env:
21-
GH_TOKEN: ${{ secrets.GH_TOKEN }}
19+
- name: Install yq
2220
run: |
23-
git config --global user.name "json-updater-bot"
24-
git config --global user.email "[email protected]"
25-
git config --global credential.helper 'store'
26-
echo "https://json-updater-bot:[email protected]" > ~/.git-credentials
21+
curl -sSL https://github.com/mikefarah/yq/releases/download/v4.18.1/yq_linux_amd64 -o /usr/local/bin/yq
22+
chmod +x /usr/local/bin/yq
2723
28-
- name: Check and modify JSON files
24+
- name: Update date_created in JSON
2925
run: |
3026
TODAY=$(date -u +%Y-%m-%d)
31-
32-
# Durchsuchen der Verzeichnisse nach JSON-Dateien
33-
for json_file in $(find . -name "*.json"); do
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")
36-
if [ "$current_date" != "$TODAY" ]; then
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"
48-
git add "$json_file"
49-
fi
50-
fi
51-
done
27+
yq e '.date_created = strftime("%Y-%m-%d")' -i your_file.json
5228
5329
- name: Commit changes if necessary
5430
run: |
31+
git status
5532
git diff --quiet || (git commit -m "Update date_created to $TODAY" && git push origin ${{ github.head_ref }})

0 commit comments

Comments
 (0)