ProxmoxVE/.github/workflows/update_json_date.yml
2025-02-11 10:52:46 +01:00

88 lines
2.8 KiB
YAML

name: Auto Update JSON-Dates
on:
push:
branches:
- main
workflow_dispatch:
jobs:
update-json-dates:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- 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
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for commit checks
- name: Set up Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Find newly created JSON files from today
id: find_new_json
run: |
TODAY=$(date -u +"%Y-%m-%d")
> new_json_files.txt
git fetch origin main --depth=1
for FILE in $(git log --since="$TODAY 00:00:00" --diff-filter=A --name-only --pretty=format: origin/main -- json/*.json || true); do
COMMIT_DATE=$(git log --format=%cI -- "$FILE" | tail -n 1 | cut -dT -f1)
if [[ "$COMMIT_DATE" == "$TODAY" ]]; then
echo "$FILE" >> new_json_files.txt
fi
done
if [[ -s new_json_files.txt ]]; then
echo "CHANGED=true" >> $GITHUB_ENV
else
echo "CHANGED=false" >> $GITHUB_ENV
fi
- name: Run update script
if: env.CHANGED == 'true'
run: |
chmod +x .github/workflows/scripts/update-json.sh
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
if: env.CHANGED == 'true'
run: |
git add json/*.json
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 \
--base main \
--label "automated pr"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Approve pull request
if: env.CHANGED == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
if [ -n "$PR_NUMBER" ]; then
gh pr review $PR_NUMBER --approve
fi