ProxmoxVE/.github/workflows/update_json_date.yml

66 lines
2.0 KiB
YAML
Raw Normal View History

name: Update JSON Date on PR
2025-01-15 10:19:32 +00:00
on:
pull_request:
2025-01-15 14:08:44 +00:00
branches:
- main
types:
- opened
- synchronize
- reopened
2025-01-15 10:27:53 +00:00
2025-01-15 10:19:32 +00:00
jobs:
update-json-date:
2025-01-15 10:19:32 +00:00
runs-on: ubuntu-latest
steps:
- name: Checkout PR Branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
2025-01-16 12:52:03 +00:00
token: ${{ secrets.JSON_APP_KEY }}
2025-01-16 12:53:28 +00:00
fetch-depth: 0
- name: Check and Update New JSON Files
run: |
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
HEAD_BRANCH=${{ github.event.pull_request.head.ref }}
2025-01-16 12:53:28 +00:00
# Hole die Base-Branch
git fetch origin $BASE_BRANCH
# Finde nur neue Dateien im PR
NEW_FILES=$(git diff --name-status origin/$BASE_BRANCH HEAD | grep "^A" | awk '{print $2}' | grep '\.json$')
echo "New JSON files found: $NEW_FILES"
TODAY=$(date +%Y-%m-%d)
for FILE in $NEW_FILES; do
if [ -f "$FILE" ]; then
echo "Checking $FILE"
# Prüfe das date_created Feld
CURRENT_DATE=$(jq -r '.date_created' "$FILE")
if [ "$CURRENT_DATE" != "$TODAY" ]; then
echo "Updating date_created in $FILE from $CURRENT_DATE to $TODAY"
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
else
echo "date_created is already set to today in $FILE"
fi
fi
done
2025-01-16 12:53:28 +00:00
# Nur committen wenn es Änderungen gibt
2025-01-16 12:52:03 +00:00
git config --global user.name "json-updater-bot[bot]"
git config --global user.email "json-updater-bot[bot]@users.noreply.github.com"
2025-01-16 12:53:28 +00:00
if [[ -n $(git status -s) ]]; then
git commit -am "Update date_created to today's date in new JSON files"
git push
else
echo "No changes needed"
fi
env:
2025-01-16 12:52:03 +00:00
GH_TOKEN: ${{ secrets.JSON_APP_KEY }}
APP_ID: ${{ secrets.JSON_APP_ID }}