changeset-release.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. name: Changeset Release
  2. run-name: Changeset Release ${{ github.actor != 'R00-B0T' && '- Create PR' || '- Ready for Review' }}
  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. # Auto-merge PR
  77. - name: Automerge on PR
  78. if: false # Needs enablePullRequestAutoMerge in repo settings to work
  79. run: gh pr merge --auto --merge ${{ github.event.pull_request.number }}
  80. env:
  81. GH_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }}