From b034bba7d6653d929f76e0bf2efbf81254de35aa Mon Sep 17 00:00:00 2001 From: Arda Kutlu Date: Tue, 17 Dec 2024 16:14:09 +0000 Subject: [PATCH] ends --- .github/workflows/deploy.yml | 16 ++++++++++++++ package/release_package.py | 42 +++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2668012..22bae28 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -78,6 +78,22 @@ jobs: if not exist "package\build\TikManager4_v${{ env.VERSION }}.exe" exit 1 shell: cmd + - name: Read Sanitized Release Notes + id: read_release_notes + run: | + sanitized_notes_file="package/build/ReleaseNotes_v${{ env.VERSION }}.md" + + if [ ! -f "$sanitized_notes_file" ]; then + echo "Error: Sanitized release notes not found: $sanitized_notes_file" + exit 1 + fi + + release_notes=$(cat "$sanitized_notes_file") + echo "release_notes<> $GITHUB_ENV + echo "$release_notes" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + shell: bash + - name: Upload Release Assets uses: actions/upload-artifact@v3 with: diff --git a/package/release_package.py b/package/release_package.py index 9231bca..b94d5cf 100644 --- a/package/release_package.py +++ b/package/release_package.py @@ -7,6 +7,8 @@ # set the TIK_DCC environment variable os.environ["TIK_DCC"] = "null" +import logging +import re import subprocess from pathlib import Path @@ -17,8 +19,8 @@ INNO_SETUP_EXE = Path("C:\\Program Files (x86)\\Inno Setup 6\\ISCC.exe") PACKAGE_ROOT = Path(__file__).parent -# INNO_SCRIPT = Path(__file__).parent / "tik_manager4_innosetup_debug.iss" +LOG = logging.getLogger(__name__) class ReleaseUtility: """Class to handle the releases.""" @@ -32,14 +34,18 @@ def __init__(self, debug_mode=False): def freeze(self): """Freeze the application using pyinstaller.""" + LOG.info("\nStarting Freeze Process.\n") subprocess.call( ["pyinstaller", self.spec_file_name, "--clean", "--noconfirm"], cwd=self.tik_root, shell=True, ) + LOG.info("Freeze Process Completed.") + LOG.info("-------------------------") def inno_setup(self): """Compile the installer using inno setup.""" + LOG.info("\nStarting Inno Setup.\n") if not INNO_SETUP_EXE.exists(): raise FileNotFoundError("Inno Setup not found at the specified location.") sys.stdout.write("Starting Inno Setup.") @@ -50,7 +56,40 @@ def inno_setup(self): injector.replace_single_line(app_line, "#define appVersion") subprocess.call([str(INNO_SETUP_EXE), str(self.inno_script_path)], shell=True) + LOG.info("Inno Setup completed.") + LOG.info("---------------------") + def extract_and_sanitize_release_notes(self): + """Extract and sanitize the release notes.""" + LOG.info("\nExtracting and sanitizing release notes.\n") + relase_notes = PACKAGE_ROOT.parent / "RELEASE_NOTES.md" + content = relase_notes.read_text() + + # Match the target version section and capture its notes + version_pattern = re.compile( + rf"##\s+v{re.escape(self.release_version)}\n(.*?)(?:\n##|$)", + re.DOTALL + ) + + match = version_pattern.search(content) + if not match: + sanitized_notes = "No release notes found." + LOG.warning(f"Version v%s not found in release notes.", self.release_version) + else: + notes = match.group(1).strip() + # Remove brackets and their content + sanitized_notes = re.sub(r"\[.*?\]\s*", "", notes) + + (PACKAGE_ROOT / "build").mkdir(exist_ok=True) + + # add the ## What's Changed at the beginning of the sanitized notes + sanitized_notes = f"## What's Changed\n\n{sanitized_notes}" + + output_file = PACKAGE_ROOT / "build" / f"ReleaseNotes_v{self.release_version}.md" + output_file.write_text(sanitized_notes) + + LOG.info("Release notes extracted and saved to %s", output_file) + return output_file if __name__ == "__main__": # get the arguments from sys @@ -59,5 +98,6 @@ def inno_setup(self): _debug_mode = any([opt in ("-d", "--debug") for opt, _ in opts]) release_utility = ReleaseUtility(debug_mode=_debug_mode) release_utility.freeze() + release_utility.extract_and_sanitize_release_notes() if not _debug_mode: release_utility.inno_setup()