changeset-release.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. name: Changeset Release
  2. run-name: Changeset Release ${{ github.actor != 'R00-B0T' && '- Create PR' || '- Update Changelog' }}
  3. on:
  4. pull_request:
  5. types: [closed, opened, 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. # Get current and previous versions to edit changelog entry
  72. - name: Get version
  73. id: get_version
  74. run: |
  75. VERSION=$(git show HEAD:package.json | jq -r '.version')
  76. echo "version=$VERSION" >> $GITHUB_OUTPUT
  77. PREV_VERSION=$(git show origin/main:package.json | jq -r '.version')
  78. echo "prev_version=$PREV_VERSION" >> $GITHUB_OUTPUT
  79. echo "version=$VERSION"
  80. echo "prev_version=$PREV_VERSION"
  81. # Update CHANGELOG.md with proper format
  82. - name: Update Changelog Format
  83. if: ${{ !contains(github.event.pull_request.labels.*.name, 'changelog-ready') }}
  84. env:
  85. VERSION: ${{ steps.get_version.outputs.version }}
  86. PREV_VERSION: ${{ steps.get_version.outputs.prev_version }}
  87. run: python .github/scripts/overwrite_changeset_changelog.py
  88. # Commit and push changelog updates
  89. - name: Push Changelog updates
  90. if: ${{ !contains(github.event.pull_request.labels.*.name, 'changelog-ready') }}
  91. run: |
  92. git config user.name "R00-B0T"
  93. git config user.email [email protected]
  94. git status
  95. echo "Running git add and commit..."
  96. git add CHANGELOG.md
  97. git commit -m "Updating CHANGELOG.md format"
  98. echo "--------------------------------------------------------------------------------"
  99. echo "Pushing to remote..."
  100. echo "--------------------------------------------------------------------------------"
  101. git push
  102. # Add label to indicate changelog has been formatted
  103. - name: Add changelog-ready label
  104. if: ${{ !contains(github.event.pull_request.labels.*.name, 'changelog-ready') }}
  105. uses: actions/github-script@v7
  106. with:
  107. github-token: ${{ secrets.GITHUB_TOKEN }}
  108. script: |
  109. await github.rest.issues.addLabels({
  110. owner: context.repo.owner,
  111. repo: context.repo.repo,
  112. issue_number: context.issue.number,
  113. labels: ['changelog-ready']
  114. });
  115. # Auto-approve PR only after it has been labeled
  116. - name: Auto approve PR
  117. if: contains(github.event.pull_request.labels.*.name, 'changelog-ready')
  118. uses: hmarr/auto-approve-action@v4
  119. with:
  120. review-message: "I'm approving since it's a bump version PR"
  121. # Auto-merge PR
  122. - name: Automerge on PR
  123. if: false # Needs enablePullRequestAutoMerge in repo settings to work contains(github.event.pull_request.labels.*.name, 'changelog-ready')
  124. run: gh pr merge --auto --merge ${{ github.event.pull_request.number }}
  125. env:
  126. GH_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }}