forked from Lyken17/pytorch-OpCounter
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76a9e4d
commit bbb6210
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,64 @@ | ||
# Ultralytics YOLO 🚀, AGPL-3.0 license | ||
# Publish pip package to PyPI https://pypi.org/project/ultralytics-thop/ | ||
|
||
name: Publish to PyPI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
workflow_dispatch: | ||
inputs: | ||
pypi: | ||
type: boolean | ||
description: Publish to PyPI | ||
|
||
jobs: | ||
publish: | ||
if: github.repository == 'ultralytics/thop' && github.actor == 'glenn-jocher' | ||
name: Publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: "0" # pulls all commits (needed correct last updated dates in Docs) | ||
- name: Set up Python environment | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
cache: "pip" # caching pip dependencies | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip wheel build twine toml | ||
pip install ultralytics --extra-index-url https://download.pytorch.org/whl/cpu | ||
- name: Check PyPI version | ||
shell: python | ||
run: | | ||
import os | ||
import toml | ||
from ultralytics.utils.checks import check_latest_pypi_version | ||
|
||
# Read version from pyproject.toml | ||
with open('pyproject.toml', 'r') as file: | ||
pyproject_version = toml.load(file)['project']['version'] | ||
v_local = tuple(map(int, pyproject_version.split('.'))) | ||
|
||
# Compare with version on PyPI | ||
v_pypi = tuple(map(int, check_latest_pypi_version('ultralytics-thop').split('.'))) | ||
print(f'Local version is {v_local}') | ||
print(f'PyPI version is {v_pypi}') | ||
d = [a - b for a, b in zip(v_local, v_pypi)] # diff | ||
increment = (d[0] == d[1] == 0) and (0 < d[2] < 3) # only publish if patch version increments by 1 or 2 | ||
os.system(f'echo "increment={increment}" >> $GITHUB_OUTPUT') | ||
os.system(f'echo "version={pyproject_version}" >> $GITHUB_OUTPUT') | ||
if increment: | ||
print('Local version is higher than PyPI version. Publishing new version to PyPI ✅.') | ||
id: check_pypi | ||
- name: Publish to PyPI | ||
continue-on-error: true | ||
if: (github.event_name == 'push' || github.event.inputs.pypi == 'true') && steps.check_pypi.outputs.increment == 'True' | ||
env: | ||
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} | ||
run: | | ||
python -m build | ||
python -m twine upload dist/* -u __token__ -p $PYPI_TOKEN |