Skip to content

Ultralytics Code Refactor https://ultralytics.com/actions (#32) #28

Ultralytics Code Refactor https://ultralytics.com/actions (#32)

Ultralytics Code Refactor https://ultralytics.com/actions (#32) #28

Workflow file for this run

# 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
pip uninstall thop -y # uninstall older thop that conflicts with this repo
pip install -e .
- name: Check PyPI version
shell: python
run: |
import os
import thop
import ultralytics
from ultralytics.utils.checks import check_latest_pypi_version
v_local = tuple(map(int, thop.__version__.split('.')))
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_patch = (d[0] == d[1] == 0) and (0 < d[2] < 3) # publish if patch version increments by 1 or 2
increment_minor = (d[0] == 0) and (d[1] == 1) and v_local[2] == 0 # publish if minor version increments
increment = increment_patch or increment_minor
os.system(f'echo "increment={increment}" >> $GITHUB_OUTPUT')
os.system(f'echo "version={thop.__version__}" >> $GITHUB_OUTPUT')
if increment:
print('Local version is higher than PyPI version. Publishing new version to PyPI ✅.')
id: check_pypi
- name: Publish new tag
if: steps.check_pypi.outputs.increment == 'True'
run: |
git config --global user.name "UltralyticsAssistant"
git config --global user.email "[email protected]"
git tag -a "v${{ steps.check_pypi.outputs.version }}" -m "$(git log -1 --pretty=%B)" # i.e. "v0.1.2 commit message"
git push origin "v${{ steps.check_pypi.outputs.version }}"
- 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