changeset-converter.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. name: Changeset Converter
  2. run-name: Changeset Conversion
  3. on:
  4. workflow_dispatch:
  5. pull_request:
  6. types: [closed]
  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 == 'workflow_dispatch' ||
  16. (
  17. github.event_name == 'pull_request' &&
  18. github.event.pull_request.merged == true &&
  19. github.event.pull_request.base.ref == 'main' &&
  20. github.actor != 'github-actions'
  21. )
  22. runs-on: ubuntu-latest
  23. permissions:
  24. contents: write
  25. pull-requests: write
  26. steps:
  27. - name: Check user for team affiliation
  28. id: team_check
  29. if: github.event_name == 'workflow_dispatch'
  30. uses: morfien101/actions-authorized-user@4a3cfbf0bcb3cafe4a71710a278920c5d94bb38b
  31. with:
  32. username: ${{ github.actor }}
  33. org: ${{ github.repository_owner }}
  34. team: "deployer"
  35. github_token: ${{ secrets.GITHUB_TOKEN }}
  36. - name: Check if user is authorized
  37. if: github.event_name == 'workflow_dispatch'
  38. run: |
  39. if [ "${{ steps.team_check.outputs.authorized }}" != "true" ]; then
  40. echo "User is not authorized to run this workflow."
  41. exit 1
  42. fi
  43. - name: Git Checkout
  44. uses: actions/checkout@v4
  45. with:
  46. fetch-depth: 0
  47. ref: ${{ env.GIT_REF }}
  48. - name: Setup Node.js
  49. uses: actions/setup-node@v4
  50. with:
  51. node-version: ${{ env.NODE_VERSION }}
  52. cache: "npm"
  53. - name: Install Dependencies
  54. run: npm ci
  55. # Check if there are any new changesets to process
  56. - name: Check for changesets
  57. id: check-changesets
  58. run: |
  59. NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ')
  60. echo "Changesets diff with previous version: $NEW_CHANGESETS"
  61. echo "new_changesets=$NEW_CHANGESETS" >> $GITHUB_OUTPUT
  62. # Create version bump PR using changesets/action if there are new changesets
  63. - name: Create Changeset Pull Request
  64. if: steps.check-changesets.outputs.new_changesets != '0'
  65. uses: changesets/action@v1
  66. with:
  67. commit: "changeset version bump"
  68. title: "Changeset version bump"
  69. version: npm run version-packages # This performs the changeset version bump
  70. env:
  71. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  72. # Get current and previous versions to edit changelog entry
  73. - name: Get version
  74. id: get_version
  75. run: |
  76. VERSION=$(git show HEAD:package.json | jq -r '.version')
  77. echo "version=$VERSION" >> $GITHUB_OUTPUT
  78. PREV_VERSION=$(git show origin/main:package.json | jq -r '.version')
  79. echo "prev_version=$PREV_VERSION" >> $GITHUB_OUTPUT
  80. echo "version=$VERSION"
  81. echo "prev_version=$PREV_VERSION"
  82. # Update CHANGELOG.md with proper format
  83. - name: Update Changelog Format
  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 to Pull Request
  90. run: |
  91. git config user.name "github-actions"
  92. git config user.email [email protected]
  93. echo "Running git add and commit..."
  94. git add CHANGELOG.md
  95. git commit -m "Updating CHANGELOG.md format"
  96. git status
  97. echo "--------------------------------------------------------------------------------"
  98. echo "Pushing to remote..."
  99. echo "--------------------------------------------------------------------------------"
  100. CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
  101. git push origin $CURRENT_BRANCH