Sync Spring Initializr Metadata #132
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Spring Initializr Metadata | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' # Run nightly at midnight UTC | |
| workflow_dispatch: # Allow manual trigger via GitHub Actions UI | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.PAT }} | |
| - name: Create resources folder | |
| run: mkdir -p resources | |
| - name: Fetch and format Initializr metadata | |
| run: | | |
| echo "Fetching metadata from start.spring.io/metadata/client..." | |
| curl -sS -H "Accept: application/json" "https://start.spring.io/metadata/client" -o resources/initializr-metadata.raw.json | |
| jq . resources/initializr-metadata.raw.json > resources/initializr-metadata.json | |
| echo "Fetching dependencies from start.spring.io/dependencies..." | |
| curl -sS -H "Accept: application/vnd.initializr.v2.2+json" "https://start.spring.io/dependencies" -o resources/dependencies.raw.json | |
| jq . resources/dependencies.raw.json > resources/dependencies.json | |
| rm resources/*.raw.json | |
| - name: Create PR with changes | |
| env: | |
| GH_TOKEN: ${{ secrets.PAT }} | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add resources/initializr-metadata.json resources/dependencies.json | |
| if git diff --staged --quiet; then | |
| echo "No changes in metadata found. Skipping." | |
| else | |
| BRANCH="chore/sync-initializr-metadata" | |
| git checkout -b "$BRANCH" | |
| git commit -m "chore: sync Spring Initializr metadata and dependencies" | |
| git push --force origin "$BRANCH" | |
| EXISTING_PR=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number') | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR #$EXISTING_PR already exists. Updated the branch." | |
| else | |
| gh pr create \ | |
| --title "chore: sync Spring Initializr metadata and dependencies" \ | |
| --body "Automated nightly sync of Spring Initializr metadata and dependencies." \ | |
| --head "$BRANCH" \ | |
| --base main | |
| echo "Created new PR." | |
| fi | |
| fi |