|
| 1 | +name: Update Spec Types |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run nightly at 4 AM UTC |
| 6 | + - cron: '0 4 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-spec-types: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Setup Node.js |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '24' |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: npm ci |
| 27 | + |
| 28 | + - name: Fetch latest spec types |
| 29 | + run: npm run fetch:spec-types |
| 30 | + |
| 31 | + - name: Check for changes |
| 32 | + id: check_changes |
| 33 | + run: | |
| 34 | + if git diff --quiet src/spec.types.ts; then |
| 35 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 36 | + else |
| 37 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 38 | + LATEST_SHA=$(grep "Last updated from commit:" src/spec.types.ts | cut -d: -f2 | tr -d ' ') |
| 39 | + echo "sha=$LATEST_SHA" >> $GITHUB_OUTPUT |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Create Pull Request |
| 43 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 44 | + env: |
| 45 | + GH_TOKEN: ${{ github.token }} |
| 46 | + run: | |
| 47 | + git config user.name "github-actions[bot]" |
| 48 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 49 | +
|
| 50 | + git checkout -B update-spec-types |
| 51 | + git add src/spec.types.ts |
| 52 | + git commit -m "chore: update spec.types.ts from upstream" |
| 53 | + git push -f origin update-spec-types |
| 54 | +
|
| 55 | + # Create PR if it doesn't exist, or update if it does |
| 56 | + PR_BODY="This PR updates \`src/spec.types.ts\` from the Model Context Protocol specification. |
| 57 | +
|
| 58 | + Source file: https://github.com/modelcontextprotocol/modelcontextprotocol/blob/${{ steps.check_changes.outputs.sha }}/schema/draft/schema.ts |
| 59 | +
|
| 60 | + This is an automated update triggered by the nightly cron job." |
| 61 | +
|
| 62 | + if gh pr view update-spec-types &>/dev/null; then |
| 63 | + echo "PR already exists, updating description..." |
| 64 | + gh pr edit update-spec-types --body "$PR_BODY" |
| 65 | + else |
| 66 | + gh pr create \ |
| 67 | + --title "chore: update spec.types.ts from upstream" \ |
| 68 | + --body "$PR_BODY" \ |
| 69 | + --base main \ |
| 70 | + --head update-spec-types |
| 71 | + fi |
0 commit comments