|
| 1 | +name: auto-release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths-ignore: |
| 8 | + - "**.md" |
| 9 | + - "website/**" |
| 10 | + - "docs/**" |
| 11 | + - ".github/**" |
| 12 | + - "!.github/workflows/**" |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }} |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +jobs: |
| 19 | + auto-release: |
| 20 | + name: Auto Release |
| 21 | + runs-on: ubuntu-latest |
| 22 | + if: "!contains(github.event.head_commit.message, 'release:')" |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + pull-requests: read |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Setup Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: 22.x |
| 37 | + |
| 38 | + - name: Configure Git |
| 39 | + run: | |
| 40 | + git config --global user.name "github-actions[bot]" |
| 41 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 42 | +
|
| 43 | + - name: Get latest release |
| 44 | + id: latest_release |
| 45 | + run: | |
| 46 | + # Get the latest release tag, fallback to v0.0.0 if none exists |
| 47 | + latest_tag=$(git tag --sort=-version:refname | head -n1 || echo "v0.0.0") |
| 48 | + echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT |
| 49 | + echo "Latest release tag: $latest_tag" |
| 50 | +
|
| 51 | + - name: Get commits since last release |
| 52 | + id: commits |
| 53 | + run: | |
| 54 | + latest_tag="${{ steps.latest_release.outputs.latest_tag }}" |
| 55 | + if [ "$latest_tag" = "v0.0.0" ]; then |
| 56 | + # If no previous release, get all commits |
| 57 | + commits=$(git log --oneline --pretty=format:"%s" | head -10) |
| 58 | + else |
| 59 | + # Get commits since last release |
| 60 | + commits=$(git log ${latest_tag}..HEAD --oneline --pretty=format:"%s") |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "Commits since $latest_tag:" |
| 64 | + echo "$commits" |
| 65 | +
|
| 66 | + # Check if there are any commits to release |
| 67 | + if [ -z "$commits" ]; then |
| 68 | + echo "No new commits to release" |
| 69 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 70 | + exit 0 |
| 71 | + fi |
| 72 | +
|
| 73 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 74 | +
|
| 75 | + - name: Determine version bump type |
| 76 | + id: bump_type |
| 77 | + if: steps.commits.outputs.should_release == 'true' |
| 78 | + run: | |
| 79 | + latest_tag="${{ steps.latest_release.outputs.latest_tag }}" |
| 80 | + commits=$(git log ${latest_tag}..HEAD --oneline --pretty=format:"%s" || git log --oneline --pretty=format:"%s" | head -10) |
| 81 | +
|
| 82 | + # Default to patch |
| 83 | + bump_type="patch" |
| 84 | +
|
| 85 | + # Check for breaking changes (major) |
| 86 | + if echo "$commits" | grep -qE "^[^:]+!:|BREAKING CHANGE"; then |
| 87 | + bump_type="major" |
| 88 | + # Check for features (minor) |
| 89 | + elif echo "$commits" | grep -qE "^feat(\(.+\))?:"; then |
| 90 | + bump_type="minor" |
| 91 | + # Check for fixes and other changes (patch) |
| 92 | + elif echo "$commits" | grep -qE "^(fix|perf|refactor|style|docs|test|build|ci|chore)(\(.+\))?:"; then |
| 93 | + bump_type="patch" |
| 94 | + fi |
| 95 | +
|
| 96 | + echo "Determined bump type: $bump_type" |
| 97 | + echo "bump_type=$bump_type" >> $GITHUB_OUTPUT |
| 98 | +
|
| 99 | + - name: Bump version |
| 100 | + id: version_bump |
| 101 | + if: steps.commits.outputs.should_release == 'true' |
| 102 | + run: | |
| 103 | + bump_type="${{ steps.bump_type.outputs.bump_type }}" |
| 104 | +
|
| 105 | + # Get current version from package.json |
| 106 | + current_version=$(node -p "require('./package.json').version") |
| 107 | + echo "Current version: $current_version" |
| 108 | +
|
| 109 | + # Bump version using npm |
| 110 | + npm version $bump_type --no-git-tag-version |
| 111 | +
|
| 112 | + # Get new version |
| 113 | + new_version=$(node -p "require('./package.json').version") |
| 114 | + echo "New version: $new_version" |
| 115 | + echo "new_version=$new_version" >> $GITHUB_OUTPUT |
| 116 | +
|
| 117 | + - name: Commit version bump and create tag |
| 118 | + if: steps.commits.outputs.should_release == 'true' |
| 119 | + run: | |
| 120 | + new_version="${{ steps.version_bump.outputs.new_version }}" |
| 121 | +
|
| 122 | + # Commit the version bump |
| 123 | + git add package.json |
| 124 | + git commit -m "release: $new_version" |
| 125 | +
|
| 126 | + # Create and push tag |
| 127 | + git tag "v$new_version" |
| 128 | + git push origin main |
| 129 | + git push origin "v$new_version" |
| 130 | +
|
| 131 | + echo "Created and pushed tag v$new_version" |
| 132 | +
|
| 133 | + - name: Summary |
| 134 | + run: | |
| 135 | + if [ "${{ steps.commits.outputs.should_release }}" = "true" ]; then |
| 136 | + echo "✅ Auto-release completed!" |
| 137 | + echo "New version: ${{ steps.version_bump.outputs.new_version }}" |
| 138 | + echo "Tag created: v${{ steps.version_bump.outputs.new_version }}" |
| 139 | + echo "" |
| 140 | + echo "The check and release workflows will now run automatically." |
| 141 | + else |
| 142 | + echo "ℹ️ No new commits to release - skipping auto-release" |
| 143 | + fi |
0 commit comments