changeset-release.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. name: Changeset Release
  2. run-name: Changeset Release ${{ github.actor != 'R00-B0T' && '- Create PR' || '- Update Changelog' }}
  3. on:
  4. workflow_dispatch:
  5. pull_request:
  6. types: [closed, opened, labeled]
  7. env:
  8. REPO_PATH: ${{ github.repository }}
  9. GIT_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}
  10. NODE_VERSION: 20.19.2
  11. PNPM_VERSION: 10.8.1
  12. jobs:
  13. # Job 1: Create version bump PR when changesets are merged to main
  14. changeset-pr-version-bump:
  15. if: >
  16. ( github.event_name == 'pull_request' &&
  17. github.event.pull_request.merged == true &&
  18. github.event.pull_request.base.ref == 'main' &&
  19. github.actor != 'R00-B0T' ) ||
  20. github.event_name == 'workflow_dispatch'
  21. runs-on: ubuntu-latest
  22. permissions:
  23. contents: write
  24. pull-requests: write
  25. steps:
  26. - name: Git Checkout
  27. uses: actions/checkout@v4
  28. with:
  29. fetch-depth: 0
  30. ref: ${{ env.GIT_REF }}
  31. - name: Install pnpm
  32. uses: pnpm/action-setup@v4
  33. with:
  34. version: ${{ env.PNPM_VERSION }}
  35. - name: Setup Node.js
  36. uses: actions/setup-node@v4
  37. with:
  38. node-version: ${{ env.NODE_VERSION }}
  39. cache: 'pnpm'
  40. - name: Install Dependencies
  41. run: pnpm install
  42. # Check if there are any new changesets to process
  43. - name: Check for changesets
  44. id: check-changesets
  45. run: |
  46. NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
  47. echo "Changesets diff with previous version: $NEW_CHANGESETS"
  48. echo "new_changesets=$NEW_CHANGESETS" >> $GITHUB_OUTPUT
  49. # Create version bump PR using changesets/action if there are new changesets
  50. - name: Changeset Pull Request
  51. if: steps.check-changesets.outputs.new_changesets != '0'
  52. id: changesets
  53. uses: changesets/action@v1
  54. with:
  55. commit: "changeset version bump"
  56. title: "Changeset version bump"
  57. version: pnpm changeset:version # This performs the changeset version bump
  58. env:
  59. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  60. # Job 2: Process version bump PR created by R00-B0T
  61. changeset-pr-edit-approve:
  62. name: Auto approve and merge Bump version PRs
  63. runs-on: ubuntu-latest
  64. permissions:
  65. contents: write
  66. pull-requests: write
  67. if: >
  68. github.event_name == 'pull_request' &&
  69. github.event.pull_request.base.ref == 'main' &&
  70. github.actor == 'R00-B0T' &&
  71. contains(github.event.pull_request.title, 'Changeset version bump')
  72. steps:
  73. - name: Determine checkout ref
  74. id: checkout-ref
  75. run: |
  76. echo "Event action: ${{ github.event.action }}"
  77. echo "Actor: ${{ github.actor }}"
  78. echo "Head ref: ${{ github.head_ref }}"
  79. echo "PR SHA: ${{ github.event.pull_request.head.sha }}"
  80. if [[ "${{ github.event.action }}" == "opened" && "${{ github.actor }}" == "R00-B0T" ]]; then
  81. echo "Using branch ref: ${{ github.head_ref }}"
  82. echo "git_ref=${{ github.head_ref }}" >> $GITHUB_OUTPUT
  83. else
  84. echo "Using SHA ref: ${{ github.event.pull_request.head.sha }}"
  85. echo "git_ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
  86. fi
  87. - name: Checkout Repo
  88. uses: actions/checkout@v4
  89. with:
  90. token: ${{ secrets.GITHUB_TOKEN }}
  91. fetch-depth: 0
  92. ref: ${{ steps.checkout-ref.outputs.git_ref }}
  93. # Commit and push changelog updates
  94. - name: Push Changelog updates
  95. if: ${{ !contains(github.event.pull_request.labels.*.name, 'changelog-ready') }}
  96. run: |
  97. git config user.name "R00-B0T"
  98. git config user.email [email protected]
  99. echo "Running git add and commit..."
  100. git add CHANGELOG.md
  101. git commit -m "Updating CHANGELOG.md format"
  102. git status
  103. echo "--------------------------------------------------------------------------------"
  104. echo "Pushing to remote..."
  105. echo "--------------------------------------------------------------------------------"
  106. git push
  107. # Add label to indicate changelog has been formatted
  108. - name: Add changelog-ready label
  109. if: ${{ !contains(github.event.pull_request.labels.*.name, 'changelog-ready') }}
  110. uses: actions/github-script@v7
  111. with:
  112. github-token: ${{ secrets.GITHUB_TOKEN }}
  113. script: |
  114. await github.rest.issues.addLabels({
  115. owner: context.repo.owner,
  116. repo: context.repo.repo,
  117. issue_number: context.issue.number,
  118. labels: ['changelog-ready']
  119. });
  120. # Auto-approve PR only after it has been labeled
  121. - name: Auto approve PR
  122. if: contains(github.event.pull_request.labels.*.name, 'changelog-ready')
  123. uses: hmarr/auto-approve-action@v4
  124. with:
  125. review-message: "I'm approving since it's a bump version PR"
  126. # Auto-merge PR
  127. - name: Automerge on PR
  128. if: false # Needs enablePullRequestAutoMerge in repo settings to work contains(github.event.pull_request.labels.*.name, 'changelog-ready')
  129. run: gh pr merge --auto --merge ${{ github.event.pull_request.number }}
  130. env:
  131. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}