ProxmoxVE/.github/workflows/check_and_update_json_date.yml
2025-01-15 10:52:34 +01:00

42 lines
1.3 KiB
YAML

name: Update JSON Date and Push Changes
on:
pull_request:
branches:
- main
jobs:
update-json:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up authentication
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config --global user.name "json-updater-bot"
git config --global user.email "json-updater-bot@users.noreply.github.com"
git config --global credential.helper 'store'
echo "https://json-updater-bot:$GH_TOKEN@github.com" > ~/.git-credentials
- name: Modify JSON files
run: |
TODAY=$(date -u +%Y-%m-%d)
# Filtern der geänderten Dateien im aktuellen PR im Vergleich zum Basisbranch
for json_file in $(git diff --name-only ${{ github.base_ref }}...${{ github.head_ref }} | grep '.json$'); do
if jq -e 'type == "object"' "$json_file" > /dev/null 2>&1; then
jq --arg today "$TODAY" '.date_created = $today' "$json_file" > tmp.json && mv tmp.json "$json_file"
fi
done
- name: Commit changes
run: |
git add *.json
git commit -m "Update date_created to $TODAY"
git push origin ${{ github.head_ref }} # Push direkt in den PR-Branch