Skip to content

Commit

Permalink
Merge branch other/next-release into main
Browse files Browse the repository at this point in the history
  • Loading branch information
anionDev committed Jan 21, 2023
2 parents b3bbf0c + 1dc78c2 commit 540096b
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 12 deletions.
1 change: 1 addition & 0 deletions .vscode/spellright.dict
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ docfx
cyclonedx
gitversion
dockerfile
pyOpenSSL
1 change: 1 addition & 0 deletions License.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ScriptCollection uses dependencies which are released under their own license:
-keyboard is licensed under the terms of the MIT-license (see appendix 1)
-lxml is licensed under the terms of the BSD-license (see https://pypi.org/project/lxml )
-ntplib is licensed under the terms of the MIT-license (see appendix 1)
-pyOpenSSL is licensed under the terms of the Apache License, Version 2.0-license (see https://raw.githubusercontent.com/pyca/pyopenssl/main/LICENSE )
-PyPDF2 is licensed under the terms of its own license (see appendix 2)
-pycdlib is licensed under the terms of the LGPL-v2.1-license (see appendix 3)
-qrcode is licensed under the terms of the BSD-license (see https://pypi.org/project/qrcode )
Expand Down
5 changes: 5 additions & 0 deletions Other/Resources/Changelog/v3.3.50.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release notes

## Changes

- Added checks in `scbuildcodeunits`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<coverage version="1.0" date="2023-01-21_17-55-04" tag="v3.3.50">
<assembly name="ScriptCollection">
<class name="Executables.py" coveredlines="0" coverablelines="233" totallines="336" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="GeneralUtilities.py" coveredlines="424" coverablelines="680" totallines="810" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="Hardening.py" coveredlines="0" coverablelines="32" totallines="59" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="ProgramRunnerBase.py" coveredlines="22" coverablelines="28" totallines="42" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="ProgramRunnerEpew.py" coveredlines="40" coverablelines="103" totallines="122" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="ProgramRunnerPopen.py" coveredlines="25" coverablelines="37" totallines="50" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="ScriptCollectionCore.py" coveredlines="490" coverablelines="1090" totallines="1440" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="TasksForCommonProjectStructure.py" coveredlines="257" coverablelines="1013" totallines="1370" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
<class name="UpdateCertificates.py" coveredlines="0" coverablelines="105" totallines="128" coveredbranches="0" totalbranches="0" coveredcodeelements="0" totalcodeelements="0" />
</assembly>
</coverage>
2 changes: 1 addition & 1 deletion ScriptCollection/ScriptCollection.codeunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<cps:codeunit xmlns:cps="https://projects.aniondev.de/PublicProjects/Common/ProjectTemplates/-/tree/main/Conventions/RepositoryStructure/CommonProjectStructure" codeunitspecificationversion="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://projects.aniondev.de/PublicProjects/Common/ProjectTemplates/-/raw/main/Conventions/RepositoryStructure/CommonProjectStructure/codeunit.xsd">
<cps:name>ScriptCollection</cps:name>
<cps:version>3.3.49</cps:version>
<cps:version>3.3.50</cps:version>
<cps:minimalcodecoverageinpercent>30</cps:minimalcodecoverageinpercent>
<cps:dependentcodeunits></cps:dependentcodeunits>
</cps:codeunit>
17 changes: 17 additions & 0 deletions ScriptCollection/ScriptCollection/GeneralUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from shutil import copyfile
import typing
from defusedxml.minidom import parse
from OpenSSL import crypto


class GeneralUtilities:
Expand Down Expand Up @@ -791,3 +792,19 @@ def generate_password(length: int = 16, alphabet: str = None) -> None:
def assert_condition(condition: bool, information: str) -> None:
if (not condition):
raise ValueError("Condition failed. "+information)

@staticmethod
@check_arguments
def get_certificate_expiry_date(certificate_file: str) -> datetime:
with open(certificate_file, encoding="utf-8") as certificate_file_content:
cert = crypto.load_certificate(crypto.FILETYPE_PEM, certificate_file_content.read())
date_as_bytes = cert.get_notAfter()
date_as_string = date_as_bytes.decode("utf-8")
result = datetime.strptime(date_as_string, '%Y%m%d%H%M%SZ')
return result


@staticmethod
@check_arguments
def certificate_is_expired(certificate_file: str) -> bool:
return GeneralUtilities.get_certificate_expiry_date(certificate_file) < datetime.now()
2 changes: 1 addition & 1 deletion ScriptCollection/ScriptCollection/ScriptCollectionCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .ProgramRunnerEpew import ProgramRunnerEpew, CustomEpewArgument


version = "3.3.49"
version = "3.3.50"
__version__ = version


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def get_property_from_commandline_arguments(commandline_arguments: list[str], pr
return result

@GeneralUtilities.check_arguments
def update_version_of_codeunit_to_project_version(self, common_tasks_file: str, current_version: str) -> None:
def update_version_of_codeunit(self, common_tasks_file: str, current_version: str) -> None:
codeunit_name: str = os.path.basename(GeneralUtilities.resolve_relative_path("..", os.path.dirname(common_tasks_file)))
codeunit_file: str = os.path.join(GeneralUtilities.resolve_relative_path("..", os.path.dirname(common_tasks_file)), f"{codeunit_name}.codeunit.xml")
self.write_version_to_codeunit_file(codeunit_file, current_version)
Expand Down Expand Up @@ -478,7 +478,7 @@ def generate_sbom_for_dotnet_project(self, codeunit_folder: str, verbosity: int,
sc = ScriptCollectionCore()
bomfile_folder = "Other\\Artifacts\\BOM"
verbosity = TasksForCommonProjectStructure.get_verbosity_from_commandline_arguments(commandline_arguments, verbosity)
sc.run_program("dotnet", f"CycloneDX {codeunit_name}\\{codeunit_name}.csproj -o {bomfile_folder}", codeunit_folder, verbosity=verbosity)
sc.run_program("dotnet", f"CycloneDX {codeunit_name}\\{codeunit_name}.csproj -o {bomfile_folder} --disable-github-licenses", codeunit_folder, verbosity=verbosity)
codeunitversion = self.get_version_of_codeunit(os.path.join(codeunit_folder, f"{codeunit_name}.codeunit.xml"))
target = f"{codeunit_folder}\\{bomfile_folder}\\{codeunit_name}.{codeunitversion}.sbom.xml"
GeneralUtilities.ensure_file_does_not_exist(target)
Expand Down Expand Up @@ -965,6 +965,7 @@ def standardized_tasks_do_common_tasks(self, common_tasks_scripts_file: str, ver
repository_folder: str = str(Path(os.path.dirname(common_tasks_scripts_file)).parent.parent.absolute())
codeunitname: str = str(os.path.basename(Path(os.path.dirname(common_tasks_scripts_file)).parent.absolute()))
verbosity = TasksForCommonProjectStructure.get_verbosity_from_commandline_arguments(commandline_arguments, verbosity)
project_version = self.get_version_of_project(repository_folder)

# Clear previously builded artifacts if desired:
if clear_artifacts_folder:
Expand Down Expand Up @@ -996,17 +997,15 @@ def standardized_tasks_do_common_tasks(self, common_tasks_scripts_file: str, ver
self.build_dependent_code_units(repository_folder, codeunitname, verbosity, target_environmenttype, additional_arguments_file)
self.copy_artifacts_from_dependent_code_units(repository_folder, codeunitname)

# Update version
self.update_version_of_codeunit_to_project_version(common_tasks_scripts_file, version)
# Update codeunit-version
self.update_version_of_codeunit(common_tasks_scripts_file, version)

# set default constants
self.set_default_constants(os.path.join(repository_folder, codeunitname))

# Check if changelog exists
# Copy changelog-file
changelog_folder = os.path.join(repository_folder, "Other", "Resources", "Changelog")
changelog_file = os.path.join(changelog_folder, f"v{version}.md")
if not os.path.isfile(changelog_file):
raise ValueError(f"Changelog-file '{changelog_file}' does not exist.")
changelog_file = os.path.join(changelog_folder, f"v{project_version}.md")
target_folder = os.path.join(repository_folder, codeunitname, "Other", "Artifacts", "Changelog")
GeneralUtilities.ensure_directory_exists(target_folder)
shutil.copy(changelog_file, target_folder)
Expand Down Expand Up @@ -1241,6 +1240,7 @@ def build_codeunits(self, repository_folder: str, verbosity: int = 1, target_env
if os.path.exists(codeunit_file):
codeunits[codeunit_name] = self.get_dependent_code_units(codeunit_file)
sorted_codeunits = self._internal_sort_codenits(codeunits)
project_version = self.get_version_of_project(repository_folder)
if len(sorted_codeunits) == 0:
raise ValueError(f'No codeunit found in subfolders of "{repository_folder}".')
else:
Expand All @@ -1250,11 +1250,11 @@ def build_codeunits(self, repository_folder: str, verbosity: int = 1, target_env
for codeunit in sorted_codeunits:
i = i+1
GeneralUtilities.write_message_to_stdout(f"{i}.: {codeunit}")
self.__do_repository_checks(repository_folder, project_version)
for codeunit in sorted_codeunits:
self.__build_codeunit(os.path.join(repository_folder, codeunit), verbosity, target_environmenttype, additional_arguments_file, is_pre_merge, True)
if export_target_directory is not None:
project_name = os.path.basename(repository_folder)
project_version = self.get_version_of_project(repository_folder)
for codeunit in sorted_codeunits:
codeunit_version = self.get_version_of_codeunit_folder(os.path.join(repository_folder, codeunit))
artifacts_folder = os.path.join(repository_folder, codeunit, "Other", "Artifacts")
Expand All @@ -1266,6 +1266,21 @@ def build_codeunits(self, repository_folder: str, verbosity: int = 1, target_env
archive_file = os.path.join(os.getcwd(), f"{filename_without_extension}.zip")
shutil.move(archive_file, target_folder)

@GeneralUtilities.check_arguments
def __do_repository_checks(self, repository_folder: str, project_version: str):
self.__check_if_changelog_exists(repository_folder, project_version)

@GeneralUtilities.check_arguments
def __check_whether_atifacts_exists(self, codeunit_folder: str):
pass # TODO

@GeneralUtilities.check_arguments
def __check_if_changelog_exists(self, repository_folder: str, project_version: str):
changelog_folder = os.path.join(repository_folder, "Other", "Resources", "Changelog")
changelog_file = os.path.join(changelog_folder, f"v{project_version}.md")
if not os.path.isfile(changelog_file):
raise ValueError(f"Changelog-file '{changelog_file}' does not exist.")

@GeneralUtilities.check_arguments
def __build_codeunit(self, codeunit_folder: str, verbosity: int = 1, target_environmenttype: str = "QualityCheck", additional_arguments_file: str = None,
is_pre_merge: bool = False, assume_dependent_codeunits_are_already_built: bool = False) -> None:
Expand Down Expand Up @@ -1351,4 +1366,5 @@ def __build_codeunit(self, codeunit_folder: str, verbosity: int = 1, target_envi
# TODO validate artifactsinformation_file against xsd
shutil.copyfile(codeunit_file,
os.path.join(artifacts_folder, f"{codeunit_name}.codeunit.xml"))
self.__check_whether_atifacts_exists(codeunit_folder)
GeneralUtilities.write_message_to_stdout(f"Finished building codeunit {codeunit_name}.")
1 change: 1 addition & 0 deletions ScriptCollection/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lxml
ntplib>=0.4.0
pycdlib>=1.13.0
pylint>=2.15.10
pyOpenSSL>=23.0.0
PyPDF2>=3.0.1
pytest>=7.2.1
qrcode>=7.3.1
Expand Down
3 changes: 2 additions & 1 deletion ScriptCollection/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ScriptCollection
version = 3.3.49
version = 3.3.50
author = Marius Göcke
author_email = [email protected]
description = The ScriptCollection is the place for reusable scripts.
Expand Down Expand Up @@ -40,6 +40,7 @@ install_requires =
ntplib>=0.4.0
pycdlib>=1.13.0
pylint>=2.15.10
pyOpenSSL>=23.0.0
PyPDF2>=3.0.1
pytest>=7.2.1
qrcode>=7.3.1
Expand Down

0 comments on commit 540096b

Please sign in to comment.