mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-11 18:29:17 +00:00
Update update_json_date.yml
This commit is contained in:
parent
5d58d6d14f
commit
a4037c151e
55
.github/workflows/update_json_date.yml
vendored
55
.github/workflows/update_json_date.yml
vendored
@ -1,11 +1,9 @@
|
||||
name: Auto Update JSON-Dateien
|
||||
name: Auto Update JSON-Dateien (nur neue Dateien)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'json/**.json'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@ -34,40 +32,57 @@ jobs:
|
||||
git config --global user.name "GitHub Actions"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
# JSON-Dateien aktualisieren
|
||||
- name: Update JSON date_created
|
||||
# Finde neu hinzugefügte JSON-Dateien
|
||||
- name: Find newly added JSON files
|
||||
id: find_new_json
|
||||
run: |
|
||||
NEW_JSON_FILES=$(git log --diff-filter=A --name-only --pretty=format: -- json/*.json || true)
|
||||
|
||||
if [[ -z "$NEW_JSON_FILES" ]]; then
|
||||
echo "No new JSON files found."
|
||||
echo "CHANGED=false" >> $GITHUB_ENV
|
||||
else
|
||||
echo "New JSON files detected:"
|
||||
echo "$NEW_JSON_FILES"
|
||||
echo "$NEW_JSON_FILES" > new_json_files.txt
|
||||
echo "CHANGED=true" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
# JSON-Dateien aktualisieren (nur wenn neue gefunden wurden)
|
||||
- name: Update date_created in new JSON files
|
||||
if: env.CHANGED == 'true'
|
||||
run: |
|
||||
TODAY=$(date -u +"%Y-%m-%d")
|
||||
CHANGED=false
|
||||
UPDATED=false
|
||||
|
||||
for FILE in json/*.json; do
|
||||
while read -r FILE; do
|
||||
if [[ -f "$FILE" ]]; then
|
||||
DATE_IN_JSON=$(jq -r '.date_created' "$FILE" 2>/dev/null || echo "")
|
||||
|
||||
if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then
|
||||
echo "Updating date_created in $FILE: $DATE_IN_JSON -> $TODAY"
|
||||
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
|
||||
CHANGED=true
|
||||
UPDATED=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done < new_json_files.txt
|
||||
|
||||
if [[ "$CHANGED" == "true" ]]; then
|
||||
echo "CHANGED=true" >> $GITHUB_ENV
|
||||
if [[ "$UPDATED" == "true" ]]; then
|
||||
echo "UPDATED=true" >> $GITHUB_ENV
|
||||
else
|
||||
echo "CHANGED=false" >> $GITHUB_ENV
|
||||
echo "UPDATED=false" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
# Falls Änderungen existieren: Commit und PR erstellen
|
||||
- name: Commit and create PR if changes exist
|
||||
if: env.CHANGED == 'true'
|
||||
if: env.UPDATED == 'true'
|
||||
run: |
|
||||
git add json/*.json
|
||||
git commit -m "Auto-update JSON date_created fields"
|
||||
git commit -m "Auto-update JSON date_created fields (new files only)"
|
||||
git checkout -b pr-update-json-dates
|
||||
git push origin pr-update-json-dates --force
|
||||
gh pr create --title "[core] Auto-update JSON files" \
|
||||
--body "This PR is auto-generated by a GitHub Action to update the `date_created` field in JSON files." \
|
||||
gh pr create --title "[core] Auto-update new JSON files" \
|
||||
--body "This PR is auto-generated by a GitHub Action to update the `date_created` field in newly created JSON files." \
|
||||
--head pr-update-json-dates \
|
||||
--base main \
|
||||
--label "automated pr"
|
||||
@ -76,7 +91,7 @@ jobs:
|
||||
|
||||
# PR automatisch approven
|
||||
- name: Approve pull request
|
||||
if: env.CHANGED == 'true'
|
||||
if: env.UPDATED == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
@ -87,7 +102,7 @@ jobs:
|
||||
|
||||
# PR erneut approven, falls erforderlich
|
||||
- name: Re-approve pull request after update
|
||||
if: env.CHANGED == 'true'
|
||||
if: env.UPDATED == 'true'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
@ -98,5 +113,5 @@ jobs:
|
||||
|
||||
# Falls keine Änderungen erkannt wurden
|
||||
- name: No changes detected
|
||||
if: env.CHANGED == 'false'
|
||||
run: echo "No changes to commit. Workflow completed successfully."
|
||||
if: env.UPDATED == 'false'
|
||||
run: echo "No new JSON files needed an update. Workflow completed successfully."
|
||||
|
Loading…
Reference in New Issue
Block a user