Skip to content

Commit 1a8675b

Browse files
chore: bump version to 1.0.0-rc.1
1 parent 5438b75 commit 1a8675b

File tree

4 files changed

+139
-50
lines changed

4 files changed

+139
-50
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
permissions:
2424
id-token: write
25-
contents: read
25+
contents: write
2626

2727
steps:
2828
- name: Checkout code
@@ -69,3 +69,15 @@ jobs:
6969
# Also tag as latest
7070
docker tag ghcr.io/${REPO_NAME}:${IMAGE_TAG} ghcr.io/${REPO_NAME}:latest
7171
docker push ghcr.io/${REPO_NAME}:latest
72+
73+
- name: Create and Push Git Tag
74+
run: |
75+
VERSION="${{ steps.get-version.outputs.VERSION }}"
76+
# Check if tag already exists
77+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
78+
echo "Tag $VERSION already exists, skipping"
79+
else
80+
echo "Creating tag: $VERSION"
81+
git tag $VERSION
82+
git push origin $VERSION
83+
fi

.github/workflows/release.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ name: Create GitHub Release
22

33
on:
44
push:
5-
branches:
6-
- main
7-
- dev
8-
paths:
9-
- 'app/core/version.py'
10-
- 'pyproject.toml'
5+
tags:
6+
- '*' # Trigger on any tag push
117

128

139
jobs:
@@ -23,6 +19,7 @@ jobs:
2319
uses: actions/checkout@v5
2420
with:
2521
fetch-depth: 0 # Fetch all history for all tags and branches
22+
fetch-tags: true # Fetch all tags
2623

