|
1 | | -name: Update JSON Date in PR |
| 1 | +name: Update Date Created in PR |
2 | 2 |
|
3 | 3 | on: |
4 | | - schedule: |
5 | | - - cron: '0 0,6,12,18 * * *' # Viermal täglich (Mitternacht, 6 Uhr, 12 Uhr, 18 Uhr UTC) |
6 | 4 | pull_request: |
7 | | - branches: |
8 | | - - main # Der PR muss gegen den Main-Branch geöffnet werden |
| 5 | + paths: |
| 6 | + - '*.json' |
| 7 | + types: [opened, synchronize] |
9 | 8 |
|
10 | 9 | jobs: |
11 | | - update-json-date: |
| 10 | + update-date: |
12 | 11 | runs-on: ubuntu-latest |
| 12 | + |
13 | 13 | steps: |
14 | 14 | - name: Checkout PR branch |
15 | 15 | uses: actions/checkout@v4 |
16 | 16 | with: |
17 | | - ref: ${{ github.head_ref }} # Den PR-Branch auschecken |
| 17 | + ref: ${{ github.head_ref }} |
18 | 18 |
|
19 | | - - name: Set up authentication |
20 | | - env: |
21 | | - GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 19 | + - name: Install yq |
22 | 20 | 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 |
27 | 23 |
|
28 | | - - name: Check and modify JSON files |
| 24 | + - name: Update date_created in JSON |
29 | 25 | run: | |
30 | 26 | 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 |
52 | 28 |
|
53 | 29 | - name: Commit changes if necessary |
54 | 30 | run: | |
| 31 | + git status |
55 | 32 | git diff --quiet || (git commit -m "Update date_created to $TODAY" && git push origin ${{ github.head_ref }}) |
0 commit comments