mirror of
https://github.com/FutaGuard/LowTechFilter.git
synced 2025-06-21 05:21:02 +08:00
✨ 自動更新版本號
This commit is contained in:
parent
cf3ab95488
commit
153a7be1ad
9
.github/workflows/auto_newversion.yml
vendored
9
.github/workflows/auto_newversion.yml
vendored
@ -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
|
||||
|
29
AutoBuild/auto_update_version.py
Normal file
29
AutoBuild/auto_update_version.py
Normal 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))
|
Loading…
x
Reference in New Issue
Block a user