grubble 4.9.4

Automatic semantic versioning based on conventional commits, optimized for AI-generated commit messages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
name: 'Grubble - Semantic Version Bump'
description: 'Automatically bump semantic version based on conventional commits'
author: 'David Garvey'

branding:
  icon: 'arrow-up'
  color: 'orange'

inputs:
  push:
    description: 'Push changes to remote'
    required: false
    default: 'false'
  tag:
    description: 'Create git tag for the version'
    required: false
    default: 'false'
  release-notes:
    description: 'Include release notes in the git tag annotation'
    required: false
    default: 'false'
  raw:
    description: 'Output only the new version string (dry run, no changes)'
    required: false
    default: 'false'
  quiet:
    description: 'Suppress commit list output'
    required: false
    default: 'false'
  preset:
    description: 'Versioning strategy (node, rust, git)'
    required: false
    default: ''
  tag-prefix:
    description: 'Prefix for git tags'
    required: false
    default: ''
  commit-prefix:
    description: 'Prefix for commit messages'
    required: false
    default: ''
  package-files:
    description: 'Comma-separated list of files to update'
    required: false
    default: ''
  git-user-name:
    description: 'Git user name for commits'
    required: false
    default: 'github-actions[bot]'
  git-user-email:
    description: 'Git user email for commits'
    required: false
    default: '41898282+github-actions[bot]@users.noreply.github.com'
  update-major-tag:
    description: 'Update major version tag (e.g., v4 -> v4.x.x)'
    required: false
    default: 'false'
  update-minor-tag:
    description: 'Update minor version tag (e.g., v4.1 -> v4.1.x)'
    required: false
    default: 'false'
  changelog:
    description: 'Generate and maintain a CHANGELOG.md file'
    required: false
    default: 'false'
  dry-run:
    description: 'Check if bump is needed without making changes (exit 0 if bump needed, 1 if not)'
    required: false
    default: 'false'
  bump-type-only:
    description: 'Output only the bump type and exit (major, minor, patch, or none)'
    required: false
    default: 'false'

outputs:
  version:
    description: 'The new version number'
    value: ${{ steps.bump.outputs.version }}
  previous-version:
    description: 'The previous version number'
    value: ${{ steps.bump.outputs.previous_version }}
  bump-type:
    description: 'The type of version bump (major, minor, patch, none)'
    value: ${{ steps.bump.outputs.bump_type }}

