Skip to content

Commit

Permalink
update version + script
Browse files Browse the repository at this point in the history
  • Loading branch information
f-peverali committed Jan 5, 2024
1 parent 9cab185 commit 3469918
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 120 deletions.
4 changes: 2 additions & 2 deletions ImplementationGuide/markdown/Einfuehrung.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<img src="https://raw.githubusercontent.com/gematik/spec-ISiK-Basismodul/master-isik-stufe-2/Material/Gematik_Logo_Flag.png" alt="gematik logo" width="400"/>

----
Version: 3.0.0
Version: 3.0.1

Datum: 1.7.2023
Datum: 05.01.2024

Status: Aktiv

Expand Down
10 changes: 5 additions & 5 deletions Resources/input/fsh/ruleset.fsh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
RuleSet: Meta
* ^status = #active
* ^experimental = false
* ^version = "3.0.0"
* ^version = "3.0.1"
* ^publisher = "gematik GmbH"
* ^date = "2023-07-01"
* ^date = "2024-01-05"

RuleSet: Meta-CapabilityStatement
* status = #active
* experimental = false
* version = "3.0.0"
* version = "3.0.1"
* publisher = "gematik GmbH"
* date = "2023-07-01"
* implementationGuide = "https://gematik.de/fhir/isik/v3/VitalparameterUndKoerpermasze/ImplementationGuide|3.0.0"
* date = "2024-01-05"
* implementationGuide = "https://gematik.de/fhir/isik/v3/VitalparameterUndKoerpermasze/ImplementationGuide|3.0.1"
* url = "https://gematik.de/fhir/isik/v3/VitalparameterUndKoerpermasze/CapabilityStatement/vitalparameter-server"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "de.gematik.isik-vitalparameter",
"version": "3.0.0",
"version": "3.0.1",
"description": "Package Release des ISiK Modul Vitalparameter und Körpermaße",
"fhirVersions": [
"4.0.1"
Expand Down
26 changes: 26 additions & 0 deletions scripts/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package.json:
- type: version
regex: '("version":\s*")([\d\.]+.*)(")'
sushi-config.yaml:
- type: version
regex: '(version:\s*)(\d+\.\d+\.\d+.*)()'
ruleset.fsh:
- type: version
regex:
- '(\*\s*version\s*=\s*")([\d\.]+.*)(")'
- '(\*\s*\^version\s*=\s*")([\d\.]+.*)(")'
- '(\*\s*implementationGuide\s*=\s*".*\|)([\d\.]+.*)(")'
- type: date
regex:
- '(\*\s*date\s*=\s*")(\d+\-\d+\-\d+)(")'
- '(\*\s*\^date\s*=\s*")(\d+\-\d+\-\d+)(")'
format: '%Y-%m-%d'
Einfuehrung.md:
- type: version
regex: '(Version: \s*)(\d+\.\d+\.\d+.*)()'
- type: date
regex: '(Datum:\s*)(\d+\.\d+\.\d+.*)()'
format: '%d.%m.%Y'
ImplementierungsleitfadenIsiK_basismodul.json:
- type: version
regex: '("version":\s*")(\d+\.\d+\.\d+.*)(",)'
185 changes: 86 additions & 99 deletions scripts/release_publish.py
Original file line number Diff line number Diff line change
@@ -1,127 +1,104 @@
import datetime
import re
import subprocess
import os
import argparse
from datetime import date
import yaml

class FileWithVersionToUpdate:
def __init__(self, filename, version_regex) -> None:
self.filename = filename
self.version_regex = version_regex
self.location = None

def set_file_location(self, location):
self.location = location

class FileWithDateToUpdate:
def __init__(self, filename, date_regex) -> None:
class FileTypeCombinationToUpdate:
def __init__(self, filename, content_type, regex_list, format=None) -> None:
self.filename = filename
self.date_regex = date_regex
self.content_type = content_type
self.regex_list = regex_list
self.format = format
self.location = None

def set_file_location(self, location):
self.location = location

# class FileWithDateToUpdate:
# def __init__(self, filename, date_regex, format) -> None:
# self.filename = filename
# self.date_regex = date_regex
# self.location = None
# self.format = format
# def set_file_location(self, location):
# self.location = location



def load_config_file(config_file_path):
with open(config_file_path, 'r') as config_file:
return yaml.safe_load(config_file)

def get_new_release_version_from_branch_name() -> str:
git_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode()
return git_branch

def replace_version_in_files(files : list, new_release_version: str):
if files is None:
print("Error: No Files found!")
return

for file in files:
replace_version_in_file(file,new_release_version)
def create_files_to_update_list(config):
files_to_update = []
for filename, replacements in config.items():
for replacement in replacements:
files_to_update.append(
FileTypeCombinationToUpdate(
filename,
replacement["type"],
replacement["regex"] if isinstance(replacement["regex"], list) else [replacement["regex"]],
replacement.get("format", None),
)
)
return files_to_update

def replace_version_in_file(file: FileWithVersionToUpdate,new_release_version: str):
with open(file.location, 'r') as input_file:
input_text = input_file.read()

output_text = re.sub(file.version_regex, rf'\g<1>{new_release_version}\g<3>', input_text)
print(f"Info: Replaced version with '{new_release_version}' in file '{file.location}'.")
def locate_files_in_current_project(files: list):
located_files = []
for current_file in files:
file_location = find_file(current_file.filename, ".")
if file_location is not None:
current_file.set_file_location(file_location)
located_files.append(current_file)
else:
print(f"Warning: File '{current_file.filename}' not found.")
return located_files

with open(file.location, 'w') as output_file:
output_file.write(output_text)

def replace_date_in_files(files : list, new_release_date: str):
def find_file(name, path="."):
for root, dirs, files in os.walk(path):
if name in files:
print(f"Info: Found '{name}' in {root}.")
return os.path.join(root, name)
return None


def replace_content_in_files(files: list, new_release_version: str, new_date: datetime):
if files is None:
print("Error: No Files found!")
print("Error: No files found!")
return

for file in files:
replace_date_in_file(file,new_release_date)
for FileTypeCombination in files:
if FileTypeCombination.content_type == "version":
replace_version_in_file(FileTypeCombination, new_release_version)
elif FileTypeCombination.content_type == "date":
replace_date_in_file(FileTypeCombination, new_date)


def replace_date_in_file(file: FileWithVersionToUpdate, new_date: str):
def replace_version_in_file(file: FileTypeCombinationToUpdate, new_release_version: str):
with open(file.location, 'r') as input_file:
input_text = input_file.read()

#output_text = re.sub(file.date_regex, rf'\g<1>{new_date.strftime(file.format)}\g<3>', input_text) #see https://www.programiz.com/python-programming/datetime#:~:text=Python%20format%20datetime&text=It%27s%20more%20common%20to%20use,()%20methods%20to%20handle%20this.
output_text = re.sub(file.date_regex, rf'\g<1>{new_date}\g<3>', input_text)
print(f"Info: Replaced date with '{new_date}' in file '{file.location}'.")
for regex in file.regex_list:
input_text = re.sub(regex, rf'\g<1>{new_release_version}\g<3>', input_text)

print(f"Info: Replaced version with '{new_release_version}' in file '{file.location}'.")

with open(file.location, 'w') as output_file:
output_file.write(output_text)

def get_file_to_update_version_list():
file_list = []
file_list.append(FileWithVersionToUpdate('package.json', r'("version":\s*")([\d\.]+.*)(")'))
file_list.append(FileWithVersionToUpdate('sushi-config.yaml', r'(version:\s*")(\d+\.\d+\.\d+.*)(")'))
file_list.append(FileWithVersionToUpdate('ruleset.fsh', r'(\*\s*version\s*=\s*")([\d\.]+.*)(")'))
file_list.append(FileWithVersionToUpdate('ruleset.fsh', r'(\*\s*\^version\s*=\s*")([\d\.]+.*)(")'))
file_list.append(FileWithVersionToUpdate('Einfuehrung.md', r'(Version: \s*)(\d+\.\d+\.\d+.*)()'))
file_list.append(FileWithVersionToUpdate('ImplementierungsleitfadenIsiK_basismodul.json', r'("version":\s*")([\d\.]+.*)(")'))
file_list.append(FileWithVersionToUpdate('ImplementierungsleitfadenIsiK_Terminplanung.json', r'("version":\s*")([\d\.]+.*)(")'))
return file_list

def get_file_to_update_date_list():
file_list = []
#file_list.append(FileWithDateToUpdate('ruleset.fsh', r'(date\s*=\s*")(\d+\-\d+\-\d+)(")'), '%m/%d/%Y' )
#file_list.append(FileWithDateToUpdate('Einfuehrung.md', r'(Datum: \s*)(\d+\.\d+\.\d+)()') , '%m/%d/%Y')
file_list.append(FileWithDateToUpdate('ruleset.fsh', r'(\*\s*date\s*=\s*")(\d+\-\d+\-\d+)(")'))
file_list.append(FileWithDateToUpdate('ruleset.fsh', r'(\*\s*\^date\s*=\s*")(\d+\-\d+\-\d+)(")'))
file_list.append(FileWithDateToUpdate('Einfuehrung.md', r'(Datum:\s*)(\d+\.\d+\.\d+.*)()'))
return file_list
output_file.write(input_text)


def locate_files_in_current_project(files: list):
return_list = []
for current_file in files:
file_location = find_file(current_file.filename, ".")
if file_location is not None:
current_file.set_file_location(file_location)
return_list.append(current_file)
else:
print(f"Warning: File '{current_file.filename}' not found.")
return return_list
def replace_date_in_file(file: FileTypeCombinationToUpdate, new_date: datetime):
with open(file.location, 'r') as input_file:
input_text = input_file.read()

def find_file(name, path="."):
for root, dirs, files in os.walk(path):
for regex in file.regex_list:
input_text = re.sub(regex, rf'\g<1>{new_date.strftime(file.format)}\g<3>', input_text)

if name in files:
print(f"Info: Found '{name}' in {root}.")
return os.path.join(root, name)
return None
print(f"Info: Replaced date with '{new_date.strftime(file.format)}' in file '{file.location}'.")

def get_latest_release_tag():
cmd = 'git describe --abbrev=0 --tags --match "v*.*.*" HEAD'
try:
output = subprocess.check_output(cmd, shell=True)
return output.decode().strip()
except subprocess.CalledProcessError:
return None
with open(file.location, 'w') as output_file:
output_file.write(input_text)

def output_commit_messages_since_last_release():
latest_release_tag = get_latest_release_tag()
Expand All @@ -136,15 +113,22 @@ def output_commit_messages_since_last_release():
except subprocess.CalledProcessError:
print("Warning: Failed to get commit messages.")

def main():
today = date.today()
def get_latest_release_tag():
cmd = 'git describe --abbrev=0 --tags --match "v*.*.*" HEAD'
try:
output = subprocess.check_output(cmd, shell=True)
return output.decode().strip()
except subprocess.CalledProcessError:
return None

parser = argparse.ArgumentParser(description='Update release version number')

def main():
parser = argparse.ArgumentParser(description='Update release version number and date')
parser.add_argument('-b', '--branch', action='store_true', help='get new version from branch name')
parser.add_argument('-v', '--version', type=str, help='specify new version number')
parser.add_argument('-d', '--date', type=str, help='specify custom date for release')
parser.add_argument('-c', '--config', type=str, default='config.yaml', help='specify config file')
parser.add_argument('-o', '--output', action='store_true', help='output commit messages since last release')
# TODO new argument -d if not date_time now

args = parser.parse_args()

if args.version:
Expand All @@ -154,16 +138,19 @@ def main():
else:
parser.error('No new release version specified. Please use either -v or -b to specify the new release version.')

if args.output:
output_commit_messages_since_last_release()
if args.date:
custom_date = datetime.datetime.strptime(args.date, '%d.%m.%Y').date()
else:
custom_date = date.today()

file_to_update_version_list = get_file_to_update_version_list()
file_version_list = locate_files_in_current_project(file_to_update_version_list)
replace_version_in_files(file_version_list, new_release_version)
config_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), args.config)
config = load_config_file(config_file_path)
files_to_update = create_files_to_update_list(config)
located_files = locate_files_in_current_project(files_to_update)
replace_content_in_files(located_files, new_release_version, custom_date)

file_to_update_date_list = get_file_to_update_date_list()
file_date_list = locate_files_in_current_project(file_to_update_date_list)
replace_date_in_files(file_date_list, today)
if args.output:
output_commit_messages_since_last_release()

if __name__ == "__main__":
main()
13 changes: 0 additions & 13 deletions scripts/update_version.sh

This file was deleted.

0 comments on commit 3469918

Please sign in to comment.