自動更新版本號

This commit is contained in:
踢低吸 2022-08-31 08:29:40 +00:00
parent cf3ab95488
commit 153a7be1ad
2 changed files with 33 additions and 5 deletions

View File

@ -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

View File

@ -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))