runs:
  using: 'composite'
  steps:
    - name: Detect OS and Architecture
      id: detect
      shell: bash
      run: |
        OS="${RUNNER_OS}"
        ARCH="${RUNNER_ARCH}"
        
        if [ "$OS" = "Linux" ]; then
          if [ "$ARCH" = "X64" ]; then
            BINARY="grubble-linux-x86_64"
          elif [ "$ARCH" = "ARM64" ]; then
            BINARY="grubble-linux-aarch64"
          else
            echo "::error::Unsupported architecture: $ARCH"
            exit 1
          fi
          ARCHIVE="${BINARY}.tar.gz"
        elif [ "$OS" = "macOS" ]; then
          if [ "$ARCH" = "X64" ]; then
            BINARY="grubble-macos-x86_64"
          elif [ "$ARCH" = "ARM64" ]; then
            BINARY="grubble-macos-aarch64"
          else
            echo "::error::Unsupported architecture: $ARCH"
            exit 1
          fi
          ARCHIVE="${BINARY}.tar.gz"
        elif [ "$OS" = "Windows" ]; then
          if [ "$ARCH" = "X64" ]; then
            BINARY="grubble-windows-x86_64.exe"
          else
            echo "::error::Unsupported architecture: $ARCH"
            exit 1
          fi
          ARCHIVE="${BINARY}.zip"
        else
          echo "::error::Unsupported operating system: $OS"
          exit 1
        fi
        
        echo "binary=$BINARY" >> $GITHUB_OUTPUT
        echo "archive=$ARCHIVE" >> $GITHUB_OUTPUT
        echo "os=$OS" >> $GITHUB_OUTPUT

    - name: Get latest release
      id: release
      shell: bash
      run: |
        RELEASE_URL="https://api.github.com/repos/davegarvey/grubble/releases/latest"
        RELEASE_DATA=$(curl -sS "$RELEASE_URL")
        VERSION=$(echo "$RELEASE_DATA" | jq -r '.tag_name')
        
        if [ "$VERSION" = "null" ] || [ -z "$VERSION" ]; then
          echo "::error::Failed to fetch latest release version"
          exit 1
        fi
        
        echo "version=$VERSION" >> $GITHUB_OUTPUT
        echo "Using grubble version: $VERSION"

    - name: Download binary
      shell: bash
      run: |
        echo "::group::Download grubble binary"
        DOWNLOAD_URL="https://github.com/davegarvey/grubble/releases/download/${{ steps.release.outputs.version }}/${{ steps.detect.outputs.archive }}"
        
        if ! curl -sSL -f -o "${{ steps.detect.outputs.archive }}" "$DOWNLOAD_URL"; then
          echo "::error::Failed to download binary from $DOWNLOAD_URL"
          exit 1
        fi
        
        echo "Downloaded ${{ steps.detect.outputs.archive }}"
        echo "::endgroup::"

    - name: Verify checksum
      shell: bash
      run: |
        echo "::group::Verify checksum"
        CHECKSUM_URL="https://github.com/davegarvey/grubble/releases/download/${{ steps.release.outputs.version }}/${{ steps.detect.outputs.archive }}.sha256"
        
        if ! curl -sSL -f -o "${{ steps.detect.outputs.archive }}.sha256" "$CHECKSUM_URL"; then
          echo "::warning::Failed to download checksum file, skipping verification"
        else
          if [ "${{ steps.detect.outputs.os }}" = "Windows" ]; then
            # Windows verification
            EXPECTED=$(cat "${{ steps.detect.outputs.archive }}.sha256" | awk '{print $1}')
            ACTUAL=$(certutil -hashfile "${{ steps.detect.outputs.archive }}" SHA256 | findstr /v "hash" | findstr /v "CertUtil")
            if [ "$EXPECTED" != "$ACTUAL" ]; then
              echo "::error::Checksum verification failed"
              exit 1
            fi
          else
            # Unix verification
            if ! shasum -a 256 -c "${{ steps.detect.outputs.archive }}.sha256"; then
              echo "::error::Checksum verification failed"
              exit 1
            fi
          fi
          echo "✓ Checksum verified"
        fi
        echo "::endgroup::"

    - name: Extract binary (Unix)
      if: steps.detect.outputs.os != 'Windows'
      shell: bash
      run: |
        echo "::group::Extract binary"
        tar xzf "${{ steps.detect.outputs.archive }}"
        chmod +x grubble
        echo "✓ Binary ready"
        echo "::endgroup::"

    - name: Extract binary (Windows)
      if: steps.detect.outputs.os == 'Windows'
      shell: pwsh
      run: |
        Write-Output "::group::Extract binary"
        Expand-Archive -Path "${{ steps.detect.outputs.archive }}" -DestinationPath . -Force
        Write-Output "✓ Binary ready"
        Write-Output "::endgroup::"

    - name: Get current version
      id: current
      shell: bash
      run: |
        if [ "${{ inputs.preset }}" = "node" ]; then
          if [ -n "${{ inputs.package-files }}" ]; then
            FIRST_FILE=$(echo "${{ inputs.package-files }}" | cut -d',' -f1)
            # Ensure relative path has ./ prefix for require() resolution
            case "$FIRST_FILE" in
              /*|./*|../*) ;;
              *) FIRST_FILE="./$FIRST_FILE" ;;
            esac
            CURRENT_VERSION=$(node -p "require('$FIRST_FILE').version" 2>/dev/null || echo "0.0.0")
          else
            CURRENT_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0")
          fi
        elif [ "${{ inputs.preset }}" = "rust" ]; then
          if [ -n "${{ inputs.package-files }}" ]; then
            FIRST_FILE=$(echo "${{ inputs.package-files }}" | cut -d',' -f1)
            CURRENT_VERSION=$(grep '^version' "$FIRST_FILE" | head -1 | cut -d'"' -f2 2>/dev/null || echo "0.0.0")
          else
            CURRENT_VERSION=$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2 2>/dev/null || echo "0.0.0")
          fi
        else
          # --raw always prints a version on stdout, but exits 1 (NoBump) when no
          # tag exists yet. Capture stdout regardless of exit code, and only
          # fall back to 0.0.0 when stdout is empty.
          if [ "${{ steps.detect.outputs.os }}" = "Windows" ]; then
            CURRENT_VERSION=$(./grubble.exe --raw 2>/dev/null) || true
          else
            CURRENT_VERSION=$(./grubble --raw 2>/dev/null) || true
          fi
          if [ -z "$CURRENT_VERSION" ]; then
            CURRENT_VERSION="0.0.0"
          fi
        fi
        echo "previous_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT

    - name: Run bump
      id: bump
      shell: bash
      run: |
        ARGS=""

        # Handle bump-type-only mode first
        if [ "${{ inputs.bump-type-only }}" = "true" ]; then
          if [ "${{ steps.detect.outputs.os }}" = "Windows" ]; then
            ./grubble.exe --bump-type
          else
            ./grubble --bump-type
          fi
          echo "bump_type=$(./grubble --bump-type)" >> $GITHUB_OUTPUT
          exit 0
        fi

        # Handle dry-run mode
        if [ "${{ inputs.dry-run }}" = "true" ]; then
          if [ "${{ steps.detect.outputs.os }}" = "Windows" ]; then
            ./grubble.exe --dry-run
          else
            ./grubble --dry-run
          fi
          echo "bump_type=$(./grubble --bump-type)" >> $GITHUB_OUTPUT
          exit 0
        fi

        if [ "${{ inputs.push }}" = "true" ]; then
          ARGS="$ARGS --push"
        fi

        if [ "${{ inputs.tag }}" = "true" ]; then
          ARGS="$ARGS --tag"
        fi

        if [ "${{ inputs.release-notes }}" = "true" ]; then
          ARGS="$ARGS --release-notes"
        fi

        if [ "${{ inputs.raw }}" = "true" ]; then
          ARGS="$ARGS --raw"
        fi

        if [ "${{ inputs.quiet }}" = "true" ]; then
          ARGS="$ARGS --quiet"
        fi

        if [ -n "${{ inputs.preset }}" ]; then
          ARGS="$ARGS --preset ${{ inputs.preset }}"
        fi

        if [ -n "${{ inputs.tag-prefix }}" ]; then
          ARGS="$ARGS --tag-prefix ${{ inputs.tag-prefix }}"
        fi

        if [ -n "${{ inputs.commit-prefix }}" ]; then
          ARGS="$ARGS --commit-prefix \"${{ inputs.commit-prefix }}\""
        fi

        if [ -n "${{ inputs.package-files }}" ]; then
          ARGS="$ARGS --package-files ${{ inputs.package-files }}"
        fi

        if [ -n "${{ inputs.git-user-name }}" ]; then
          ARGS="$ARGS --git-user-name \"${{ inputs.git-user-name }}\""
        fi

        if [ -n "${{ inputs.git-user-email }}" ]; then
          ARGS="$ARGS --git-user-email \"${{ inputs.git-user-email }}\""
        fi

        if [ "${{ inputs.update-major-tag }}" = "true" ]; then
          ARGS="$ARGS --update-major-tag"
        fi

        if [ "${{ inputs.update-minor-tag }}" = "true" ]; then
          ARGS="$ARGS --update-minor-tag"
        fi

        if [ "${{ inputs.changelog }}" = "true" ]; then
          ARGS="$ARGS --changelog"
        fi

        # Run grubble. Exit 1 = "no bump needed" (clean no-op), other non-0 = error.
        set +e
        if [ "${{ steps.detect.outputs.os }}" = "Windows" ]; then
          OUTPUT=$(./grubble.exe $ARGS 2>&1)
          GRUBBLE_EXIT=$?
        else
          OUTPUT=$(./grubble $ARGS 2>&1)
          GRUBBLE_EXIT=$?
        fi
        set -e

        echo "$OUTPUT"

        if [ $GRUBBLE_EXIT -eq 1 ]; then
          # No bump needed — exit cleanly, not an error
          echo "version=${{ steps.current.outputs.previous_version }}" >> $GITHUB_OUTPUT
          echo "bump_type=none" >> $GITHUB_OUTPUT
          echo "previous_version=${{ steps.current.outputs.previous_version }}" >> $GITHUB_OUTPUT
          exit 0
        elif [ $GRUBBLE_EXIT -ne 0 ]; then
          echo "::error::Grubble command failed (exit $GRUBBLE_EXIT): $OUTPUT"
          exit 1
        fi

        # Get the new version — forward config flags so --raw uses the same preset and files.
        # Only version-relevant flags (not action flags like --push/--tag) to keep --raw a pure read.
        READ_ARGS="--raw"
        if [ -n "${{ inputs.preset }}" ]; then
          READ_ARGS="$READ_ARGS --preset ${{ inputs.preset }}"
        fi
        if [ -n "${{ inputs.package-files }}" ]; then
          READ_ARGS="$READ_ARGS --package-files ${{ inputs.package-files }}"
        fi
        if [ -n "${{ inputs.tag-prefix }}" ]; then
          READ_ARGS="$READ_ARGS --tag-prefix ${{ inputs.tag-prefix }}"
        fi
        if [ -n "${{ inputs.commit-prefix }}" ]; then
          READ_ARGS="$READ_ARGS --commit-prefix \"${{ inputs.commit-prefix }}\""
        fi
        # --raw always prints a version on stdout, but exits 1 (NoBump) when no
        # further bump is needed post-commit. Capture stdout regardless of exit
        # code, and only fall back to the previous version when stdout is empty
        # (i.e. a true error such as the binary being missing).
        if [ "${{ steps.detect.outputs.os }}" = "Windows" ]; then
          NEW_VERSION=$(./grubble.exe $READ_ARGS 2>/dev/null) || true
        else
          NEW_VERSION=$(./grubble $READ_ARGS 2>/dev/null) || true
        fi
        if [ -z "$NEW_VERSION" ]; then
          NEW_VERSION="${{ steps.current.outputs.previous_version }}"
        fi

        echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT

        # Determine bump type
        PREV="${{ steps.current.outputs.previous_version }}"
        if [ "$NEW_VERSION" != "$PREV" ]; then
          PREV_MAJOR=$(echo $PREV | cut -d. -f1)
          PREV_MINOR=$(echo $PREV | cut -d. -f2)
          PREV_PATCH=$(echo $PREV | cut -d. -f3)

          NEW_MAJOR=$(echo $NEW_VERSION | cut -d. -f1)
          NEW_MINOR=$(echo $NEW_VERSION | cut -d. -f2)
          NEW_PATCH=$(echo $NEW_VERSION | cut -d. -f3)

          if [ "$NEW_MAJOR" != "$PREV_MAJOR" ]; then
            echo "bump_type=major" >> $GITHUB_OUTPUT
          elif [ "$NEW_MINOR" != "$PREV_MINOR" ]; then
            echo "bump_type=minor" >> $GITHUB_OUTPUT
          elif [ "$NEW_PATCH" != "$PREV_PATCH" ]; then
            echo "bump_type=patch" >> $GITHUB_OUTPUT
          else
            echo "bump_type=none" >> $GITHUB_OUTPUT
          fi
        else
          echo "bump_type=none" >> $GITHUB_OUTPUT
        fi

        echo "previous_version=$PREV" >> $GITHUB_OUTPUT