-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script required by pipeline "cli/bump_version.py"
- Loading branch information
1 parent
5078878
commit 1d7fb49
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python3 | ||
"""Bump the version number in version.php by one. | ||
If the date part is not from today, set it to today and set part_number to 00 | ||
""" | ||
|
||
import fileinput | ||
import sys | ||
import datetime | ||
import os | ||
import pathlib | ||
|
||
version_file = os.path.join(pathlib.Path(__file__).parent.resolve(), "..", 'version.php') | ||
|
||
if not os.path.exists(version_file): | ||
print(f"version.php does not exist at {version_file}. Skipping.") | ||
exit(1) | ||
|
||
for line in fileinput.input(version_file, inplace=True): | ||
if line.startswith("$plugin->version"): | ||
version = line.split("=")[1].strip()[:-1] | ||
|
||
part_date = version[:8] | ||
part_number = version[8:] | ||
|
||
old_date = datetime.datetime.strptime(part_date, "%Y%m%d") | ||
# check if this is today | ||
if old_date.date() == datetime.date.today(): | ||
# increment part_number | ||
part_number = str(int(part_number) + 1) | ||
# to string with leading zeros | ||
part_number = part_number.zfill(2) | ||
else: | ||
part_date = datetime.date.today().strftime("%Y%m%d") | ||
part_number = "00" | ||
|
||
print(f"$plugin->version = {part_date}{part_number};") | ||
else: | ||
print(line, end='') | ||
|
||
print(f"Version bumped for {version_file}.") |