1
0
mirror of https://github.com/community-scripts/ProxmoxVE.git synced 2025-03-08 13:19:05 +00:00
ProxmoxVE/.github/workflows/update_json_date.yml

88 lines
2.8 KiB
YAML
Raw Normal View History

2025-02-11 10:52:46 +01:00
name: Auto Update JSON-Dates
2025-02-11 09:43:21 +01:00
on:
2025-02-11 10:33:05 +01:00
push:
branches:
- main
workflow_dispatch:
jobs:
2025-02-11 10:33:05 +01:00
update-json-dates:
runs-on: ubuntu-latest
2025-02-11 10:33:05 +01:00
permissions:
contents: write
pull-requests: write
steps:
2025-02-11 10:33:05 +01: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 10:46:57 +01:00
with:
2025-02-11 10:52:46 +01:00
fetch-depth: 0 # Fetch full history for commit checks
2025-02-11 10:33:05 +01:00
- name: Set up Git
2025-02-11 09:59:09 +01:00
run: |
2025-02-11 10:33:05 +01:00
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2025-02-11 09:59:09 +01:00
2025-02-11 10:46:57 +01:00
- name: Find newly created JSON files from today
id: find_new_json
2025-02-11 10:34:00 +01:00
run: |
2025-02-11 10:46:57 +01:00
TODAY=$(date -u +"%Y-%m-%d")
2025-02-11 10:49:19 +01:00
> new_json_files.txt
2025-02-11 10:46:57 +01:00
2025-02-11 10:52:46 +01:00
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
2025-02-11 10:49:19 +01:00
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 10:46:57 +01:00
2025-02-11 10:49:19 +01:00
if [[ -s new_json_files.txt ]]; then
2025-02-11 10:34:00 +01:00
echo "CHANGED=true" >> $GITHUB_ENV
2025-02-11 10:49:19 +01:00
else
echo "CHANGED=false" >> $GITHUB_ENV
2025-02-11 10:34:00 +01:00
fi
2025-02-11 10:43:57 +01:00
- name: Run update script
2025-02-11 10:34:00 +01:00
if: env.CHANGED == 'true'
2025-02-11 10:33:05 +01:00
run: |
2025-02-11 10:49:37 +01:00
chmod +x .github/workflows/scripts/update-json.sh
2025-02-11 10:46:57 +01:00
while read -r FILE; do
2025-02-11 10:49:37 +01:00
.github/workflows/scripts/update-json.sh "$FILE"
2025-02-11 10:46:57 +01:00
done < new_json_files.txt
2025-02-11 09:59:09 +01:00
2025-02-11 10:33:05 +01:00
- name: Commit and create PR if changes exist
2025-02-11 10:43:57 +01:00
if: env.CHANGED == 'true'
2025-02-11 10:30:20 +01:00
run: |
2025-02-11 10:33:05 +01:00
git add json/*.json
2025-02-11 10:46:57 +01: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 10:33:05 +01:00
--base main \
--label "automated pr"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
2025-02-11 10:30:20 +01:00
2025-02-11 10:33:05 +01:00
- name: Approve pull request
2025-02-11 10:43:57 +01:00
if: env.CHANGED == 'true'
env:
2025-02-11 10:33:05 +01:00
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
2025-02-11 10:46:57 +01:00
PR_NUMBER=$(gh pr list --head "pr-update-json-dates" --json number --jq '.[].number')
2025-02-11 10:33:05 +01:00
if [ -n "$PR_NUMBER" ]; then
gh pr review $PR_NUMBER --approve
2025-02-11 10:30:20 +01:00
fi