-
Notifications
You must be signed in to change notification settings - Fork 88
Refactor CI/CD system based on latest standardization for upstreams #135
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 1 commit
Commits
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
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 |
---|---|---|
|
@@ -64,17 +64,19 @@ jobs: | |
matrix: | ||
python: ["3.9"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install dependencies | ||
run: pip install toml loguru tox | ||
run: pip install tox | ||
- name: Build the package | ||
run: | | ||
export GUIDELLM_BUILD_TYPE=release_candidate | ||
export GUIDELLM_BUILD_NUMBER=${{ github.run_number }} | ||
export GUIDELLM_BUILD_TYPE=candidate | ||
tox -e build | ||
- name: Upload build artifacts | ||
id: artifact-upload | ||
|
@@ -87,7 +89,7 @@ jobs: | |
retention-days: 30 | ||
- name: Log artifact location | ||
run: | | ||
echo "Artifacts uploaded to: https://api.github.com/repos/neuralmagic/guidellm/actions/artifacts/${{ steps.artifact-upload.outputs.artifact-id }}" | ||
echo "Artifacts uploaded to: ${{ steps.artifact-upload.outputs.artifact-url }}" | ||
- name: Push wheel to PyPI | ||
uses: neuralmagic/nm-actions/actions/[email protected] | ||
with: | ||
|
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 |
---|---|---|
|
@@ -12,17 +12,19 @@ jobs: | |
matrix: | ||
python: ["3.9"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- name: Install dependencies | ||
run: pip install toml loguru tox | ||
run: pip install tox | ||
- name: Build the package | ||
run: | | ||
export GUIDELLM_BUILD_TYPE=release | ||
export GUIDELLM_BUILD_NUMBER=${{ github.run_number }} | ||
tox -e build | ||
- name: Upload build artifacts | ||
id: artifact-upload | ||
|
@@ -35,7 +37,7 @@ jobs: | |
retention-days: 90 | ||
- name: Log artifact location | ||
run: | | ||
echo "Artifacts uploaded to: https://api.github.com/repos/neuralmagic/guidellm/actions/artifacts/${{ steps.artifact-upload.outputs.artifact-id }}" | ||
echo "Artifacts uploaded to: Artifacts uploaded to: ${{ steps.artifact-upload.outputs.artifact-url }}" | ||
- name: Push wheel to PyPI | ||
uses: neuralmagic/nm-actions/actions/[email protected] | ||
with: | ||
|
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
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,126 @@ | ||
import os | ||
import re | ||
from pathlib import Path | ||
from typing import Optional, Union | ||
|
||
from packaging.version import Version | ||
from setuptools import setup | ||
from setuptools_git_versioning import count_since, get_branch, get_sha, get_tags | ||
|
||
LAST_RELEASE_VERSION = Version("0.0.0") | ||
TAG_VERSION_PATTERN = re.compile(r"^v(\d+\.\d+\.\d+)$") | ||
|
||
|
||
def get_last_version_diff() -> tuple[Version, Optional[str], Optional[int]]: | ||
""" | ||
Get the last version, last tag, and the number of commits since the last tag. | ||
If no tags are found, return the last release version and None for the tag/commits. | ||
|
||
:returns: A tuple containing the last version, last tag, and number of commits since | ||
the last tag. | ||
""" | ||
tagged_versions = [ | ||
(Version(match.group(1)), tag) | ||
for tag in get_tags(root=Path(__file__).parent) | ||
if (match := TAG_VERSION_PATTERN.match(tag)) | ||
] | ||
tagged_versions.sort(key=lambda tv: tv[0]) | ||
last_version, last_tag = ( | ||
tagged_versions[-1] if tagged_versions else (LAST_RELEASE_VERSION, None) | ||
) | ||
commits_since_last = ( | ||
count_since(last_tag + "^{commit}", root=Path(__file__).parent) | ||
if last_tag | ||
else None | ||
) | ||
|
||
return last_version, last_tag, commits_since_last | ||
|
||
|
||
def get_next_version( | ||
build_type: str, build_iteration: Optional[Union[str, int]] | ||
) -> tuple[Version, Optional[str], int]: | ||
""" | ||
Get the next version based on the build type and iteration. | ||
- build_type == release: take the last version and add a post if build iteration | ||
- build_type == candidate: increment to next minor, add 'rc' with build iteration | ||
- build_type == nightly: increment to next minor, add 'a' with build iteration | ||
- build_type == alpha: increment to next minor, add 'a' with build iteration | ||
- build_type == dev: increment to next minor, add 'dev' with build iteration | ||
|
||
:param build_type: The type of build (release, candidate, nightly, alpha, dev). | ||
:param build_iteration: The build iteration number. If None, defaults to the number | ||
of commits since the last tag or 0 if no commits since the last tag. | ||
:returns: A tuple containing the next version, the last tag the version is based | ||
off of (if any), and the final build iteration used. | ||
""" | ||
version, tag, commits_since_last = get_last_version_diff() | ||
|
||
if not build_iteration and build_iteration != 0: | ||
build_iteration = commits_since_last or 0 | ||
elif isinstance(build_iteration, str): | ||
build_iteration = int(build_iteration) | ||
|
||
if build_type == "release": | ||
if commits_since_last: | ||
# add post since we have commits since last tag | ||
version = Version(f"{version.base_version}.post{build_iteration}") | ||
return version, tag, build_iteration | ||
|
||
# not in release pathway, so need to increment to target next release version | ||
version = Version(f"{version.major}.{version.minor + 1}.0") | ||
|
||
if build_type == "candidate": | ||
# add 'rc' since we are in candidate pathway | ||
version = Version(f"{version}.rc{build_iteration}") | ||
elif build_type in ["nightly", "alpha"]: | ||
# add 'a' since we are in nightly or alpha pathway | ||
version = Version(f"{version}.a{build_iteration}") | ||
else: | ||
# assume 'dev' if not in any of the above pathways | ||
version = Version(f"{version}.dev{build_iteration}") | ||
|
||
return version, tag, build_iteration | ||
|
||
|
||
def write_version_files() -> tuple[Path, Path]: | ||
""" | ||
Write the version information to version.txt and version.py files. | ||
version.txt contains the version string. | ||
version.py contains the version plus additional metadata. | ||
|
||
:returns: A tuple containing the paths to the version.txt and version.py files. | ||
""" | ||
build_type = os.getenv("GUIDELLM_BUILD_TYPE", "dev").lower() | ||
version, tag, build_iteration = get_next_version( | ||
build_type=build_type, | ||
build_iteration=os.getenv("GUIDELLM_BUILD_ITERATION"), | ||
) | ||
module_path = Path(__file__).parent / "src" / "guidellm" | ||
version_txt_path = module_path / "version.txt" | ||
version_py_path = module_path / "version.py" | ||
|
||
with version_txt_path.open("w") as file: | ||
file.write(str(version)) | ||
|
||
with version_py_path.open("w") as file: | ||
file.writelines( | ||
[ | ||
f'version = "{version}"\n', | ||
f'build_type = "{build_type}"\n', | ||
f'build_iteration = "{build_iteration}"\n', | ||
f'git_commit = "{get_sha()}"\n', | ||
f'git_branch = "{get_branch()}"\n', | ||
f'git_last_tag = "{tag}"\n', | ||
] | ||
) | ||
|
||
return version_txt_path, version_py_path | ||
|
||
|
||
setup( | ||
setuptools_git_versioning={ | ||
"enabled": True, | ||
"version_file": str(write_version_files()[0]), | ||
} | ||
) |
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.