-
Notifications
You must be signed in to change notification settings - Fork 303
fix: updated logic to update versions with scripts for nightly #1165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0bed146
updated logic to update versions with scripts for nightly
lucaseduoli 1dea2ad
Potential fix for pull request finding
lucaseduoli 2d031e5
Potential fix for pull request finding
lucaseduoli 15d04ff
Potential fix for pull request finding
lucaseduoli 7d7c30e
Potential fix for pull request finding
lucaseduoli 7c37253
update import
lucaseduoli 154b79e
remove pyproject from update version
lucaseduoli 983ef05
updated update_pyproject_name
lucaseduoli a90582a
updated nightly logic
lucaseduoli 93f43dd
changed things for github
lucaseduoli 7612909
fix github nitpicks
lucaseduoli 5b1fb99
Potential fix for pull request finding
lucaseduoli 4a3f479
Potential fix for pull request finding
lucaseduoli e6fe41e
Potential fix for pull request finding
lucaseduoli 4810497
Potential fix for pull request finding
lucaseduoli dc92fa0
Potential fix for pull request finding
lucaseduoli 3c29f3a
Potential fix for pull request finding
lucaseduoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import sys | ||
| import requests | ||
| from packaging.version import Version | ||
| from pathlib import Path | ||
| import tomllib | ||
| from typing import Optional | ||
|
|
||
| PYPI_OPENRAG_NIGHTLY_URL = "https://pypi.org/pypi/openrag-nightly/json" | ||
| PYPI_OPENRAG_URL = "https://pypi.org/pypi/openrag/json" | ||
|
|
||
| def get_latest_published_version(is_nightly: bool) -> Optional[Version]: | ||
| url = PYPI_OPENRAG_NIGHTLY_URL if is_nightly else PYPI_OPENRAG_URL | ||
| res = requests.get(url, timeout=10) | ||
| if res.status_code == 404: | ||
| return None | ||
| res.raise_for_status() | ||
| try: | ||
| version_str = res.json()["info"]["version"] | ||
| except Exception as e: | ||
| msg = "Got unexpected response from PyPI" | ||
| raise RuntimeError(msg) from e | ||
| return Version(version_str) | ||
|
|
||
| def create_tag(): | ||
| # Read version from pyproject.toml | ||
| pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml" | ||
| with open(pyproject_path, "rb") as f: | ||
| pyproject_data = tomllib.load(f) | ||
|
|
||
| current_version_str = pyproject_data["project"]["version"] | ||
| current_version = Version(current_version_str) | ||
|
|
||
| try: | ||
| current_nightly_version = get_latest_published_version(is_nightly=True) | ||
| except (requests.RequestException, KeyError, ValueError): | ||
| current_nightly_version = None | ||
|
|
||
| build_number = "0" | ||
| latest_base_version = current_version.base_version | ||
| nightly_base_version = current_nightly_version.base_version if current_nightly_version else None | ||
|
|
||
| if latest_base_version == nightly_base_version: | ||
| dev_number = (current_nightly_version.dev if current_nightly_version.dev is not None else -1) if current_nightly_version else -1 | ||
| build_number = str(dev_number + 1) | ||
|
|
||
| # Build PEP 440-compliant nightly version (without leading "v") | ||
| nightly_version_str = f"{latest_base_version}.dev{build_number}" | ||
|
|
||
| # Verify PEP440 | ||
| Version(nightly_version_str) | ||
|
|
||
| # Git tag uses a leading "v" prefix | ||
| new_nightly_version = f"v{nightly_version_str}" | ||
| return new_nightly_version | ||
|
|
||
| if __name__ == "__main__": | ||
| try: | ||
| tag = create_tag() | ||
| print(tag) | ||
| except Exception as e: | ||
| print(f"Error creating tag: {e}", file=sys.stderr) | ||
| sys.exit(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Add current dir to sys.path | ||
| current_dir = Path(__file__).resolve().parent | ||
| current_dir_str = str(current_dir) | ||
| if current_dir_str not in sys.path: | ||
| sys.path.append(current_dir_str) | ||
|
|
||
| from update_pyproject_name import update_pyproject_name | ||
| from update_pyproject_version import update_version | ||
|
|
||
| def main(): | ||
| if len(sys.argv) != 3: | ||
| print("Usage: update_pyproject_combined.py main <main_tag>") | ||
| sys.exit(1) | ||
|
|
||
| mode = sys.argv[1] | ||
| main_tag = sys.argv[2] | ||
|
|
||
| if mode != "main": | ||
| print("Only 'main' mode is supported") | ||
| sys.exit(1) | ||
|
|
||
| # Update name and version for openrag | ||
| update_pyproject_name("openrag-nightly") | ||
| update_version(main_tag) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| def update_pyproject_name(new_name: str): | ||
| path = Path("pyproject.toml") | ||
| if not path.exists(): | ||
| print("File pyproject.toml not found") | ||
| raise SystemExit(1) | ||
|
|
||
| content = path.read_text() | ||
| new_content = re.sub(r'^name = "[^"]+"', f'name = "{new_name}"', content, flags=re.M) | ||
|
|
||
| # Fail if the name pattern was not found / no substitution was made | ||
| if new_content == content: | ||
| print( | ||
| 'Error: Could not find a line matching `name = "..."` in pyproject.toml to update.', | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| path.write_text(new_content) | ||
| print(f"Updated name in pyproject.toml to {new_name}") | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) != 2: | ||
| print("Usage: update_pyproject_name.py <new_name>") | ||
| sys.exit(1) | ||
| update_pyproject_name(sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
| from packaging.version import Version, InvalidVersion | ||
|
|
||
| def update_version(new_version): | ||
| pyproject_path = Path("pyproject.toml") | ||
| with open(pyproject_path, "r") as f: | ||
| content = f.read() | ||
|
|
||
| # Update the version field | ||
| # Removes 'v' prefix if present from tag | ||
| clean_version = new_version.lstrip('v') | ||
|
|
||
| # Validate that the resulting version is a valid PEP 440 version | ||
| try: | ||
| Version(clean_version) | ||
| except InvalidVersion: | ||
| print( | ||
| f"Error: '{clean_version}' is not a valid PEP 440 version after stripping any leading 'v'.", | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| new_content = re.sub( | ||
| r'^version = "[^"]+"', | ||
| f'version = "{clean_version}"', | ||
| content, | ||
| flags=re.M, | ||
| ) | ||
|
|
||
| # Fail if the version pattern was not found / no substitution was made | ||
| if new_content == content: | ||
| print( | ||
| 'Error: Could not find a line matching `version = "..."` in pyproject.toml to update.', | ||
| file=sys.stderr, | ||
| ) | ||
| sys.exit(1) | ||
|
|
||
| with open(pyproject_path, "w") as f: | ||
| f.write(new_content) | ||
| print(f"Updated pyproject.toml version to {clean_version}") | ||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) < 2: | ||
| print("Usage: python update_pyproject_version.py <new_version>") | ||
| sys.exit(1) | ||
| update_version(sys.argv[1]) | ||
lucaseduoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.