name: Auto Update Latest JSON-Datei 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 - 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 latest created JSON file id: find_latest_json run: | LATEST_JSON=$(git log --diff-filter=A --name-only --pretty=format: -- json/*.json | tail -n 1 || true) if [[ -z "$LATEST_JSON" ]]; then echo "No new JSON files found." echo "CHANGED=false" >> $GITHUB_ENV else echo "Latest JSON file: $LATEST_JSON" echo "LATEST_JSON=$LATEST_JSON" >> $GITHUB_ENV echo "CHANGED=true" >> $GITHUB_ENV fi - name: Run update script if: env.CHANGED == 'true' run: | chmod +x .github/workflows/scripts/update-json.sh .github/workflows/scripts/update-json.sh "$LATEST_JSON" - 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 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 \ --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-date" --json number --jq '.[].number') if [ -n "$PR_NUMBER" ]; then gh pr review $PR_NUMBER --approve fi