changeset-release.yml 6.1 KB

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