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:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
|
||||||
- 'json/**.json'
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@ -34,40 +32,57 @@ jobs:
|
|||||||
git config --global user.name "GitHub Actions"
|
git config --global user.name "GitHub Actions"
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
# JSON-Dateien aktualisieren
|
# Finde neu hinzugefügte JSON-Dateien
|
||||||
- name: Update JSON date_created
|
- 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: |
|
run: |
|
||||||
TODAY=$(date -u +"%Y-%m-%d")
|
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
|
if [[ -f "$FILE" ]]; then
|
||||||
DATE_IN_JSON=$(jq -r '.date_created' "$FILE" 2>/dev/null || echo "")
|
DATE_IN_JSON=$(jq -r '.date_created' "$FILE" 2>/dev/null || echo "")
|
||||||
|
|
||||||
if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then
|
if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then
|
||||||
echo "Updating date_created in $FILE: $DATE_IN_JSON -> $TODAY"
|
echo "Updating date_created in $FILE: $DATE_IN_JSON -> $TODAY"
|
||||||
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
|
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
|
||||||
CHANGED=true
|
UPDATED=true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done < new_json_files.txt
|
||||||
|
|
||||||
if [[ "$CHANGED" == "true" ]]; then
|
if [[ "$UPDATED" == "true" ]]; then
|
||||||
echo "CHANGED=true" >> $GITHUB_ENV
|
echo "UPDATED=true" >> $GITHUB_ENV
|
||||||
else
|
else
|
||||||
echo "CHANGED=false" >> $GITHUB_ENV
|
echo "UPDATED=false" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Falls Änderungen existieren: Commit und PR erstellen
|
# Falls Änderungen existieren: Commit und PR erstellen
|
||||||
- name: Commit and create PR if changes exist
|
- name: Commit and create PR if changes exist
|
||||||
if: env.CHANGED == 'true'
|
if: env.UPDATED == 'true'
|
||||||
run: |
|
run: |
|
||||||
git add json/*.json
|
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 checkout -b pr-update-json-dates
|
||||||
git push origin pr-update-json-dates --force
|
git push origin pr-update-json-dates --force
|
||||||
gh pr create --title "[core] Auto-update 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 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 \
|
--head pr-update-json-dates \
|
||||||
--base main \
|
--base main \
|
||||||
--label "automated pr"
|
--label "automated pr"
|
||||||
@ -76,7 +91,7 @@ jobs:
|
|||||||
|
|
||||||
# PR automatisch approven
|
# PR automatisch approven
|
||||||
- name: Approve pull request
|
- name: Approve pull request
|
||||||
if: env.CHANGED == 'true'
|
if: env.UPDATED == 'true'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
@ -87,7 +102,7 @@ jobs:
|
|||||||
|
|
||||||
# PR erneut approven, falls erforderlich
|
# PR erneut approven, falls erforderlich
|
||||||
- name: Re-approve pull request after update
|
- name: Re-approve pull request after update
|
||||||
if: env.CHANGED == 'true'
|
if: env.UPDATED == 'true'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
@ -98,5 +113,5 @@ jobs:
|
|||||||
|
|
||||||
# Falls keine Änderungen erkannt wurden
|
# Falls keine Änderungen erkannt wurden
|
||||||
- name: No changes detected
|
- name: No changes detected
|
||||||
if: env.CHANGED == 'false'
|
if: env.UPDATED == 'false'
|
||||||
run: echo "No changes to commit. Workflow completed successfully."
|
run: echo "No new JSON files needed an update. Workflow completed successfully."
|
||||||
|
Loading…
Reference in New Issue
Block a user