Skip to content

Commit

Permalink
CI - automate windows .msi packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Dec 20, 2024
1 parent c7d324a commit 82da69c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
44 changes: 20 additions & 24 deletions .github/workflows/dev-nightly-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ jobs:
with:
ref: dev

- name: Install build tools (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt update && sudo apt install -y automake libtool autogen mcpp
sudo apt install -y openjdk-21-jdk
sudo apt install -y gcc-multilib
sudo apt install -y gcc-i686-linux-gnu
sudo apt install -y gcc-aarch64-linux-gnu
- name: Install Rust Toolchain (Linux)
if: runner.os == 'Linux'
uses: dtolnay/rust-toolchain@stable

- name: Install Python
uses: actions/setup-python@v5
with:
Expand All @@ -51,32 +37,42 @@ jobs:
run: |
echo "PYTHON=python3" >> $GITHUB_ENV
- name: Create shell envs (Windows)
if: runner.os == 'Windows'
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe > msbuild_path.txt
set /p MSBUILD_PATH=<msbuild_path.txt
set VCVARSALL=%MSBUILD_PATH%\..\..\..\..\VC\Auxiliary\Build\vcvarsall.bat
echo VCVARSALL=%VCVARSALL% >> %GITHUB_ENV%
echo PYTHON=python >> %GITHUB_ENV%
- name: Build dist assets (Linux)
if: runner.os == 'Linux'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
sudo apt update
sudo apt install -y automake libtool autogen mcpp
sudo apt install -y openjdk-21-jdk
sudo apt install -y gcc-multilib
sudo apt install -y gcc-i686-linux-gnu
sudo apt install -y gcc-aarch64-linux-gnu
$PYTHON $GITHUB_WORKSPACE/scripts/package.py
$PYTHON $GITHUB_WORKSPACE/scripts/test-dist.py
- name: Create shell envs (Windows x64)
if: runner.os == 'Windows'
shell: cmd
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe > msbuild_path.txt
set /p MSBUILD_PATH=<msbuild_path.txt
set VCVARSALL=%MSBUILD_PATH%\..\..\..\..\VC\Auxiliary\Build\vcvarsall.bat
echo VCVARSALL=%VCVARSALL% >> %GITHUB_ENV%
echo PYTHON=python >> %GITHUB_ENV%
- name: Build dist assets (Windows x64)
if: runner.os == 'Windows'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: cmd
run: |
call "%VCVARSALL%" x64
dotnet tool install --global wix
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
wix extension add --global WixToolset.UI.wixext
wix extension list --global
%PYTHON% %GITHUB_WORKSPACE%\scripts\package.py
%PYTHON% %GITHUB_WORKSPACE%\scripts\test-dist.py
Expand Down
17 changes: 4 additions & 13 deletions scripts/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import zlib

from utilities.versions import sync_sources_digest, sync_versions
from utilities.common import are_generated_files_git_changed, compare_dir, copy_file_list, create_temp_dir, get_src_generated_files, is_arm64_toolchain_installed, is_cmake_installed, is_debian_based, is_dotnet_installed, is_i386_toolchain_installed, is_redhat_based, is_rpmbuild_installed, is_ubuntu, is_dotnet_installed, is_wix_installed, is_x86_64_toolchain_installed, verify_git_repo, run_command_sudo
from utilities.common import are_generated_files_git_changed, compare_dir, copy_file_list, create_temp_dir, get_src_generated_files, is_arm64_toolchain_installed, is_cmake_installed, is_debian_based, is_dotnet_installed, is_i386_toolchain_installed, is_redhat_based, is_rpmbuild_installed, is_ubuntu, is_dotnet_installed, is_wix_installed, is_x86_64_toolchain_installed, run_command, verify_git_repo, run_command_sudo
from utilities.files import compare_msi_files, compare_tar_gz_files, compare_zip_files, create_rtf_from_txt, create_zip_file, compare_deb_files, force_delete, force_delete_glob, path_join

def delete_other_versions(target_dir: str, file_pattern: str, new_version: str ):
Expand Down Expand Up @@ -86,10 +86,7 @@ def do_cmake_reconfigure(root_dir: str, options: str, sudo_pwd: str = "") ->str:
cmake_command = ['cmake'] + shlex.split(options) + ['..']
formatted_command = ' '.join([f'[{elem}]' for elem in cmake_command])
print("CMake command:", formatted_command) # Display the cmake_command list with brackets
subprocess.run(cmake_command, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: Running CMake configuration {options}: {e}")
sys.exit(1)
run_command(cmake_command)
finally:
# Restore the original working directory
os.chdir(original_dir)
Expand All @@ -101,10 +98,7 @@ def do_cmake_build(build_dir: str):
original_dir = os.getcwd()
try:
os.chdir(build_dir)
subprocess.run(['cmake', '--build', '.'], check=True)
except subprocess.CalledProcessError as e:
print(f"Error running cmake build: {e}")
sys.exit(1)
run_command(['cmake', '--build', '.'])
finally:
# Restore the original working directory
os.chdir(original_dir)
Expand All @@ -114,10 +108,7 @@ def do_cpack_build(build_dir: str):
original_dir = os.getcwd()
try:
os.chdir(build_dir)
subprocess.run(['cpack', '.'], check=True)
except subprocess.CalledProcessError as e:
print(f"Error running CPack: {e}")
sys.exit(1)
run_command(['cpack', '.'])
finally:
# Restore the original working directory
os.chdir(original_dir)
Expand Down
25 changes: 19 additions & 6 deletions scripts/utilities/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import filecmp
import glob
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -182,9 +183,24 @@ def expand_globs(root_dir: str, file_list: list) -> list:

def run_command(command: list) -> str:
"""Run a shell command and return the output."""
result = subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
print(f"Error during '{' '.join(command)}': {result.stderr}")
try:
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode != 0:
print(f"stdout for '{' '.join(command)}': {result.stdout}")
print(f"stderr for '{' '.join(command)}': {result.stderr}")
# If result.stderr contains the string "CPack Error: Problem running WiX.", then
# print the content of the log file at the specified path.
if "CPack Error: Problem running WiX." in result.stderr:
log_file_match = re.search(r"'([^']+)'", result.stderr)
if log_file_match:
log_file = log_file_match.group(1)
if os.path.exists(log_file):
print(f"Contents of {log_file}:")
with open(log_file, 'r') as f:
print(f.read())
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"Error during '{' '.join(command)}': {e}")
sys.exit(1)

return result.stdout.strip()
Expand Down Expand Up @@ -342,6 +358,3 @@ def compare_dir(dir1: str, dir2: str) -> bool:
differences_found = True

return not differences_found



0 comments on commit 82da69c

Please sign in to comment.