|
| 1 | +name: Changeset Release |
| 2 | +run-name: Changeset Release ${{ github.actor != 'R00-B0T' && '- Create PR' || '- Approve & Merge' }} |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + types: [closed, opened, synchronize, labeled] |
| 7 | + |
| 8 | +env: |
| 9 | + REPO_PATH: ${{ github.repository }} |
| 10 | + GIT_REF: ${{ github.event.pull_request.head.sha }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + # Job 1: Create version bump PR when changesets are merged to main |
| 14 | + changeset-pr-version-bump: |
| 15 | + if: > |
| 16 | + github.event_name == 'pull_request' && |
| 17 | + github.event.pull_request.merged == true && |
| 18 | + github.event.pull_request.base.ref == 'main' && |
| 19 | + github.actor != 'R00-B0T' |
| 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 | + |
| 31 | + - name: Setup Node.js |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: 20 |
| 35 | + cache: 'npm' |
| 36 | + |
| 37 | + - name: Install Dependencies |
| 38 | + run: npm install |
| 39 | + |
| 40 | + # Check if there are any new changesets to process |
| 41 | + - name: Check for changesets |
| 42 | + id: check-changesets |
| 43 | + run: | |
| 44 | + NEW_CHANGESETS=$(find .changeset -name "*.md" ! -name "README.md" | wc -l | tr -d ' ') |
| 45 | + echo "Changesets diff with previous version: $NEW_CHANGESETS" |
| 46 | + echo "new_changesets=$NEW_CHANGESETS" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + # Create version bump PR using changesets/action if there are new changesets |
| 49 | + - name: Changeset Pull Request |
| 50 | + if: steps.check-changesets.outputs.new_changesets != '0' |
| 51 | + id: changesets |
| 52 | + uses: changesets/action@v1 |
| 53 | + with: |
| 54 | + commit: "changeset version bump" |
| 55 | + title: "Changeset version bump" |
| 56 | + version: npm run version-packages # This performs the changeset version bump |
| 57 | + env: |
| 58 | + GITHUB_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }} |
| 59 | + |
| 60 | + # Job 2: Process version bump PR created by R00-B0T |
| 61 | + changeset-pr-approve-merge: |
| 62 | + name: Auto approve and merge Bump version PRs |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: write |
| 66 | + pull-requests: write |
| 67 | + if: > |
| 68 | + github.event_name == 'pull_request' && |
| 69 | + github.event.pull_request.base.ref == 'main' && |
| 70 | + github.actor == 'R00-B0T' && |
| 71 | + contains(github.event.pull_request.title, 'Changeset version bump') |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Checkout Repo |
| 75 | + uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + token: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }} |
| 78 | + fetch-depth: 0 |
| 79 | + ref: ${{ env.GIT_REF }} |
| 80 | + |
| 81 | + # Auto-approve PR |
| 82 | + - name: Auto approve PR |
| 83 | + uses: hmarr/auto-approve-action@v4 |
| 84 | + with: |
| 85 | + review-message: "I'm approving since it's a bump version PR" |
| 86 | + |
| 87 | + # Enable auto-merge for the PR |
| 88 | + - name: Enable automerge on PR |
| 89 | + run: gh pr merge --squash --auto ${{ github.event.pull_request.number }} |
| 90 | + env: |
| 91 | + GH_TOKEN: ${{ secrets.CROSS_REPO_ACCESS_TOKEN }} |
0 commit comments