|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths-ignore: |
| 7 | + - ".github/**" |
| 8 | + - "docs/**" |
| 9 | + - "*.md" |
| 10 | + - "LICENSE" |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: release |
| 17 | + cancel-in-progress: false |
| 18 | + |
| 19 | +jobs: |
| 20 | + version-and-release: |
| 21 | + name: Bump version, tag, and release |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: "!contains(github.event.head_commit.message, '[skip ci]')" |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Get current version |
| 30 | + id: current |
| 31 | + run: | |
| 32 | + version=$(python3 -c "import json; print(json.load(open('.cursor-plugin/plugin.json'))['version'])") |
| 33 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + - name: Determine bump type from commits |
| 36 | + id: bump |
| 37 | + run: | |
| 38 | + last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 39 | + if [ -z "$last_tag" ]; then |
| 40 | + commits=$(git log --oneline --format="%s") |
| 41 | + else |
| 42 | + commits=$(git log "$last_tag"..HEAD --oneline --format="%s") |
| 43 | + fi |
| 44 | +
|
| 45 | + bump="patch" |
| 46 | + if echo "$commits" | grep -qiE "^(feat|feature)(\(.+\))?!:|BREAKING CHANGE"; then |
| 47 | + bump="major" |
| 48 | + elif echo "$commits" | grep -qiE "^(feat|feature)(\(.+\))?:"; then |
| 49 | + bump="minor" |
| 50 | + fi |
| 51 | +
|
| 52 | + echo "bump=$bump" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + - name: Compute new version |
| 55 | + id: new |
| 56 | + run: | |
| 57 | + current="${{ steps.current.outputs.version }}" |
| 58 | + bump="${{ steps.bump.outputs.bump }}" |
| 59 | + IFS='.' read -r major minor patch <<< "$current" |
| 60 | + case "$bump" in |
| 61 | + major) major=$((major + 1)); minor=0; patch=0 ;; |
| 62 | + minor) minor=$((minor + 1)); patch=0 ;; |
| 63 | + patch) patch=$((patch + 1)) ;; |
| 64 | + esac |
| 65 | + echo "version=$major.$minor.$patch" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Check if version changed |
| 68 | + id: check |
| 69 | + run: | |
| 70 | + if [ "${{ steps.current.outputs.version }}" = "${{ steps.new.outputs.version }}" ]; then |
| 71 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 72 | + else |
| 73 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Update version files |
| 77 | + if: steps.check.outputs.skip == 'false' |
| 78 | + env: |
| 79 | + NEW_VERSION: ${{ steps.new.outputs.version }} |
| 80 | + OLD_VERSION: ${{ steps.current.outputs.version }} |
| 81 | + run: | |
| 82 | + python3 -c " |
| 83 | + import json, os |
| 84 | +
|
| 85 | + new_version = os.environ['NEW_VERSION'] |
| 86 | + old_version = os.environ['OLD_VERSION'] |
| 87 | +
|
| 88 | + path = '.cursor-plugin/plugin.json' |
| 89 | + with open(path) as f: |
| 90 | + data = json.load(f) |
| 91 | + data['version'] = new_version |
| 92 | + with open(path, 'w') as f: |
| 93 | + json.dump(data, f, indent=2) |
| 94 | + f.write('\n') |
| 95 | +
|
| 96 | + readme = 'README.md' |
| 97 | + with open(readme) as f: |
| 98 | + content = f.read() |
| 99 | + content = content.replace( |
| 100 | + f'version-{old_version}-', |
| 101 | + f'version-{new_version}-' |
| 102 | + ) |
| 103 | + with open(readme, 'w') as f: |
| 104 | + f.write(content) |
| 105 | + " |
| 106 | +
|
| 107 | + - name: Commit and tag |
| 108 | + if: steps.check.outputs.skip == 'false' |
| 109 | + run: | |
| 110 | + git config user.name "github-actions[bot]" |
| 111 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 112 | + git add -A |
| 113 | + git commit -m "chore: bump version to ${{ steps.new.outputs.version }} [skip ci]" |
| 114 | + git tag "v${{ steps.new.outputs.version }}" |
| 115 | + git push origin main --tags |
| 116 | +
|
| 117 | + - name: Create GitHub Release |
| 118 | + if: steps.check.outputs.skip == 'false' |
| 119 | + env: |
| 120 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 121 | + run: | |
| 122 | + gh release create "v${{ steps.new.outputs.version }}" \ |
| 123 | + --title "v${{ steps.new.outputs.version }}" \ |
| 124 | + --generate-notes |
0 commit comments