From 95aec64de13d482c2b368f95f06d6d0e1272c388 Mon Sep 17 00:00:00 2001 From: "Linlang Lv (iSoftStone Information)" Date: Fri, 19 Apr 2024 14:30:23 +0800 Subject: [PATCH] add upload test --- .github/workflows/test_upload.yml | 3 ++- scripts/publish.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 scripts/publish.py diff --git a/.github/workflows/test_upload.yml b/.github/workflows/test_upload.yml index 9cdcd51a83..96ce1bc4a8 100644 --- a/.github/workflows/test_upload.yml +++ b/.github/workflows/test_upload.yml @@ -50,6 +50,7 @@ jobs: run: | pip install numpy pip install cython + python scripts/publish.py python setup.py bdist_wheel - name: Build and publish env: @@ -82,4 +83,4 @@ jobs: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.TESTPYPI_TOKEN }} run: | - twine upload --repository-url https://test.pypi.org/legacy/ dist/pyqlib-*-manylinux*.whl \ No newline at end of file + twine upload --repository-url https://test.pypi.org/legacy/ dist/pyqlib-*-manylinux*.whl diff --git a/scripts/publish.py b/scripts/publish.py new file mode 100644 index 0000000000..a67d87b77e --- /dev/null +++ b/scripts/publish.py @@ -0,0 +1,35 @@ +import re + + +def read_file(): + with open("qlib/__init__.py", "r", encoding="utf-8") as f: + content = f.read() + return content + + +def write_file(content: str): + with open("qlib/__init__.py", "w", encoding="utf-8") as f: + f.write(content) + + +def update_version(version_num: list): + if len(version_num) == 3: + new_version = f"{version_num[0]}.{version_num[1]}.{version_num[2]}.{1}" + if len(version_num) == 4: + new_version = f"{version_num[0]}.{version_num[1]}.{version_num[2]}.{int(version_num[3]) + 1}" + return new_version + + +def main(): + content = read_file() + pattern = r"__version__ = \"(\d+(\.\d+)*(\.\d+)*)\"" + match = re.search(pattern, content) + old_version = match.group(1) + old_version_num = old_version.split(".") + new_version = update_version(old_version_num) + new_content = content.replace(old_version, new_version) + write_file(new_content) + + +if __name__ == "__main__": + main()