changeset-release.yml 5.0 KB

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