2025-02-11 09:46:57 +00:00
|
|
|
name: Auto Update JSON-Dates
|
2025-02-11 08:43:21 +00:00
|
|
|
|
2025-02-11 08:41:38 +00:00
|
|
|
on:
|
2025-02-11 09:33:05 +00:00
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
2025-02-11 08:41:38 +00:00
|
|
|
workflow_dispatch:
|
|
|
|
|
|
|
|
jobs:
|
2025-02-11 09:33:05 +00:00
|
|
|
update-json-dates:
|
2025-02-11 08:41:38 +00:00
|
|
|
runs-on: ubuntu-latest
|
2025-02-11 09:33:05 +00:00
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: write
|
|
|
|
pull-requests: write
|
|
|
|
|
2025-02-11 08:41:38 +00:00
|
|
|
steps:
|
2025-02-11 09:33:05 +00:00
|
|
|
- name: Generate a token
|
|
|
|
id: generate-token
|
|
|
|
uses: actions/create-github-app-token@v1
|
|
|
|
with:
|
|
|
|
app-id: ${{ vars.APP_ID }}
|
|
|
|
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
|
|
|
|
|
|
|
- name: Checkout repository
|
2025-02-11 08:41:38 +00:00
|
|
|
uses: actions/checkout@v4
|
2025-02-11 09:46:57 +00:00
|
|
|
with:
|
|
|
|
fetch-depth: 10 # Fetch at least 2 commits to compare changes
|
2025-02-11 08:41:38 +00:00
|
|
|
|
2025-02-11 09:33:05 +00:00
|
|
|
- name: Set up Git
|
2025-02-11 08:59:09 +00:00
|
|
|
run: |
|
2025-02-11 09:33:05 +00:00
|
|
|
git config --global user.name "GitHub Actions"
|
|
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
2025-02-11 08:59:09 +00:00
|
|
|
|
2025-02-11 09:46:57 +00:00
|
|
|
- name: Find newly created JSON files from today
|
|
|
|
id: find_new_json
|
2025-02-11 09:34:00 +00:00
|
|
|
run: |
|
2025-02-11 09:46:57 +00:00
|
|
|
TODAY=$(date -u +"%Y-%m-%d")
|
|
|
|
|
|
|
|
git fetch origin main --depth=1
|
|
|
|
|
|
|
|
NEW_JSON_FILES=$(git log --since="$TODAY 00:00:00" --diff-filter=A --name-only --pretty=format: origin/main -- json/*.json || true)
|
2025-02-11 09:34:00 +00:00
|
|
|
|
2025-02-11 09:46:57 +00:00
|
|
|
if [[ -z "$NEW_JSON_FILES" ]]; then
|
|
|
|
echo "No new JSON files created today."
|
2025-02-11 09:34:00 +00:00
|
|
|
echo "CHANGED=false" >> $GITHUB_ENV
|
|
|
|
else
|
2025-02-11 09:46:57 +00:00
|
|
|
echo "New JSON files detected today:"
|
|
|
|
echo "$NEW_JSON_FILES"
|
|
|
|
echo "$NEW_JSON_FILES" > new_json_files.txt
|
2025-02-11 09:34:00 +00:00
|
|
|
echo "CHANGED=true" >> $GITHUB_ENV
|
|
|
|
fi
|
|
|
|
|
2025-02-11 09:43:57 +00:00
|
|
|
- name: Run update script
|
2025-02-11 09:34:00 +00:00
|
|
|
if: env.CHANGED == 'true'
|
2025-02-11 09:33:05 +00:00
|
|
|
run: |
|
2025-02-11 09:43:57 +00:00
|
|
|
chmod +x .github/workflows/scripts/update-json.sh
|
2025-02-11 09:46:57 +00:00
|
|
|
while read -r FILE; do
|
|
|
|
.github/workflows/scripts/update-json.sh "$FILE"
|
|
|
|
done < new_json_files.txt
|
2025-02-11 08:59:09 +00:00
|
|
|
|
2025-02-11 09:33:05 +00:00
|
|
|
- name: Commit and create PR if changes exist
|
2025-02-11 09:43:57 +00:00
|
|
|
if: env.CHANGED == 'true'
|
2025-02-11 09:30:20 +00:00
|
|
|
run: |
|
2025-02-11 09:33:05 +00:00
|
|
|
git add json/*.json
|
2025-02-11 09:46:57 +00:00
|
|
|
git commit -m "Auto-update date_created in new JSON files"
|
|
|
|
git checkout -b pr-update-json-dates
|
|
|
|
git push origin pr-update-json-dates --force
|
|
|
|
gh pr create --title "[core] Auto-update new JSON files" \
|
|
|
|
--body "This PR is auto-generated to update the `date_created` field in newly created JSON files." \
|
|
|
|
--head pr-update-json-dates \
|
2025-02-11 09:33:05 +00:00
|
|
|
--base main \
|
|
|
|
--label "automated pr"
|
|
|
|
env:
|
|
|
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
2025-02-11 09:30:20 +00:00
|
|
|
|
2025-02-11 09:33:05 +00:00
|
|
|
- name: Approve pull request
|
2025-02-11 09:43:57 +00:00
|
|
|
if: env.CHANGED == 'true'
|
2025-02-11 08:41:38 +00:00
|
|
|
env:
|
2025-02-11 09:33:05 +00:00
|
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
2025-02-11 08:41:38 +00:00
|
|
|
run: |
|
2025-02-11 09:46:57 +00:00
|
|
|
PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
|
2025-02-11 09:33:05 +00:00
|
|
|
if [ -n "$PR_NUMBER" ]; then
|
|
|
|
gh pr review $PR_NUMBER --approve
|
2025-02-11 09:30:20 +00:00
|
|
|
fi
|