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