changeset-release.yml 5.1 KB

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