|
| 1 | +name: Version Bump on Label |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +jobs: |
| 8 | + bump-version: |
| 9 | + name: Bump Version |
| 10 | + if: startsWith(github.event.label.name, 'bump:') |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 16 | + ref: ${{ github.head_ref }} |
| 17 | + |
| 18 | + - name: Determine bump type |
| 19 | + id: bump_type |
| 20 | + run: | |
| 21 | + LABEL="${{ github.event.label.name }}" |
| 22 | + BUMP_TYPE="${LABEL#bump:}" |
| 23 | + echo "type=$BUMP_TYPE" >> $GITHUB_OUTPUT |
| 24 | +
|
| 25 | + - name: Find plugin.json |
| 26 | + id: find_plugin |
| 27 | + run: | |
| 28 | + # Look for plugin.json in different locations |
| 29 | + if [ -f "plugin/.claude-plugin/plugin.json" ]; then |
| 30 | + echo "path=plugin/.claude-plugin/plugin.json" >> $GITHUB_OUTPUT |
| 31 | + elif [ -f ".claude-plugin/plugin.json" ]; then |
| 32 | + echo "path=.claude-plugin/plugin.json" >> $GITHUB_OUTPUT |
| 33 | + elif [ -f ".cursor-plugin/plugin.json" ]; then |
| 34 | + echo "path=.cursor-plugin/plugin.json" >> $GITHUB_OUTPUT |
| 35 | + else |
| 36 | + echo "Could not find plugin.json" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | +
|
| 40 | + - name: Read current version |
| 41 | + id: current_version |
| 42 | + run: | |
| 43 | + PLUGIN_JSON="${{ steps.find_plugin.outputs.path }}" |
| 44 | + VERSION=$(grep -o '"version": *"[^"]*"' "$PLUGIN_JSON" | head -1 | grep -o '[0-9]*\.[0-9]*\.[0-9]*') |
| 45 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 46 | + echo "Current version: $VERSION" |
| 47 | +
|
| 48 | + - name: Calculate new version |
| 49 | + id: new_version |
| 50 | + run: | |
| 51 | + VERSION="${{ steps.current_version.outputs.version }}" |
| 52 | + BUMP_TYPE="${{ steps.bump_type.outputs.type }}" |
| 53 | +
|
| 54 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 55 | +
|
| 56 | + case "$BUMP_TYPE" in |
| 57 | + major) |
| 58 | + MAJOR=$((MAJOR + 1)) |
| 59 | + MINOR=0 |
| 60 | + PATCH=0 |
| 61 | + ;; |
| 62 | + minor) |
| 63 | + MINOR=$((MINOR + 1)) |
| 64 | + PATCH=0 |
| 65 | + ;; |
| 66 | + patch) |
| 67 | + PATCH=$((PATCH + 1)) |
| 68 | + ;; |
| 69 | + esac |
| 70 | +
|
| 71 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 72 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 73 | + echo "Bumping version: $VERSION → $NEW_VERSION ($BUMP_TYPE)" |
| 74 | +
|
| 75 | + - name: Update version in plugin.json |
| 76 | + run: | |
| 77 | + PLUGIN_JSON="${{ steps.find_plugin.outputs.path }}" |
| 78 | + OLD_VERSION="${{ steps.current_version.outputs.version }}" |
| 79 | + NEW_VERSION="${{ steps.new_version.outputs.version }}" |
| 80 | +
|
| 81 | + sed -i "s/\"version\": *\"$OLD_VERSION\"/\"version\": \"$NEW_VERSION\"/" "$PLUGIN_JSON" |
| 82 | +
|
| 83 | + echo "Updated $PLUGIN_JSON:" |
| 84 | + grep version "$PLUGIN_JSON" |
| 85 | +
|
| 86 | + - name: Commit version bump |
| 87 | + run: | |
| 88 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 89 | + git config --local user.name "github-actions[bot]" |
| 90 | + git add . |
| 91 | + git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }}" |
| 92 | + git push |
0 commit comments