-
Notifications
You must be signed in to change notification settings - Fork 4
108 lines (100 loc) · 4.06 KB
/
bump.yaml
File metadata and controls
108 lines (100 loc) · 4.06 KB
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
name: Bump version
on:
workflow_call:
inputs:
increment:
description: "Force a specific bump (auto|PATCH|MINOR|MAJOR)"
type: string
required: false
default: "auto"
dry_run:
description: "Compute the bump but do not commit/push"
type: boolean
required: false
default: false
outputs:
tag:
description: "Resolved tag (with v prefix) after the bump, or projected tag in dry-run"
value: ${{ jobs.bump.outputs.tag }}
workflow_dispatch:
inputs:
increment:
description: "Force a specific bump"
type: choice
required: false
default: "auto"
options: ["auto", "PATCH", "MINOR", "MAJOR"]
dry_run:
description: "Compute the bump but do not commit/push"
type: boolean
required: false
default: false
jobs:
bump:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.emit.outputs.tag }}
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.COMMITIZEN }}
- name: Install commitizen
run: pip install commitizen --quiet
- name: Detect partial bump
id: detect
run: |
PROJECT_VERSION=$(cz version --project)
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
# Strip v prefix from tag for comparison with project version
LATEST_TAG_NOPREFIX="${LATEST_TAG#v}"
if [ -n "$LATEST_TAG" ] && [ "$LATEST_TAG_NOPREFIX" != "$PROJECT_VERSION" ]; then
echo "partial=true" >> "$GITHUB_OUTPUT"
echo "orphan_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
echo "::warning::Detected orphan tag $LATEST_TAG (project version is $PROJECT_VERSION). Will advance past it."
else
echo "partial=false" >> "$GITHUB_OUTPUT"
fi
- name: Bump version (real)
if: steps.detect.outputs.partial != 'true' && inputs.dry_run == false
uses: commitizen-tools/commitizen-action@0.27.1
with:
github_token: ${{ secrets.COMMITIZEN }}
increment: ${{ inputs.increment != 'auto' && inputs.increment || '' }}
- name: Bump version (dry-run)
if: steps.detect.outputs.partial != 'true' && inputs.dry_run == true
id: dryrun
run: |
ARGS="--dry-run --yes"
if [ "${{ inputs.increment }}" != "auto" ]; then
ARGS="$ARGS --increment ${{ inputs.increment }}"
fi
OUT=$(cz bump $ARGS 2>&1 | tee /dev/stderr)
PROJECTED=$(echo "$OUT" | grep -oE 'tag to create: v?[0-9]+\.[0-9]+\.[0-9]+' | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
if [ -z "$PROJECTED" ]; then
# Fallback parser for older cz versions
PROJECTED=$(echo "$OUT" | grep -oE '\-> [0-9]+\.[0-9]+\.[0-9]+' | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
fi
if [ -z "$PROJECTED" ]; then
echo "::error::Could not parse projected version from 'cz bump --dry-run' output"
exit 1
fi
echo "projected=$PROJECTED" >> "$GITHUB_OUTPUT"
echo "Projected version: $PROJECTED"
- name: Refuse to bump (orphan tag detected)
if: steps.detect.outputs.partial == 'true'
run: |
echo "::error::Orphan tag ${{ steps.detect.outputs.orphan_tag }} exists on the remote but pyproject.toml is at $(cz version --project). Resolve manually: either (a) delete the orphan tag with 'git push --delete origin ${{ steps.detect.outputs.orphan_tag }}' if it was published in error, or (b) hand-bump pyproject.toml + docs/source/changelog.md to match the tag. Then re-run."
exit 1
- name: Emit resulting tag
id: emit
run: |
if [ "${{ inputs.dry_run }}" = "true" ]; then
VERSION="${{ steps.dryrun.outputs.projected }}"
else
VERSION=$(cz version --project)
fi
TAG="v$VERSION"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Resolved tag: $TAG"