Update update_json_date.yml

This commit is contained in:
CanbiZ 2025-02-11 10:46:57 +01:00 committed by GitHub
parent f1683ad39f
commit 8acf81b937
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
name: Auto Update Latest JSON-Datei name: Auto Update JSON-Dates
on: on:
push: push:
@ -24,23 +24,30 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
with:
fetch-depth: 10 # Fetch at least 2 commits to compare changes
- 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"
- name: Find latest created JSON file - name: Find newly created JSON files from today
id: find_latest_json id: find_new_json
run: | run: |
LATEST_JSON=$(git log --diff-filter=A --name-only --pretty=format: -- json/*.json | tail -n 1 || true) TODAY=$(date -u +"%Y-%m-%d")
if [[ -z "$LATEST_JSON" ]]; then git fetch origin main --depth=1
echo "No new JSON files found."
NEW_JSON_FILES=$(git log --since="$TODAY 00:00:00" --diff-filter=A --name-only --pretty=format: origin/main -- json/*.json || true)
if [[ -z "$NEW_JSON_FILES" ]]; then
echo "No new JSON files created today."
echo "CHANGED=false" >> $GITHUB_ENV echo "CHANGED=false" >> $GITHUB_ENV
else else
echo "Latest JSON file: $LATEST_JSON" echo "New JSON files detected today:"
echo "LATEST_JSON=$LATEST_JSON" >> $GITHUB_ENV echo "$NEW_JSON_FILES"
echo "$NEW_JSON_FILES" > new_json_files.txt
echo "CHANGED=true" >> $GITHUB_ENV echo "CHANGED=true" >> $GITHUB_ENV
fi fi
@ -48,18 +55,20 @@ jobs:
if: env.CHANGED == 'true' if: env.CHANGED == 'true'
run: | run: |
chmod +x .github/workflows/scripts/update-json.sh chmod +x .github/workflows/scripts/update-json.sh
.github/workflows/scripts/update-json.sh "$LATEST_JSON" while read -r FILE; do
.github/workflows/scripts/update-json.sh "$FILE"
done < new_json_files.txt
- name: Commit and create PR if changes exist - name: Commit and create PR if changes exist
if: env.CHANGED == 'true' if: env.CHANGED == 'true'
run: | run: |
git add json/*.json git add json/*.json
git commit -m "Auto-update date_created in latest JSON file" git commit -m "Auto-update date_created in new JSON files"
git checkout -b pr-update-json-date git checkout -b pr-update-json-dates
git push origin pr-update-json-date --force git push origin pr-update-json-dates --force
gh pr create --title "[core] Auto-update latest JSON file" \ gh pr create --title "[core] Auto-update new JSON files" \
--body "This PR is auto-generated to update the `date_created` field in the latest created JSON file." \ --body "This PR is auto-generated to update the `date_created` field in newly created JSON files." \
--head pr-update-json-date \ --head pr-update-json-dates \
--base main \ --base main \
--label "automated pr" --label "automated pr"
env: env:
@ -70,7 +79,7 @@ jobs:
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
PR_NUMBER=$(gh pr list --head "pr-update-json-date" --json number --jq '.[].number') PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
if [ -n "$PR_NUMBER" ]; then if [ -n "$PR_NUMBER" ]; then
gh pr review $PR_NUMBER --approve gh pr review $PR_NUMBER --approve
fi fi