Skip to content

Commit

Permalink
auto update version
Browse files Browse the repository at this point in the history
  • Loading branch information
lemisky committed Jul 8, 2021
1 parent c7c644d commit 044406e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install build
python .github/workflows/update_version.py
- name: Build package
run: python -m build
- name: Publish package
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
import re

if __name__ == '__main__':
tag: os.DirEntry
tmp_mtime = 0
latest_name: str = None
for tag in os.scandir('.git/refs/tags'):
print(f'tag {tag.name}')
tag_stat = os.stat(tag)
# 最近修改时间
mtime = tag_stat.st_mtime
if mtime > tmp_mtime:
latest_name = tag.name
tmp_mtime = mtime
print(f'最新tag是: {latest_name}')
version = latest_name[1:]
print(f'最新version是: {version}')

# 读取文件
init_py = 'docts/__init__.py'
init = open(init_py, encoding='utf-8').read()
new_init = re.sub('\n__version__.*\n', f"\n__version__ = '{version}'\n", init)
open(init_py, 'w', encoding='utf-8').write(new_init)
2 changes: 1 addition & 1 deletion docts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

__description__ = 'document translate, read & translate & write'
__url__ = 'https://github.com/foyoux/docts'
__version__ = '0.0.3'
__version__ = '0.0.1'
__author__ = 'foyou'
__author_email__ = '[email protected]'
__license__ = 'GPL-3.0'
Expand Down

0 comments on commit 044406e

Please sign in to comment.