From 44fb55688743bcd4d389329c61362caa6cb48c4f Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 25 Jul 2022 01:51:01 +0800 Subject: [PATCH] ok --- .github/workflows/python-publish.yml | 4 ++- run_output_version.py | 41 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 run_output_version.py diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 9bc50da..e50a4d4 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -35,7 +35,9 @@ jobs: uses: actions/setup-python@v1 with: python-version: 3.7 - + - name: out version + run: + python run_tags_add.py # 构建和发布 - name: Install pypa/build run: >- diff --git a/run_output_version.py b/run_output_version.py new file mode 100644 index 0000000..011d78a --- /dev/null +++ b/run_output_version.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +import os + + +def view_all_environment_variables(): + from icecream import ic + for item in os.environ: + name = item + value = os.environ[item] + ic(name, value) + + +# view_all_environment_variables() + +tagName = os.environ.get('GITHUB_REF_NAME') +print("tagName:", tagName) +fileDir = os.path.dirname(__file__) +print("file dir:", fileDir) +versionFilePath = os.path.join(fileDir, "version.py") +print(f"edit file {versionFilePath} output: version = {tagName}") +# with open(versionFilePath, 'w') as f: +# f.write(f'version = "{tagName}"') + +with open("pyefun/__init__.py", "r") as f: + lines = f.readlines() + # 找到版本号的行 + for i, line in enumerate(lines): + if '__version__' in line: + # 找到版本号的行 + version_line = i + break + # 替换版本号 + lines[version_line] = f"__version__ = '{tagName}'\n" + +# 写出文件 +with open("pyefun/__init__.py", "w") as f: + f.writelines(lines) + + + +exit()