ProxmoxVE/.github/workflows/check_and_update_json_date.yml

56 lines
1.9 KiB
YAML
Raw Normal View History

2025-01-15 09:59:01 +00:00
name: Update JSON Date in PR
on:
2025-01-15 09:59:01 +00:00
schedule:
- cron: '0 0,6,12,18 * * *' # Viermal täglich (Mitternacht, 6 Uhr, 12 Uhr, 18 Uhr UTC)
2025-01-15 09:50:30 +00:00
pull_request:
2025-01-15 09:37:30 +00:00
branches:
2025-01-15 09:59:01 +00:00
- main # Der PR muss gegen den Main-Branch geöffnet werden
jobs:
2025-01-15 09:59:01 +00:00
update-json-date:
runs-on: ubuntu-latest
steps:
2025-01-15 09:59:01 +00:00
- name: Checkout PR branch
2025-01-15 09:40:38 +00:00
uses: actions/checkout@v4
2025-01-15 09:50:30 +00:00
with:
2025-01-15 09:59:01 +00:00
ref: ${{ github.head_ref }} # Den PR-Branch auschecken
2025-01-15 09:25:38 +00:00
2025-01-15 09:40:38 +00:00
- name: Set up authentication
env:
2025-01-15 09:50:30 +00:00
GH_TOKEN: ${{ secrets.GH_TOKEN }}
2025-01-15 09:40:38 +00:00
run: |
2025-01-15 09:50:30 +00:00
git config --global user.name "json-updater-bot"
git config --global user.email "json-updater-bot@users.noreply.github.com"
2025-01-15 09:40:38 +00:00
git config --global credential.helper 'store'
2025-01-15 09:50:30 +00:00
echo "https://json-updater-bot:$GH_TOKEN@github.com" > ~/.git-credentials
2025-01-15 09:40:38 +00:00
2025-01-15 09:59:01 +00:00
- name: Check and modify JSON files
run: |
2025-01-15 09:25:38 +00:00
TODAY=$(date -u +%Y-%m-%d)
2025-01-15 10:00:17 +00:00
# Durchsuchen der Verzeichnisse nach JSON-Dateien
2025-01-15 09:54:23 +00:00
for json_file in $(find . -name "*.json"); do
2025-01-15 10:00:17 +00:00
if python3 -c "import json, sys; print(json.load(sys.stdin).get('date_created'))" < "$json_file" &>/dev/null; then
current_date=$(python3 -c "import json, sys; data=json.load(sys.stdin); print(data.get('date_created'))" < "$json_file")
2025-01-15 09:59:01 +00:00
if [ "$current_date" != "$TODAY" ]; then
2025-01-15 10:00:17 +00:00
python3 -c "
import json
import sys
# Lade die JSON-Datei
with open('$json_file', 'r+') as file:
data = json.load(file)
data['date_created'] = '$TODAY' # Setze das 'date_created' auf das heutige Datum
file.seek(0)
json.dump(data, file, indent=4)
file.truncate() # Truncate file to remove any extra content"
2025-01-15 09:59:01 +00:00
git add "$json_file"
fi
2025-01-15 09:45:22 +00:00
fi
2025-01-15 09:40:38 +00:00
done
2025-01-15 09:59:01 +00:00
- name: Commit changes if necessary
run: |
2025-01-15 09:59:01 +00:00
git diff --quiet || (git commit -m "Update date_created to $TODAY" && git push origin ${{ github.head_ref }})