2025-01-15 09:21:44 +00:00
|
|
|
name: Update Pull Request
|
2025-01-10 12:36:20 +00:00
|
|
|
|
|
|
|
on:
|
2025-01-15 09:21:44 +00:00
|
|
|
push:
|
|
|
|
branches-ignore: ["main"]
|
2025-01-15 08:58:13 +00:00
|
|
|
workflow_dispatch:
|
2025-01-10 12:36:20 +00:00
|
|
|
|
|
|
|
jobs:
|
2025-01-15 09:21:44 +00:00
|
|
|
update-pr:
|
2025-01-10 12:36:20 +00:00
|
|
|
runs-on: ubuntu-latest
|
2025-01-15 09:21:44 +00:00
|
|
|
permissions:
|
|
|
|
contents: write
|
|
|
|
pull-requests: write
|
2025-01-10 12:36:20 +00:00
|
|
|
|
|
|
|
steps:
|
2025-01-15 09:21:44 +00:00
|
|
|
- name: Generate a token
|
|
|
|
id: generate-token
|
|
|
|
uses: actions/create-github-app-token@v1
|
2025-01-15 08:58:13 +00:00
|
|
|
with:
|
2025-01-15 09:21:44 +00:00
|
|
|
app-id: ${{ vars.APP_ID }}
|
|
|
|
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
2025-01-10 12:36:20 +00:00
|
|
|
|
2025-01-15 09:21:44 +00:00
|
|
|
- name: Checkout code
|
|
|
|
uses: actions/checkout@v4
|
2025-01-10 12:36:20 +00:00
|
|
|
with:
|
2025-01-15 09:21:44 +00:00
|
|
|
fetch-depth: 0
|
2025-01-10 12:36:20 +00:00
|
|
|
|
2025-01-15 09:21:44 +00:00
|
|
|
- name: Update JSON files
|
2025-01-10 12:36:20 +00:00
|
|
|
run: |
|
|
|
|
TODAY=$(date +%Y-%m-%d)
|
2025-01-10 13:20:42 +00:00
|
|
|
for file in $(git diff --diff-filter=A --name-only HEAD | grep '^json/.*\.json$'); do
|
2025-01-10 12:36:20 +00:00
|
|
|
if jq -e '.date_created' $file > /dev/null 2>&1; then
|
|
|
|
echo "Updating date_created in $file"
|
|
|
|
jq --arg date "$TODAY" '.date_created = $date' $file > temp.json && mv temp.json $file
|
|
|
|
git add $file
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2025-01-15 09:21:44 +00:00
|
|
|
- name: Commit and push changes to PR branch
|
2025-01-15 09:18:33 +00:00
|
|
|
env:
|
2025-01-15 09:21:44 +00:00
|
|
|
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
|
2025-01-10 12:36:20 +00:00
|
|
|
run: |
|
2025-01-15 09:21:44 +00:00
|
|
|
git config user.name "github-actions[bot]"
|
|
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
git commit -m "Update date_created in JSON files" || echo "No changes to commit"
|
|
|
|
git push origin HEAD:${{ github.event.pull_request.head.ref }} --force
|