-
Notifications
You must be signed in to change notification settings - Fork 2
128 lines (119 loc) · 5.02 KB
/
bump-version.yml
File metadata and controls
128 lines (119 loc) · 5.02 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Bump Version
on:
workflow_dispatch:
inputs:
bump_type:
description: 'Semver component to increment (ignored when version is set)'
required: true
type: choice
default: patch
options:
- major
- minor
- patch
version:
description: 'Explicit version override (semver, e.g. 5.8.0). Leave blank to auto-increment.'
required: false
type: string
concurrency:
group: bump-version
cancel-in-progress: false
permissions:
contents: write
pull-requests: write
jobs:
bump:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve target version
id: resolve
env:
INPUT_VERSION: ${{ inputs.version }}
INPUT_BUMP_TYPE: ${{ inputs.bump_type }}
run: |
explicit="$INPUT_VERSION"
if [[ -n "$explicit" ]]; then
if ! [[ "$explicit" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: '$explicit' is not valid semver (e.g. 5.8.0)" >&2
exit 1
fi
printf 'version=%s\n' "$explicit" >> "$GITHUB_OUTPUT"
echo "Resolved version: $explicit (explicit override)"
else
primary=".claude-plugin/plugin.json"
current=$(grep '"version"' "$primary" | head -1 | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([0-9.]*\)".*/\1/p')
if [[ -z "$current" || "$current" == "null" ]]; then
echo "ERROR: Could not detect current version from $primary" >&2
exit 1
fi
if ! [[ "$current" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: Current version '$current' is not valid semver; use an explicit version override." >&2
exit 1
fi
IFS='.' read -r major minor patch <<< "$current"
case "$INPUT_BUMP_TYPE" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
*) echo "ERROR: Unknown bump_type '$INPUT_BUMP_TYPE'" >&2; exit 1 ;;
esac
new_version="${major}.${minor}.${patch}"
printf 'version=%s\n' "$new_version" >> "$GITHUB_OUTPUT"
echo "Resolved version: $new_version (auto $INPUT_BUMP_TYPE bump from $current)"
fi
- name: Bump version in all manifests
env:
TARGET_VERSION: ${{ steps.resolve.outputs.version }}
run: bash scripts/bump-version.sh "$TARGET_VERSION"
- name: Verify version consistency
run: bash tests/version-check.sh
- name: Create branch, commit, and push
id: branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_VERSION: ${{ steps.resolve.outputs.version }}
run: |
branch="chore/bump-version-${TARGET_VERSION}"
# Check early for an existing open PR to avoid redundant work
existing=$(gh pr list --head "$branch" --base main --state open --json number --jq '.[0].number // empty' || true)
if [[ -n "$existing" ]]; then
echo "PR #$existing already open for $branch; skipping."
echo "branch=" >> "$GITHUB_OUTPUT"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -u
if git diff --cached --quiet; then
echo "Nothing to commit – version files already at ${TARGET_VERSION}."
echo "branch=" >> "$GITHUB_OUTPUT"
exit 0
fi
git checkout -b "$branch"
git commit -m "chore: bump version to ${TARGET_VERSION}"
# Use --force-with-lease to handle the case where the remote branch already
# exists from a previous interrupted run (safe because we just diverged from main)
git push --force-with-lease -u origin "$branch"
echo "branch=$branch" >> "$GITHUB_OUTPUT"
- name: Open pull request
if: steps.branch.outputs.branch != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_VERSION: ${{ steps.resolve.outputs.version }}
BRANCH: ${{ steps.branch.outputs.branch }}
run: |
existing=$(gh pr list --head "$BRANCH" --base main --state open --json number --jq '.[0].number // empty' || true)
if [[ -n "$existing" ]]; then
echo "PR already open for $BRANCH (#$existing); skipping creation."
exit 0
fi
body=$(printf 'Automated version bump to `%s`.\n\nWhen this PR merges, the `Release Tag` workflow will create tag `v%s` and dispatch the `autodev-version-bump` event to `GoCodeAlone/autodev-marketplace`.\n' "$TARGET_VERSION" "$TARGET_VERSION")
gh pr create \
--base main \
--head "$BRANCH" \
--title "chore: bump version to ${TARGET_VERSION}" \
--body "$body"