1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-02-01 23:31:50 +00:00
ProxmoxVE/.github/workflows/check_and_update_json_date.yml
2025-01-15 10:59:01 +01:00

45 lines
1.6 KiB
YAML

name: Update JSON Date in PR
on:
schedule:
- cron: '0 0,6,12,18 * * *' # Viermal täglich (Mitternacht, 6 Uhr, 12 Uhr, 18 Uhr UTC)
pull_request:
branches:
- main # Der PR muss gegen den Main-Branch geöffnet werden
jobs:
update-json-date:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }} # Den PR-Branch auschecken
- name: Set up authentication
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config --global user.name "json-updater-bot"
git config --global user.email "json-updater-bot@users.noreply.github.com"
git config --global credential.helper 'store'
echo "https://json-updater-bot:$GH_TOKEN@github.com" > ~/.git-credentials
- name: Check and modify JSON files
run: |
TODAY=$(date -u +%Y-%m-%d)
# Überprüfen, ob JSON-Dateien vorhanden sind und das Datum setzen
for json_file in $(find . -name "*.json"); do
if jq -e 'type == "object"' "$json_file" > /dev/null 2>&1; then
current_date=$(jq -r '.date_created' "$json_file")
if [ "$current_date" != "$TODAY" ]; then
jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file"
git add "$json_file"
fi
fi
done
- name: Commit changes if necessary
run: |
git diff --quiet || (git commit -m "Update date_created to $TODAY" && git push origin ${{ github.head_ref }})