Update check_and_update_json_date.yml

This commit is contained in:
CanbiZ 2025-01-15 10:59:01 +01:00 committed by GitHub
parent c934085b16
commit e503ce3806
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,19 +1,20 @@
name: Update JSON Date and Push Changes name: Update JSON Date in PR
on: on:
schedule:
- cron: '0 0,6,12,18 * * *' # Viermal täglich (Mitternacht, 6 Uhr, 12 Uhr, 18 Uhr UTC)
pull_request: pull_request:
branches: branches:
- main - main # Der PR muss gegen den Main-Branch geöffnet werden
jobs: jobs:
update-json: update-json-date:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout code - name: Checkout PR branch
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.head_ref }} ref: ${{ github.head_ref }} # Den PR-Branch auschecken
- name: Set up authentication - name: Set up authentication
env: env:
@ -24,17 +25,20 @@ jobs:
git config --global credential.helper 'store' git config --global credential.helper 'store'
echo "https://json-updater-bot:$GH_TOKEN@github.com" > ~/.git-credentials echo "https://json-updater-bot:$GH_TOKEN@github.com" > ~/.git-credentials
- name: Modify JSON files - name: Check and modify JSON files
run: | run: |
TODAY=$(date -u +%Y-%m-%d) 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 for json_file in $(find . -name "*.json"); do
if jq -e 'type == "object"' "$json_file" > /dev/null 2>&1; then if jq -e 'type == "object"' "$json_file" > /dev/null 2>&1; then
jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file" 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 fi
done done
- name: Commit changes - name: Commit changes if necessary
run: | run: |
git add *.json git diff --quiet || (git commit -m "Update date_created to $TODAY" && git push origin ${{ github.head_ref }})
git commit -m "Update date_created to $TODAY" || echo "No changes to commit"
git push origin ${{ github.head_ref }} # Push direkt in den PR-Branch