|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Version bump type' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - patch |
| 12 | + - minor |
| 13 | + - major |
| 14 | + |
| 15 | +jobs: |
| 16 | + create-release-pr: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + # Ensure this workflow only runs from the main branch |
| 22 | + if: github.ref == 'refs/heads/main' |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Setup Node.js |
| 31 | + uses: actions/setup-node@v4 |
| 32 | + with: |
| 33 | + node-version: '20' |
| 34 | + cache: 'yarn' |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: yarn install --frozen-lockfile |
| 38 | + |
| 39 | + - name: Configure git |
| 40 | + run: | |
| 41 | + git config user.name "github-actions[bot]" |
| 42 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 43 | +
|
| 44 | + - name: Get current version |
| 45 | + id: current_version |
| 46 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 47 | + |
| 48 | + - name: Bump version |
| 49 | + id: bump_version |
| 50 | + run: | |
| 51 | + yarn version --${{ github.event.inputs.version }} --no-git-tag-version |
| 52 | + NEW_VERSION=$(node -p "require('./package.json').version") |
| 53 | + echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 54 | + echo "Bumped version from ${{ steps.current_version.outputs.version }} to $NEW_VERSION" |
| 55 | +
|
| 56 | + - name: Generate changelog |
| 57 | + id: changelog |
| 58 | + run: | |
| 59 | + # Get the latest tag |
| 60 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 61 | +
|
| 62 | + if [ -z "$LATEST_TAG" ]; then |
| 63 | + echo "No previous tag found, generating changelog from first commit" |
| 64 | + COMMIT_RANGE=$(git rev-list --max-parents=0 HEAD)..HEAD |
| 65 | + else |
| 66 | + echo "Latest tag: $LATEST_TAG" |
| 67 | + COMMIT_RANGE=$LATEST_TAG..HEAD |
| 68 | + fi |
| 69 | +
|
| 70 | + # Generate changelog |
| 71 | + CHANGELOG=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --no-merges) |
| 72 | +
|
| 73 | + # Save to file for PR body |
| 74 | + cat > /tmp/changelog.md <<EOF |
| 75 | + ## Changes in v${{ steps.bump_version.outputs.new_version }} |
| 76 | +
|
| 77 | + $CHANGELOG |
| 78 | + EOF |
| 79 | +
|
| 80 | + # Output for use in PR |
| 81 | + echo "changelog<<EOF" >> $GITHUB_OUTPUT |
| 82 | + cat /tmp/changelog.md >> $GITHUB_OUTPUT |
| 83 | + echo "EOF" >> $GITHUB_OUTPUT |
| 84 | +
|
| 85 | + - name: Update CHANGELOG.md |
| 86 | + run: | |
| 87 | + # Create or update CHANGELOG.md |
| 88 | + if [ ! -f CHANGELOG.md ]; then |
| 89 | + echo "# Changelog" > CHANGELOG.md |
| 90 | + echo "" >> CHANGELOG.md |
| 91 | + echo "All notable changes to this project will be documented in this file." >> CHANGELOG.md |
| 92 | + echo "" >> CHANGELOG.md |
| 93 | + fi |
| 94 | +
|
| 95 | + # Prepare new entry |
| 96 | + cat > /tmp/new_entry.md <<EOF |
| 97 | + ## [v${{ steps.bump_version.outputs.new_version }}] - $(date +%Y-%m-%d) |
| 98 | +
|
| 99 | + EOF |
| 100 | +
|
| 101 | + cat /tmp/changelog.md | tail -n +3 >> /tmp/new_entry.md |
| 102 | + echo "" >> /tmp/new_entry.md |
| 103 | +
|
| 104 | + # Insert after the header |
| 105 | + sed -i '1,/^All notable/r /tmp/new_entry.md' CHANGELOG.md || { |
| 106 | + # If sed fails (no header found), just prepend |
| 107 | + cat /tmp/new_entry.md CHANGELOG.md > /tmp/new_changelog.md |
| 108 | + mv /tmp/new_changelog.md CHANGELOG.md |
| 109 | + } |
| 110 | +
|
| 111 | + - name: Create Pull Request |
| 112 | + uses: peter-evans/create-pull-request@v6 |
| 113 | + with: |
| 114 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + branch: release/v${{ steps.bump_version.outputs.new_version }} |
| 116 | + commit-message: "chore: bump version to v${{ steps.bump_version.outputs.new_version }}" |
| 117 | + title: "Release v${{ steps.bump_version.outputs.new_version }}" |
| 118 | + body: | |
| 119 | + ## Release v${{ steps.bump_version.outputs.new_version }} |
| 120 | +
|
| 121 | + This PR bumps the version from **v${{ steps.current_version.outputs.version }}** to **v${{ steps.bump_version.outputs.new_version }}**. |
| 122 | +
|
| 123 | + ${{ steps.changelog.outputs.changelog }} |
| 124 | +
|
| 125 | + --- |
| 126 | +
|
| 127 | + ### Release Checklist |
| 128 | + - [ ] Review changelog and version bump |
| 129 | + - [ ] Merge this PR to main |
| 130 | + - [ ] Create a GitHub release from main with tag `v${{ steps.bump_version.outputs.new_version }}` |
| 131 | + - [ ] Run `yarn build` locally |
| 132 | + - [ ] Run `npm publish` to publish to npm registry |
| 133 | +
|
| 134 | + --- |
| 135 | + *This PR was automatically generated by the release workflow* |
| 136 | + labels: | |
| 137 | + release |
| 138 | + automated |
0 commit comments