ProxmoxVE/.github/workflows/update_json_date.yml

86 lines
2.7 KiB
YAML
Raw Normal View History

2025-02-11 09:49:19 +00:00
name: Auto Update JSON-Dateien (new files only)
2025-02-11 08:43:21 +00:00
on:
2025-02-11 09:33:05 +00:00
push:
branches:
- main
workflow_dispatch:
jobs:
2025-02-11 09:33:05 +00:00
update-json-dates:
runs-on: ubuntu-latest
2025-02-11 09:33:05 +00:00
permissions:
contents: write
pull-requests: write
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
uses: actions/checkout@v4
2025-02-11 09:46:57 +00:00
with:
2025-02-11 09:49:19 +00:00
fetch-depth: 0 # Fetch full history to check commit timestamps
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")
2025-02-11 09:49:19 +00:00
> new_json_files.txt
2025-02-11 09:46:57 +00:00
2025-02-11 09:49:19 +00:00
for FILE in $(git ls-files --json | jq -r '.[]'); 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
2025-02-11 09:46:57 +00:00
2025-02-11 09:49:19 +00:00
if [[ -s new_json_files.txt ]]; then
2025-02-11 09:34:00 +00:00
echo "CHANGED=true" >> $GITHUB_ENV
2025-02-11 09:49:19 +00:00
else
echo "CHANGED=false" >> $GITHUB_ENV
2025-02-11 09:34:00 +00:00
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:49:37 +00:00
chmod +x .github/workflows/scripts/update-json.sh
2025-02-11 09:46:57 +00:00
while read -r FILE; do
2025-02-11 09:49:37 +00:00
.github/workflows/scripts/update-json.sh "$FILE"
2025-02-11 09:46:57 +00:00
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'
env:
2025-02-11 09:33:05 +00:00
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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