From 2a79d801647674f6d3e012769a79539a46034c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Job?= Date: Fri, 11 Oct 2024 09:42:31 +0200 Subject: [PATCH] Build and sign Windows installer (#1702) --- scripts/packaging/win/build_installer.bat | 101 ++++++++++++++-------- scripts/packaging/win/build_version.py | 2 +- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/scripts/packaging/win/build_installer.bat b/scripts/packaging/win/build_installer.bat index 8efe849487..b740324d3a 100644 --- a/scripts/packaging/win/build_installer.bat +++ b/scripts/packaging/win/build_installer.bat @@ -1,37 +1,68 @@ @echo on -REM replace with one from environment -set RELEASE_TYPE=dev - -aws s3 ls %STAGE_URL% --recursive - -heat.exe /? -candle.exe /? -light.exe /? - - -REM heat.exe dir dist\\snow\\_internal ^ -REM -gg ^ -REM -cg SnowflakeCLIInternalFiles ^ -REM -dr TESTFILEPRODUCTDIR ^ -REM -var var.SnowflakeCLIInternalFiles ^ -REM -sfrag ^ -REM -o _internal.wxs -REM -REM candle.exe ^ -REM -arch x64 ^ -REM -dSnowflakeCLIVersion=%CLI_VERSION% ^ -REM -dSnowflakeCLIInternalFiles=dist\\snow\\_internal ^ -REM scripts\packaging\win\snowflake_cli.wxs ^ -REM scripts\packaging\win\snowflake_cli_exitdlg.wxs ^ -REM _internal.wxs -REM -REM light.exe ^ -REM -ext WixUIExtension ^ -REM -ext WixUtilExtension ^ -REM -cultures:en-us ^ -REM -loc scripts\packaging\win\snowflake_cli_en-us.wxl ^ -REM -out snowflake-cli-%CLI_VERSION%-x86_64.msi ^ -REM snowflake_cli.wixobj ^ -REM snowflake_cli_exitdlg.wixobj ^ -REM _internal.wixobj +set PATH=C:\Program Files\7-Zip;C:\Users\jenkins\AppData\Local\Programs\Python\Python38;C:\Users\jenkins\AppData\Local\Programs\Python\Python38\Scripts;C:\Program Files (x86)\WiX Toolset v3.11\bin;%PATH% + +python.exe --version +python.exe -c "import platform as p; print(f'{p.system()=}, {p.architecture()=}')" + +python.exe -m pip install hatch +FOR /F "delims=" %%I IN ('hatch run packaging:win-build-version') DO SET CLI_VERSION=%%I +FOR /F "delims=" %%I IN ('git rev-parse %svnRevision%') DO SET REVISION=%%I +FOR /F "delims=" %%I IN ('echo %releaseType%') DO SET RELEASE_TYPE=%%I + +echo CLI_VERSION = %CLI_VERSION% +echo REVISION = %REVISION%` +echo RELEASE_TYPE = %RELEASE_TYPE%` + +set CLI_ZIP=snowflake-cli-%CLI_VERSION%.zip +set CLI_MSI=snowflake-cli-%CLI_VERSION%-x86_64.msi +set STAGE_URL=s3://sfc-eng-jenkins/repository/snowflake-cli/staging/%RELEASE_TYPE%/windows_x86_64/%REVISION% +set RELEASE_URL=s3://sfc-eng-jenkins/repository/snowflake-cli/%RELEASE_TYPE%/windows_x86_64/%REVISION% + +echo "[INFO] downloading artifacts" +cmd /c aws s3 cp %STAGE_URL%/%CLI_ZIP% . || goto :error + +echo "[INFO] building installer" +7z x %CLI_ZIP% || goto :error + +signtool sign /debug /sm /d "Snowflake CLI" /t http://timestamp.digicert.com /a dist\snow\snow.exe || goto :error +signtool verify /v /pa dist\snow\snow.exe || goto :error + +heat.exe dir dist\snow\_internal ^ + -gg ^ + -cg SnowflakeCLIInternalFiles ^ + -dr TESTFILEPRODUCTDIR ^ + -var var.SnowflakeCLIInternalFiles ^ + -sfrag ^ + -o _internal.wxs || goto :error + +candle.exe ^ + -arch x64 ^ + -dSnowflakeCLIVersion=%CLI_VERSION% ^ + -dSnowflakeCLIInternalFiles=dist\\snow\\_internal ^ + scripts\packaging\win\snowflake_cli.wxs ^ + scripts\packaging\win\snowflake_cli_exitdlg.wxs ^ + _internal.wxs || goto :error + +light.exe ^ + -ext WixUIExtension ^ + -ext WixUtilExtension ^ + -cultures:en-us ^ + -loc scripts\packaging\win\snowflake_cli_en-us.wxl ^ + -out %CLI_MSI% ^ + snowflake_cli.wixobj ^ + snowflake_cli_exitdlg.wixobj ^ + _internal.wixobj || goto :error + +signtool sign /debug /sm /d "Snowflake CLI" /t http://timestamp.digicert.com /a %CLI_MSI% || goto :error +signtool verify /v /pa %CLI_MSI% || goto :error + +echo "[INFO] uploading artifacts" +cmd /c aws s3 cp %CLI_MSI% %RELEASE_URL%/%CLI_MSI% || goto :error + +REM FINISH SCRIPT EXECUTION HERE +GOTO :EOF + +:error +echo Failed with error code #%errorlevel%. +exit /b %errorlevel% diff --git a/scripts/packaging/win/build_version.py b/scripts/packaging/win/build_version.py index 204f1a8365..4682f6b15b 100644 --- a/scripts/packaging/win/build_version.py +++ b/scripts/packaging/win/build_version.py @@ -17,7 +17,7 @@ def parse_version_for_windows_build() -> list[str]: case last if "dev" in last: version = msv + last.split("dev") - return version + return [segment for segment in version if segment] if __name__ == "__main__":