post-merge.yml.disabled 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. name: Post-Merge Automation
  2. on:
  3. push:
  4. branches: [main]
  5. workflow_dispatch:
  6. inputs:
  7. skip_version_bump:
  8. description: 'Skip version bump (maintainer override)'
  9. required: false
  10. type: boolean
  11. default: false
  12. jobs:
  13. check-trigger:
  14. name: Check Trigger Type
  15. runs-on: ubuntu-latest
  16. outputs:
  17. should_bump: ${{ steps.check.outputs.should_bump }}
  18. steps:
  19. - name: Checkout code
  20. uses: actions/checkout@v4
  21. with:
  22. fetch-depth: 2
  23. - name: Determine if version bump needed
  24. id: check
  25. run: |
  26. COMMIT_MSG="${{ github.event.head_commit.message }}"
  27. # Skip version bump commits to prevent loops
  28. if echo "$COMMIT_MSG" | grep -qE "^\[skip ci\]|chore: bump version"; then
  29. echo "should_bump=false" >> $GITHUB_OUTPUT
  30. echo "Version bump commit detected - skipping to prevent loops"
  31. else
  32. echo "should_bump=true" >> $GITHUB_OUTPUT
  33. echo "Will bump version based on commit message: $COMMIT_MSG"
  34. fi
  35. auto-version-bump:
  36. name: Auto Version Bump
  37. runs-on: ubuntu-latest
  38. needs: check-trigger
  39. if: |
  40. needs.check-trigger.outputs.should_bump == 'true' &&
  41. github.event.inputs.skip_version_bump != 'true'
  42. permissions:
  43. contents: write
  44. steps:
  45. - name: Checkout code
  46. uses: actions/checkout@v4
  47. with:
  48. fetch-depth: 0
  49. token: ${{ secrets.GITHUB_TOKEN }}
  50. - name: Setup Node.js
  51. uses: actions/setup-node@v4
  52. with:
  53. node-version: '20'
  54. - name: Configure Git
  55. run: |
  56. git config user.name "github-actions[bot]"
  57. git config user.email "github-actions[bot]@users.noreply.github.com"
  58. - name: Determine version bump type
  59. id: bump-type
  60. run: |
  61. # Get the last commit message
  62. COMMIT_MSG=$(git log -1 --pretty=%B)
  63. # Determine bump type from commit message
  64. if echo "$COMMIT_MSG" | grep -qiE "^(feat|feature)\(.*\)!:|^BREAKING CHANGE:|^[a-z]+!:"; then
  65. echo "type=major" >> $GITHUB_OUTPUT
  66. echo "Detected BREAKING CHANGE - bumping major version"
  67. elif echo "$COMMIT_MSG" | grep -qiE "^(feat|feature)(\(.*\))?:"; then
  68. echo "type=minor" >> $GITHUB_OUTPUT
  69. echo "Detected feature - bumping minor version"
  70. elif echo "$COMMIT_MSG" | grep -qiE "^(fix|bugfix)(\(.*\))?:"; then
  71. echo "type=patch" >> $GITHUB_OUTPUT
  72. echo "Detected fix - bumping patch version"
  73. elif echo "$COMMIT_MSG" | grep -qiE "^\[alpha\]"; then
  74. echo "type=alpha" >> $GITHUB_OUTPUT
  75. echo "Detected [alpha] tag - bumping alpha version"
  76. elif echo "$COMMIT_MSG" | grep -qiE "^\[beta\]"; then
  77. echo "type=beta" >> $GITHUB_OUTPUT
  78. echo "Detected [beta] tag - bumping beta version"
  79. elif echo "$COMMIT_MSG" | grep -qiE "^\[rc\]"; then
  80. echo "type=rc" >> $GITHUB_OUTPUT
  81. echo "Detected [rc] tag - bumping rc version"
  82. else
  83. echo "type=patch" >> $GITHUB_OUTPUT
  84. echo "No specific type detected - defaulting to patch version bump"
  85. fi
  86. - name: Bump version
  87. run: |
  88. BUMP_TYPE="${{ steps.bump-type.outputs.type }}"
  89. # Get current version
  90. CURRENT_VERSION=$(cat VERSION)
  91. echo "Current version: $CURRENT_VERSION"
  92. # Bump version in package.json
  93. npm run version:bump:$BUMP_TYPE
  94. # Get new version
  95. NEW_VERSION=$(cat VERSION)
  96. echo "New version: $NEW_VERSION"
  97. # Update CHANGELOG.md
  98. DATE=$(date +%Y-%m-%d)
  99. # Get only the first line (title) of commit message to avoid multiline issues
  100. COMMIT_TITLE=$(git log -1 --pretty=%s)
  101. # Create changelog entry (use printf to avoid heredoc issues)
  102. printf "## [%s] - %s\n\n### Changes\n- %s\n\n" "$NEW_VERSION" "$DATE" "$COMMIT_TITLE" > /tmp/changelog_entry.md
  103. # Prepend to CHANGELOG.md (after the header)
  104. if [ -f CHANGELOG.md ]; then
  105. # Insert after the first occurrence of "## ["
  106. awk '/^## \[/ && !found {print; system("cat /tmp/changelog_entry.md"); found=1; next} 1' CHANGELOG.md > /tmp/changelog_new.md
  107. mv /tmp/changelog_new.md CHANGELOG.md
  108. fi
  109. - name: Commit version bump
  110. run: |
  111. NEW_VERSION=$(cat VERSION)
  112. git add VERSION package.json CHANGELOG.md
  113. git commit -m "chore: bump version to v$NEW_VERSION [skip ci]"
  114. git tag "v$NEW_VERSION"
  115. - name: Push changes
  116. run: |
  117. git push origin main --tags
  118. env:
  119. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  120. - name: Create GitHub Release
  121. run: |
  122. NEW_VERSION=$(cat VERSION)
  123. # Extract changelog entry for this version
  124. RELEASE_NOTES=$(awk '/^## \['"$NEW_VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
  125. # If no specific notes found, use commit message
  126. if [ -z "$RELEASE_NOTES" ]; then
  127. RELEASE_NOTES="Release v$NEW_VERSION"
  128. fi
  129. # Create the release
  130. gh release create "v$NEW_VERSION" \
  131. --title "v$NEW_VERSION" \
  132. --notes "$RELEASE_NOTES" \
  133. --latest
  134. env:
  135. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  136. - name: Summary
  137. if: success()
  138. run: |
  139. NEW_VERSION=$(cat VERSION)
  140. echo "## 🚀 Version Bumped to v$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
  141. echo "" >> $GITHUB_STEP_SUMMARY
  142. echo "- ✅ Version updated in VERSION and package.json" >> $GITHUB_STEP_SUMMARY
  143. echo "- ✅ CHANGELOG.md updated" >> $GITHUB_STEP_SUMMARY
  144. echo "- ✅ Git tag created: v$NEW_VERSION" >> $GITHUB_STEP_SUMMARY
  145. echo "- ✅ GitHub release published" >> $GITHUB_STEP_SUMMARY