-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from hsyhhssyy/master
新增Pypi的GithubAction
- Loading branch information
Showing
2 changed files
with
97 additions
and
14 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,34 @@ | ||
name: Pylint | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
pypi-publish: | ||
name: upload release to PyPI | ||
runs-on: ubuntu-latest | ||
environment: release | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install setuptools wheel twine | ||
- name: Build package | ||
run: | | ||
python setup.py bdist_wheel --auto-increment-version | ||
- name: Publish package distributions to PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
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 |
---|---|---|
@@ -1,32 +1,78 @@ | ||
import os | ||
import json | ||
import random | ||
import setuptools | ||
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel | ||
|
||
from urllib import request | ||
|
||
|
||
def ver_num(_v): | ||
num = int(_v.replace('.', '')) | ||
if num < 1000: | ||
num *= 10 | ||
return num | ||
|
||
def get_new_version(): | ||
pypi = json.loads(request.urlopen('https://pypi.python.org/pypi/amiyabot/json').read()) | ||
v_list = {ver_num(v): v for v in pypi['releases'].keys()} | ||
s_list = sorted(v_list) | ||
latest = v_list[s_list[-1]] | ||
|
||
print(f'latest: {latest}') | ||
|
||
return f"{latest}" | ||
# return f"1.10.10" | ||
|
||
# Auto increment the version number. | ||
# 1.0.9 -> 1.1.0 , 1.9.9 -> 2.0.0 but 9.9.9 -> 10.0.0 | ||
def incr_version(v): | ||
v = v.split('.') | ||
if len(v) == 3: | ||
if int(v[2]) >= 9: | ||
v[2] = '0' | ||
if int(v[1]) >= 9: | ||
v[1] = '0' | ||
v[0] = str(int(v[0]) + 1) | ||
else: | ||
v[1] = str(int(v[1]) + 1) | ||
else: | ||
v[2] = str(int(v[2]) + 1) | ||
else: | ||
v.append('1') | ||
return '.'.join(v) | ||
|
||
class CustomBdistWheelCommand(_bdist_wheel): | ||
user_options = _bdist_wheel.user_options + [ | ||
('auto-increment-version', None, 'Auto increment the version number before building with special rule: 1.0.9 -> 1.1.0 , 1.9.9 -> 2.0.0 . However 9.9.9 -> 10.0.0') | ||
] | ||
|
||
def initialize_options(self): | ||
_bdist_wheel.initialize_options(self) | ||
self.auto_increment_version = False | ||
|
||
def finalize_options(self): | ||
latest_version = get_new_version() | ||
if self.auto_increment_version: | ||
new_version = incr_version(latest_version) | ||
print(f'Auto-incrementing version to: {new_version}') | ||
self.distribution.metadata.version = new_version | ||
else: | ||
new_version = incr_version(latest_version) | ||
release_new = input(f'new?: {new_version} (Y/n)') | ||
|
||
pypi = json.loads(request.urlopen('https://pypi.python.org/pypi/amiyabot/json').read()) | ||
v_list = {ver_num(v): v for v in pypi['releases'].keys()} | ||
s_list = sorted(v_list) | ||
latest = v_list[s_list[-1]] | ||
if not (not release_new or release_new.lower() == 'y'): | ||
new_version = input('version: ') | ||
|
||
print(f'latest: {latest}') | ||
self.distribution.metadata.version = new_version | ||
|
||
latest = latest.split('.') | ||
latest[-1] = str(int(latest[-1]) + 1) | ||
# 加入一个随机数的BuildNumber保证Action可以重复执行 | ||
build_number = random.randint(0, 1000) | ||
self.build_number = f"{build_number}" | ||
|
||
new_version = '.'.join(latest) | ||
release_new = input(f'new?: {new_version} (Y/n)') | ||
_bdist_wheel.finalize_options(self) | ||
|
||
if not (not release_new or release_new.lower() == 'y'): | ||
new_version = '' | ||
def run(self): | ||
_bdist_wheel.run(self) | ||
|
||
with open('README.md', mode='r', encoding='utf-8') as md: | ||
description = md.read() | ||
|
@@ -44,7 +90,7 @@ def ver_num(_v): | |
|
||
setuptools.setup( | ||
name='amiyabot', | ||
version=new_version or input('version: '), | ||
version="0.0.1", | ||
author='vivien8261', | ||
author_email='[email protected]', | ||
url='https://www.amiyabot.com', | ||
|
@@ -57,6 +103,9 @@ def ver_num(_v): | |
include_package_data=True, | ||
python_requires='>=3.8', | ||
install_requires=requirements, | ||
cmdclass={ | ||
'bdist_wheel': CustomBdistWheelCommand, | ||
}, | ||
) | ||
|
||
# python setup.py bdist_wheel | ||
# python setup.py bdist_wheel --auto-increment-version |