ProxmoxVE/.github/workflows/update_json_date.yml

77 lines
2.4 KiB
YAML
Raw Normal View History

2025-02-11 09:43:57 +00:00
name: Auto Update Latest JSON-Datei
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: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:43:57 +00:00
- name: Find latest created JSON file
id: find_latest_json
2025-02-11 09:34:00 +00:00
run: |
2025-02-11 09:43:57 +00:00
LATEST_JSON=$(git log --diff-filter=A --name-only --pretty=format: -- json/*.json | tail -n 1 || true)
2025-02-11 09:34:00 +00:00
2025-02-11 09:43:57 +00:00
if [[ -z "$LATEST_JSON" ]]; then
echo "No new JSON files found."
2025-02-11 09:34:00 +00:00
echo "CHANGED=false" >> $GITHUB_ENV
else
2025-02-11 09:43:57 +00:00
echo "Latest JSON file: $LATEST_JSON"
echo "LATEST_JSON=$LATEST_JSON" >> $GITHUB_ENV
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
.github/workflows/scripts/update-json.sh "$LATEST_JSON"
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:43:57 +00:00
git commit -m "Auto-update date_created in latest JSON file"
git checkout -b pr-update-json-date
git push origin pr-update-json-date --force
gh pr create --title "[core] Auto-update latest JSON file" \
--body "This PR is auto-generated to update the `date_created` field in the latest created JSON file." \
--head pr-update-json-date \
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:43:57 +00:00
PR_NUMBER=$(gh pr list --head "pr-update-json-date" --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