1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-03-08 13:19:05 +00:00
ProxmoxVE/.github/workflows/update_json_date.yml

118 lines
3.9 KiB
YAML
Raw Normal View History

2025-02-11 10:34:00 +01:00
name: Auto Update JSON-Dateien (nur neue Dateien)
2025-02-11 09:43:21 +01:00
on:
2025-02-11 10:33:05 +01:00
push:
branches:
- main
workflow_dispatch:
jobs:
2025-02-11 10:33:05 +01:00
update-json-dates:
runs-on: ubuntu-latest
2025-02-11 10:33:05 +01:00
permissions:
contents: write
pull-requests: write
steps:
2025-02-11 10:33:05 +01:00
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
# Repository auschecken
- name: Checkout repository
uses: actions/checkout@v4
2025-02-11 10:33:05 +01:00
# Git-Setup
- name: Set up Git
2025-02-11 09:59:09 +01:00
run: |
2025-02-11 10:33:05 +01:00
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2025-02-11 09:59:09 +01:00
2025-02-11 10:34:00 +01:00
# 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'
2025-02-11 10:33:05 +01:00
run: |
TODAY=$(date -u +"%Y-%m-%d")
2025-02-11 10:34:00 +01:00
UPDATED=false
2025-02-11 09:59:09 +01:00
2025-02-11 10:34:00 +01:00
while read -r FILE; do
2025-02-11 10:33:05 +01:00
if [[ -f "$FILE" ]]; then
DATE_IN_JSON=$(jq -r '.date_created' "$FILE" 2>/dev/null || echo "")
2025-02-11 09:59:09 +01:00
2025-02-11 10:33:05 +01:00
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"
2025-02-11 10:34:00 +01:00
UPDATED=true
2025-02-11 10:33:05 +01:00
fi
fi
2025-02-11 10:34:00 +01:00
done < new_json_files.txt
2025-02-11 09:59:09 +01:00
2025-02-11 10:34:00 +01:00
if [[ "$UPDATED" == "true" ]]; then
echo "UPDATED=true" >> $GITHUB_ENV
2025-02-11 10:33:05 +01:00
else
2025-02-11 10:34:00 +01:00
echo "UPDATED=false" >> $GITHUB_ENV
2025-02-11 10:33:05 +01:00
fi
2025-02-11 09:59:09 +01:00
2025-02-11 10:33:05 +01:00
# Falls Änderungen existieren: Commit und PR erstellen
- name: Commit and create PR if changes exist
2025-02-11 10:34:00 +01:00
if: env.UPDATED == 'true'
2025-02-11 10:30:20 +01:00
run: |
2025-02-11 10:33:05 +01:00
git add json/*.json
2025-02-11 10:34:00 +01:00
git commit -m "Auto-update JSON date_created fields (new files only)"
2025-02-11 10:33:05 +01:00
git checkout -b pr-update-json-dates
git push origin pr-update-json-dates --force
2025-02-11 10:34:00 +01:00
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." \
2025-02-11 10:33:05 +01:00
--head pr-update-json-dates \
--base main \
--label "automated pr"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
2025-02-11 10:30:20 +01:00
2025-02-11 10:33:05 +01:00
# PR automatisch approven
- name: Approve pull request
2025-02-11 10:34:00 +01:00
if: env.UPDATED == 'true'
2025-02-11 10:33:05 +01:00
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
2025-02-11 10:33:05 +01:00
PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
if [ -n "$PR_NUMBER" ]; then
gh pr review $PR_NUMBER --approve
2025-02-11 09:44:17 +01:00
fi
2025-02-11 10:33:05 +01:00
# PR erneut approven, falls erforderlich
- name: Re-approve pull request after update
2025-02-11 10:34:00 +01:00
if: env.UPDATED == 'true'
env:
2025-02-11 10:33:05 +01:00
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
2025-02-11 10:33:05 +01:00
PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
if [ -n "$PR_NUMBER" ]; then
gh pr review $PR_NUMBER --approve
2025-02-11 10:30:20 +01:00
fi
2025-02-11 10:33:05 +01:00
# Falls keine Änderungen erkannt wurden
- name: No changes detected
2025-02-11 10:34:00 +01:00
if: env.UPDATED == 'false'
run: echo "No new JSON files needed an update. Workflow completed successfully."