Skip to content

Commit 88ee3f5

Browse files
authored
ci: adding a release prep github workflow (#309)
1 parent c35ef13 commit 88ee3f5

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

.github/workflows/prep-release.yml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
name: Prep release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version_bump:
7+
type: choice
8+
description: "Type of version bump"
9+
default: patch
10+
required: true
11+
options:
12+
- major
13+
- minor
14+
- patch
15+
- custom
16+
custom_version:
17+
type: string
18+
required: false
19+
description: "Custom version (ignore for other bump types)"
20+
generate_pre_release:
21+
type: boolean
22+
default: true
23+
required: true
24+
description: "Generate a RC build"
25+
26+
permissions:
27+
contents: write
28+
pull-requests: write
29+
30+
concurrency:
31+
group: pre-release
32+
cancel-in-progress: false
33+
34+
jobs:
35+
validate:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Enforce custom_version when bump=custom
39+
run: |
40+
if [[ "${{ inputs.version_bump }}" == "custom" ]]; then
41+
if [[ -z "${{ inputs.custom_version }}" ]]; then
42+
echo "::error title=Missing input::Set 'custom_version' when version_bump=custom"; exit 1
43+
fi
44+
if [[ ! "${{ inputs.custom_version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
45+
echo "::error title=Invalid SemVer::Use x.y.z (can use optional pre-release/build identifiers)"; exit 1
46+
fi
47+
fi
48+
prep-release:
49+
runs-on: ubuntu-latest
50+
51+
env:
52+
GH_TOKEN: ${{ secrets.GH_PAT }}
53+
54+
steps:
55+
- uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
59+
- name: Configure git author
60+
run: |
61+
git config --local user.name "Apollo Bot"
62+
git config --local user.email "[email protected]"
63+
64+
- name: Retrieve current version from Cargo.toml
65+
id: meta
66+
run: |
67+
set -eu
68+
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -er --arg NAME "apollo-mcp-server" '.packages[] | select(.name == $NAME) | .version')
69+
[ -n "$VERSION" ] || { echo "::error::Could not determine version"; exit 1; }
70+
echo "current_version=$VERSION" >> "$GITHUB_OUTPUT"
71+
72+
- name: Bump the version
73+
id: bump
74+
shell: bash
75+
env:
76+
CURR: ${{ steps.meta.outputs.current_version }}
77+
CUSTOM: ${{ inputs.custom_version }}
78+
BUMP: ${{ inputs.bump }}
79+
run: |
80+
set -euo pipefail
81+
82+
if [[ -n "${CUSTOM:-}" ]]; then then
83+
# strip any pre-release / build metadata for arithmetic (e.g., -rc.1, +build.5)
84+
BASE="${CURR%%[-+]*}"
85+
86+
IFS=. read -r MA MI PA <<< "$BASE"
87+
88+
case "$BUMP" in
89+
major) MA=$((MA+1)); MI=0; PA=0 ;;
90+
minor) MI=$((MI+1)); PA=0 ;;
91+
patch) PA=$((PA+1)) ;;
92+
*) echo "::error::Unknown bump '$BUMP'"; exit 1 ;;
93+
esac
94+
95+
NEW_VERSION="$MA.$MI.$PA"
96+
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
97+
echo "Bumped: $CURR -> $NEW_VERSION"
98+
else
99+
echo "new_version=$CUSTOM" >> "$GITHUB_OUTPUT"
100+
echo "Bumped: $CURR -> $CUSTOM"
101+
fi
102+
103+
- name: Prepare release branch
104+
id: prep_branch
105+
run: |
106+
set -e
107+
git fetch origin develop
108+
git switch -c "release/${{ steps.bump.outputs.new_version }}" "origin/develop"
109+
echo "release_branch=release/${{ steps.bump.outputs.new_version }}" >> "$GITHUB_OUTPUT"
110+
111+
- name: Update Cargo version
112+
run: |
113+
cargo install cargo-edit --locked
114+
cargo set-version --workspace "${{ steps.bump.outputs.new_version }}"
115+
116+
- name: Replace versions in scripts and docs
117+
env:
118+
CURR_VERSION: ${{ steps.meta.outputs.current_version }}
119+
NEW_VERSION: ${{ steps.bump.outputs.new_version }}
120+
run: |
121+
python3 - <<'PY'
122+
import os, re, sys, glob, pathlib
123+
124+
current_version = os.environ["CURR_VERSION"]
125+
new_version = os.environ["NEW_VERSION"]
126+
127+
# negative lookbehind (word,., or -) + optional 'v' + the escaped current version + negative lookahead (word or .)
128+
# e.g. current version of 1.0.1 will match 1.0.1, v1.0.1, v1.0.1-rc.1
129+
# e.g. current version of 1.0.1 will not match ver1.0.1, 1.0.1x, 1.0.11, 1.0.1.beta
130+
pat = re.compile(rf'(?<![\w.-])(v?){re.escape(current_version)}(?![\w.])')
131+
132+
def repl(m): # preserve 'v' prefix if it existed
133+
return (m.group(1) or '') + new_version
134+
135+
# Targets to update
136+
targets = [
137+
"scripts/nix/install.sh", # nix shell script
138+
"scripts/windows/install.ps1", # PowerShell
139+
*glob.glob("**/*.mdx", recursive=True), # docs
140+
]
141+
142+
changed = 0
143+
for path in targets:
144+
p = pathlib.Path(path)
145+
if not p.exists():
146+
continue
147+
txt = p.read_text(encoding="utf-8")
148+
new_txt, n = pat.subn(repl, txt)
149+
if n:
150+
p.write_text(new_txt, encoding="utf-8")
151+
print(f"Updated {path} ({n} occurrence{'s' if n!=1 else ''})")
152+
changed += n
153+
154+
if changed == 0:
155+
sys.exit("::warning::No occurrences of the current version were found.")
156+
PY
157+
158+
- name: Push changes to release branch
159+
id: push_changes
160+
run: |
161+
set -e
162+
git add -A || true
163+
git commit -m "Bumping to version ${{ steps.bump.outputs.new_version }}" || true
164+
git push origin HEAD

0 commit comments

Comments
 (0)