2724
- name: Set up Python
2825
uses: actions/setup-python@v6
@@ -34,11 +31,26 @@ jobs:
3431
python -m pip install --upgrade pip
3532
pip install openai pydantic
3633
34+
- name: Get current tag
35+
id: get-tag
36+
run: |
37+
# Get the tag that triggered this workflow
38+
TAG_NAME=${GITHUB_REF#refs/tags/}
39+
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT
40+
echo "Current tag: ${TAG_NAME}"
41+
42+
- name: Checkout tag commit
43+
run: |
44+
TAG_NAME="${{ steps.get-tag.outputs.TAG_NAME }}"
45+
git checkout ${TAG_NAME} || git checkout -b temp-${TAG_NAME} ${TAG_NAME}
46+
echo "Checked out tag: ${TAG_NAME}"
47+
3748
- name: Run Python script to generate release notes
3849
id: generate_release_notes
3950
env:
4051
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
4152
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
CURRENT_TAG: ${{ steps.get-tag.outputs.TAG_NAME }}
4254
run: |
4355
echo "Running generate_release_notes.py"
4456
python scripts/generate_release_notes.py
@@ -49,20 +61,13 @@ jobs:
4961
echo "Version: ${{ steps.generate_release_notes.outputs.version }}"
5062
echo "Release Notes: ${{ steps.generate_release_notes.outputs.release_notes }}"
5163
52-
- name: Create Release Tag
53-
run: |
54-
VERSION=$(cat $GITHUB_OUTPUT | grep "^version=" | cut -f2- -d=)
55-
echo "Creating tag: $VERSION"
56-
git tag $VERSION
57-
git push origin $VERSION
58-
5964
- name: Create GitHub Release
6065
uses: actions/create-release@v1
6166
env:
6267
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6368
with:
64-
tag_name: ${{ steps.generate_release_notes.outputs.version }}
65-
release_name: Release ${{ steps.generate_release_notes.outputs.version }} - ${{ steps.generate_release_notes.outputs.version_name }}
69+
tag_name: ${{ steps.get-tag.outputs.TAG_NAME }}
70+
release_name: Release ${{ steps.get-tag.outputs.TAG_NAME }} - ${{ steps.generate_release_notes.outputs.version_name }}
6671
body: ${{ steps.generate_release_notes.outputs.release_notes }}
6772
draft: false
68-
prerelease: ${{ github.ref == 'refs/heads/dev' }}
73+
prerelease: ${{ contains(steps.get-tag.outputs.TAG_NAME, 'beta') || contains(steps.get-tag.outputs.TAG_NAME, 'alpha') || contains(steps.get-tag.outputs.TAG_NAME, 'rc') || contains(steps.get-tag.outputs.TAG_NAME, 'pre') }}

app/core/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.0.beta.1"
1+
__version__ = "1.0.0-rc.1"

scripts/generate_release_notes.py

Lines changed: 104 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ def get_merge_commit_details(commit_hash):
5757
return []
5858

5959

60-
def get_commits_between_releases(last_release, branch):
61-
"""Get commits since the last release tag for release notes generation."""
60+
def get_commits_between_releases(last_release, current_tag):
61+
"""Get commits between two tags for release notes generation."""
6262
if last_release:
63-
range_spec = f"{last_release}..{branch}"
63+
range_spec = f"{last_release}..{current_tag}"
6464
else:
65-
range_spec = branch
65+
# If no previous release, get all commits up to current tag
66+
range_spec = current_tag
6667
print(f"Getting commits for release notes: {range_spec}")
6768

6869
# Get merge commits with their hashes (these are the important ones in our flow)
@@ -131,29 +132,79 @@ class ReleaseNotes(BaseModel):
131132

132133

133134
def get_version_from_version_py() -> str:
134-
"""Read version from app/core/version.py."""
135+
"""Read version from app/core/version.py using regex (avoids import dependencies)."""
135136
try:
136-
from app.core.version import __version__
137-
138-
print(f"Read version from app/core/version.py: {__version__}")
139-
return __version__
140-
except ImportError as e:
141-
print(f"Error importing version from app.core.version: {e}")
142-
# Fallback: try to read the file directly
143-
try:
144-
version_path = project_root / "app" / "core" / "version.py"
145-
if version_path.exists():
146-
content = version_path.read_text()
147-
match = re.search(r'__version__\s*=\s*"([^"]*)"', content)
148-
if match:
149-
version = match.group(1)
150-
print(f"Read version from version.py (regex fallback): {version}")
151-
return version
152-
except Exception as e2:
153-
print(f"Error reading version.py: {e2}")
137+
version_path = project_root / "app" / "core" / "version.py"
138+
if version_path.exists():
139+
content = version_path.read_text()
140+
match = re.search(r'__version__\s*=\s*"([^"]*)"', content)
141+
if match:
142+
version = match.group(1)
143+
print(f"Read version from version.py: {version}")
144+
return version
145+
print("Warning: version.py not found")
146+
return "0.0.0"
147+
except Exception as e:
148+
print(f"Error reading version.py: {e}")
154149
return "0.0.0"
155150

156151

152+
def is_prerelease(version: str) -> bool:
153+
"""Check if version is a pre-release (contains alpha, beta, rc, etc.)."""
154+
prerelease_patterns = [r"alpha", r"beta", r"rc", r"pre", r"dev"]
155+
version_lower = version.lower()
156+
return any(re.search(pattern, version_lower) for pattern in prerelease_patterns)
157+
158+
159+
def get_all_tags() -> list[str]:
160+
"""Get all tags sorted by version."""
161+
try:
162+
result = subprocess.run(
163+
["git", "tag", "--sort=-version:refname"],
164+
capture_output=True,
165+
text=True,
166+
)
167+
if result.returncode == 0:
168+
tags = [tag.strip() for tag in result.stdout.strip().split("\n") if tag.strip()]
169+
return tags
170+
return []
171+
except Exception as e:
172+
print(f"Error getting tags: {e}")
173+
return []
174+
175+
176+
def get_previous_release_tag(current_version: str) -> str | None:
177+
"""Get the appropriate previous release tag based on pre-release logic."""
178+
all_tags = get_all_tags()
179+
current_is_prerelease = is_prerelease(current_version)
180+
181+
if not all_tags:
182+
return None
183+
184+
# Find current tag in the list
185+
try:
186+
current_index = all_tags.index(current_version)
187+
except ValueError:
188+
# Current version not in tags, use the first tag as reference
189+
current_index = 0
190+
191+
# If current is a pre-release, find previous pre-release or stable
192+
# If current is stable, find previous stable (skip pre-releases)
193+
for i in range(current_index + 1, len(all_tags)):
194+
tag = all_tags[i]
195+
tag_is_prerelease = is_prerelease(tag)
196+
197+
if current_is_prerelease:
198+
# For pre-releases, include any previous release (stable or pre-release)
199+
return tag
200+
else:
201+
# For stable releases, only include previous stable releases
202+
if not tag_is_prerelease:
203+
return tag
204+
205+
return None
206+
207+
157208
def generate_release_notes(commits, last_release_tag):
158209
prompt = (
159210
"Generate release notes for the given commits. Focus on user-facing changes and important technical"
@@ -246,15 +297,36 @@ def write_to_github_output(name, value):
246297

247298

248299
def main():
249-
branch_name = get_current_branch()
250-
print(f"Current Branch Name: {branch_name}")
251-
252-
last_release_tag = get_last_release_tag()
253-
print(f"Latest Release Tag: {last_release_tag}")
254-
commits = get_commits_between_releases(last_release_tag, branch_name)
255-
256-
# Read version from version.py (single source of truth)
257-
version = get_version_from_version_py()
300+
# Get current tag from environment (set by GitHub Actions) or from git
301+
current_tag = os.environ.get("CURRENT_TAG")
302+
if not current_tag:
303+
# Try to get from git ref
304+
try:
305+
result = subprocess.run(
306+
["git", "describe", "--tags", "--exact-match", "HEAD"],
307+
capture_output=True,
308+
text=True,
309+
)
310+
if result.returncode == 0:
311+
current_tag = result.stdout.strip()
312+
except Exception:
313+
pass
314+
315+
if not current_tag:
316+
# Fallback: read from version.py
317+
current_tag = get_version_from_version_py()
318+
print(f"Warning: No tag found, using version from version.py: {current_tag}")
319+
320+
print(f"Current Tag/Version: {current_tag}")
321+
322+
# Get the appropriate previous release based on pre-release logic
323+
last_release_tag = get_previous_release_tag(current_tag)
324+
print(f"Previous Release Tag: {last_release_tag}")
325+
326+
commits = get_commits_between_releases(last_release_tag, current_tag)
327+
328+
# Use current tag as version
329+
version = current_tag
258330

259331
if commits:
260332
print(f"Commits for release notes: {commits}")

0 commit comments

Comments
 (0)