Update update_json_date.yml

This commit is contained in:
CanbiZ 2025-02-11 10:35:53 +01:00 committed by GitHub
parent a4037c151e
commit 0122e70b1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
name: Auto Update JSON-Dateien (nur neue Dateien) name: Auto Update JSON-Dateien (new files only)
on: on:
push: push:
@ -22,33 +22,26 @@ jobs:
app-id: ${{ vars.APP_ID }} app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }} private-key: ${{ secrets.APP_PRIVATE_KEY }}
# Repository auschecken
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
# Git-Setup
- name: Set up Git - name: Set up Git
run: | run: |
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"
# Finde neu hinzugefügte JSON-Dateien
- name: Find newly added JSON files - name: Find newly added JSON files
id: find_new_json id: find_new_json
run: | run: |
NEW_JSON_FILES=$(git log --diff-filter=A --name-only --pretty=format: -- json/*.json || true) NEW_JSON_FILES=$(git log --diff-filter=A --name-only --pretty=format: -- json/*.json || true)
if [[ -z "$NEW_JSON_FILES" ]]; then if [[ -z "$NEW_JSON_FILES" ]]; then
echo "No new JSON files found."
echo "CHANGED=false" >> $GITHUB_ENV echo "CHANGED=false" >> $GITHUB_ENV
else else
echo "New JSON files detected:"
echo "$NEW_JSON_FILES"
echo "$NEW_JSON_FILES" > new_json_files.txt echo "$NEW_JSON_FILES" > new_json_files.txt
echo "CHANGED=true" >> $GITHUB_ENV echo "CHANGED=true" >> $GITHUB_ENV
fi fi
# JSON-Dateien aktualisieren (nur wenn neue gefunden wurden)
- name: Update date_created in new JSON files - name: Update date_created in new JSON files
if: env.CHANGED == 'true' if: env.CHANGED == 'true'
run: | run: |
@ -60,7 +53,6 @@ jobs:
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"
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"
UPDATED=true UPDATED=true
fi fi
@ -73,7 +65,6 @@ jobs:
echo "UPDATED=false" >> $GITHUB_ENV echo "UPDATED=false" >> $GITHUB_ENV
fi fi
# 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.UPDATED == 'true' if: env.UPDATED == 'true'
run: | run: |
@ -82,14 +73,13 @@ jobs:
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 new 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." \ --body "This PR is auto-generated 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"
env: env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }} GH_TOKEN: ${{ steps.generate-token.outputs.token }}
# PR automatisch approven
- name: Approve pull request - name: Approve pull request
if: env.UPDATED == 'true' if: env.UPDATED == 'true'
env: env:
@ -100,7 +90,6 @@ jobs:
gh pr review $PR_NUMBER --approve gh pr review $PR_NUMBER --approve
fi fi
# PR erneut approven, falls erforderlich
- name: Re-approve pull request after update - name: Re-approve pull request after update
if: env.UPDATED == 'true' if: env.UPDATED == 'true'
env: env:
@ -111,7 +100,6 @@ jobs:
gh pr review $PR_NUMBER --approve gh pr review $PR_NUMBER --approve
fi fi
# Falls keine Änderungen erkannt wurden
- name: No changes detected - name: No changes detected
if: env.UPDATED == 'false' if: env.UPDATED == 'false'
run: echo "No new JSON files needed an update. Workflow completed successfully." run: echo "No new JSON files needed an update. Workflow completed successfully."