From 153a7be1ad9baaed283dc7e12a036c255b19291a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B8=A2=E4=BD=8E=E5=90=B8?= Date: Wed, 31 Aug 2022 08:29:40 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E8=87=AA=E5=8B=95=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E8=99=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto_newversion.yml | 9 ++++----- AutoBuild/auto_update_version.py | 29 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 AutoBuild/auto_update_version.py diff --git a/.github/workflows/auto_newversion.yml b/.github/workflows/auto_newversion.yml index d6d3887..e482f41 100644 --- a/.github/workflows/auto_newversion.yml +++ b/.github/workflows/auto_newversion.yml @@ -2,6 +2,8 @@ name: Auto Update Version on: push: + paths: + - "**.txt" jobs: # This workflow contains a single job called "build" @@ -17,16 +19,13 @@ jobs: with: python-version: "3.x" - # - name: Run AutoBuild - # run: | - # cd AutoBuild - # python auto_update_version.py - id: files uses: jitterbit/get-changed-files@v1 with: format: "csv" - run: | + cd AutoBuild mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.files.outputs.added_modified }}') for added_modified_file in "${added_modified_files[@]}"; do - echo "Do something with this ${added_modified_file}." + python auto_update_version.py done diff --git a/AutoBuild/auto_update_version.py b/AutoBuild/auto_update_version.py new file mode 100644 index 0000000..009c66d --- /dev/null +++ b/AutoBuild/auto_update_version.py @@ -0,0 +1,29 @@ +import re +import sys +from datetime import datetime, timedelta, timezone + +tz = timezone(timedelta(hours=+8)) +today = datetime.now(tz).date() + +args = sys.argv +if len(args) != 2: + print('Got Empty Arguments') + sys.exit(1) + +files = args[-1] + +with open(files, 'r') as f: + pattern = r'(?<=Version: )(\d+\.\d+\.)(\d+)' + read_file = f.read() + first = '\n'.join(read_file.splitlines()[:5]) + version = re.findall(pattern, first, re.MULTILINE)[0] + dt = datetime.strptime(version[0], '%Y.%m%d.').date() + newversion = today.strftime('%Y.%m%d.') + + if dt != today: + newversion += '1' + else: + newversion += str(int(version[1])+1) + + with open(files, 'w') as f_: + f_.write(read_file.replace(''.join(version), newversion))