changeset-release.yml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. name: Changeset Release
  2. run-name: Changeset Release ${{ github.actor != 'R00-B0T' && '- Create PR' || '- Approve & Merge' }}
  3. on:
  4. pull_request:
  5. types: [closed, opened, synchronize, labeled]
  6. env:
  7. REPO_PATH: ${{ github.repository }}
  8. GIT_REF: ${{ github.event.pull_request.head.sha }}
  9. jobs:
  10. # Job 1: Create version bump PR when changesets are merged to main
  11. changeset-pr-version-bump:
  12. if: >
  13. github.event_name == 'pull_request' &&
  14. github.event.pull_request.merged == true &&
  15. github.event.pull_request.base.ref == 'main' &&
  16. github.actor != 'R00-B0T'
  17. runs-on: ubuntu-latest
  18. permissions:
  19. contents: write
  20. pull-requests: write
  21. steps:
  22. - name: Git Checkout
  23. uses: actions/checkout@v4
  24. with:
  25. fetch-depth: 0
  26. ref: ${{ env.GIT_REF }}
  27. - name: Setup Node.js
  28. uses: actions/setup-node@v4
  29. with:
  30. node-version: 20
  31. cache: 'npm'
  32. - name: Install Dependencies
  33. run: npm run install:all
  34. # Check if there are any new changesets to process
  35. - name: Check for changesets
  36. id: check-changesets
  37. run: |
  38. NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
  39. echo "Changesets diff with previous version: $NEW_CHANGESETS"
  40. echo "new_changesets=$NEW_CHANGESETS" >> $GITHUB_OUTPUT
  41. # Create version bump PR using changesets/action if there are new changesets
  42. - name: Changeset Pull Request
  43. if: steps.check-changesets.outputs.new_changesets != '0'
  44. id: changesets
  45. uses: changesets/action@v1
  46. with:
  47. commit: "changeset version bump"
  48. title: "Changeset version bump"
  49. version: npm run version-packages # This performs the changeset version bump
  50. env:
  51. GITHUB_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }}
  52. # Job 2: Process version bump PR created by R00-B0T
  53. changeset-pr-approve-merge:
  54. name: Auto approve and merge Bump version PRs
  55. runs-on: ubuntu-latest
  56. permissions:
  57. contents: write
  58. pull-requests: write
  59. if: >
  60. github.event_name == 'pull_request' &&
  61. github.event.pull_request.base.ref == 'main' &&
  62. github.actor == 'R00-B0T' &&
  63. contains(github.event.pull_request.title, 'Changeset version bump')
  64. steps:
  65. - name: Checkout Repo
  66. uses: actions/checkout@v4
  67. with:
  68. token: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }}
  69. fetch-depth: 0
  70. ref: ${{ env.GIT_REF }}
  71. # Auto-approve PR
  72. - name: Auto approve PR
  73. uses: hmarr/auto-approve-action@v4
  74. with:
  75. review-message: "I'm approving since it's a bump version PR"
  76. # Enable auto-merge for the PR
  77. - name: Enable automerge on PR
  78. run: gh pr merge --merge --auto ${{ github.event.pull_request.number }}
  79. env:
  80. GH_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }}