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
2025-02-11 09:46:06 +01:00

82 lines
2.6 KiB
YAML

name: Update JSON Date
on:
schedule:
- cron: "0 */6 * * *" # Läuft alle 6 Stunden
workflow_dispatch:
jobs:
check-open-prs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Open PRs
id: list_prs
run: |
echo "Fetching open PRs..."
PRS=$(gh pr list --state open --json number --jq '.[].number' || echo "")
if [[ -z "$PRS" ]]; then
echo "No open PRs found."
exit 0
fi
echo "$PRS" | tr ' ' '\n' > pr_list.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Process Each PR
if: success()
run: |
TODAY=$(date -u +"%Y-%m-%d")
while read -r PR_NUMBER; do
echo "Processing PR #$PR_NUMBER"
BRANCH_NAME=$(gh pr view $PR_NUMBER --json headRefName --jq '.headRefName')
REPO_NAME="${{ github.repository }}"
# Prüfen, ob der Branch remote existiert
if ! git ls-remote --exit-code origin "$BRANCH_NAME"; then
echo "Branch $BRANCH_NAME für PR #$PR_NUMBER existiert nicht, überspringe..."
continue
fi
# Checkout PR Branch
git fetch origin "$BRANCH_NAME"
git checkout -B "$BRANCH_NAME" "origin/$BRANCH_NAME"
# Get newly added JSON files
NEW_JSON_FILES=$(gh api repos/$REPO_NAME/pulls/$PR_NUMBER/files --jq '.[] | select(.status == "added") | .filename' | grep '^json/.*\.json$' || true)
if [[ -z "$NEW_JSON_FILES" ]]; then
echo "No new JSON files in PR #$PR_NUMBER"
continue
fi
UPDATED=false
for FILE in $NEW_JSON_FILES; do
DATE_IN_JSON=$(jq -r '.date_created' "$FILE")
if [[ "$DATE_IN_JSON" != "$TODAY" ]]; then
echo "Updating $FILE: $DATE_IN_JSON -> $TODAY"
jq --arg date "$TODAY" '.date_created = $date' "$FILE" > tmp.json && mv tmp.json "$FILE"
UPDATED=true
fi
done
if [[ "$UPDATED" == "true" ]]; then
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "Update date_created in new JSON files"
git push origin "$BRANCH_NAME"
else
echo "No updates needed for PR #$PR_NUMBER"
fi
done < pr_list.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}