Automatically get version number from project file
This commit is contained in:
parent
bbdd5ce586
commit
29b8c59c9e
16
build.py
16
build.py
@ -2,11 +2,12 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import argparse
|
import argparse
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
import re
|
||||||
|
|
||||||
dockercmd = 'docker'
|
dockercmd = 'docker'
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Create custom recumock images.')
|
parser = argparse.ArgumentParser(description='Create custom recumock images.')
|
||||||
parser.add_argument('tags', metavar='TAG', nargs='+', help='Version tags to build.')
|
parser.add_argument('tags', metavar='TAG', nargs='*', help='Version tags to build.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -25,6 +26,19 @@ def build(images, directory, platforms, build_args = None):
|
|||||||
print(' '.join(command))
|
print(' '.join(command))
|
||||||
subprocess.run(command, check=True)
|
subprocess.run(command, check=True)
|
||||||
|
|
||||||
|
def version_from_project():
|
||||||
|
with open(r'MinecraftDiscordBot\MinecraftDiscordBot.csproj', 'r') as f:
|
||||||
|
project = f.read()
|
||||||
|
|
||||||
|
regex = r"<Version>\s*([^<]*?)\s*<\/Version>"
|
||||||
|
matches = re.search(regex, project, re.IGNORECASE)
|
||||||
|
if not matches:
|
||||||
|
raise Exception("Could not read version from project file!")
|
||||||
|
return matches.group(1)
|
||||||
|
|
||||||
|
if len(args.tags) == 0:
|
||||||
|
args.tags.append(version_from_project())
|
||||||
|
|
||||||
for version in args.tags:
|
for version in args.tags:
|
||||||
parts = version.split('.')
|
parts = version.split('.')
|
||||||
tags = list('.'.join(parts[:i]) for i in range(1, len(parts) + 1))
|
tags = list('.'.join(parts[:i]) for i in range(1, len(parts) + 1))
|
||||||
|
Loading…
Reference in New Issue
Block a user