diff --git a/scripts/build.ps1 b/scripts/build.ps1 index edb0a24..6c06222 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -1 +1,115 @@ -pdm build -d build/ \ No newline at end of file +$DEPLOYMENT_PATH = 'B:\deployments\EKF-Diagnostics' +$ENV_PATH = 'B:\deployments\EKF-Diagnostics\dopt_ekf_sensor-anomalies' +$PY_PATH = Join-Path -Path $ENV_PATH -ChildPath 'python' +$SRC_PATH = (Get-Location).Path + +Write-Output "Build Pipeline for d-opt EKF-Diagnostics sensor anomaly detection" +Write-Output "Building package..." +.\scripts\publish.ps1 +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were build errors" + Exit +} +Write-Output "Built package successfully" + +# manual +Write-Output "Generate manual..." +.\scripts\cvt_manual.ps1 +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there errors while generating the README file" + Exit +} +Write-Output "Generated manual file successfully" +Write-Output "Copying manual file..." +$readme_src_path = Join-Path -Path $SRC_PATH -ChildPath 'docs\manual.pdf' +$readme_dest_path = Join-Path -Path $ENV_PATH -ChildPath 'manual' +Copy-Item -Path $readme_src_path -Destination $readme_dest_path -Force +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors while copying the manual file" + Exit +} +Write-Output "Copied manual file successfully" + + +Write-Output "Go into env directory..." +Set-Location $ENV_PATH +Write-Output "Install package into environment..." +pycage venv add -p -i http://localhost:8001/simple/ dopt-sensor-anomalies +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors while installing the package into the environment" + Exit +} +Write-Output "Successfully installed package" + +# copy CLI file +Write-Output "Copying CLI script file..." +$cli_path = Join-Path -Path $SRC_PATH -ChildPath 'cli.py' +Copy-Item -Path $cli_path -Destination $PY_PATH -Force +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors while copying the CLI script file" + Exit +} +Write-Output "Copied CLI script file successfully" + +# copy model files +Write-Output "Copying model weight files..." +$model_src_path = Join-Path -Path $SRC_PATH -ChildPath 'tests\_models\' +$model_dest_path = Join-Path -Path $ENV_PATH -ChildPath 'models' +Copy-Item -Path "$model_src_path\*.pth" -Destination $model_dest_path -Force +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors while copying the model weight files" + Exit +} +Write-Output "Copied model weight files successfully" + + +# env preparation +Write-Output "Preparing environment with cleanup and pre-compilation..." +pycage clean dist-info +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors while deleting the distribution info files" + Exit +} +pycage compile -q -d -f +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors during the pre-compilation process" + Exit +} +Write-Output "Successfully prepared environment with cleanup and pre-compilation" + +Write-Output "Get version string..." +$pyproject = Get-Content $SRC_PATH\pyproject.toml -Raw + +if ($pyproject -match '\[project\].*?\n[\s\w\n=""-_{}]*\[[\w-]*\]') { + $projectBlock = $matches[0] + if ($projectBlock -match 'version\s*=\s*"([^"]+)"') { + $version = $matches[1] + Write-Output "The version string is: $version" + } + else { + Write-Output "[PWSH] Exiting script because the version string was not found" + Exit + } +} +else { + Write-Output "[PWSH] Exiting script because the version string was not found" + Exit +} + +Write-Output "Packaging whole standalone environment in a ZIP file" +$dest_path = Join-Path -Path $DEPLOYMENT_PATH -ChildPath "dopt_ekf_sensor-anomalies_v$version.zip" +$compress = @{ + Path = "$ENV_PATH\**" + CompressionLevel = "Optimal" + DestinationPath = $dest_path +} +Compress-Archive @compress -Force + +if ($? -eq $false){ + Write-Output "[PWSH] Exiting script because there were errors during the archive compression operation" + Exit +} +Write-Output "Successfully compressed archive. Saved under: >$dest_path<" + +Write-Output "Go back to source directory..." +Set-Location $SRC_PATH diff --git a/scripts/build_pdm.ps1 b/scripts/build_pdm.ps1 new file mode 100644 index 0000000..edb0a24 --- /dev/null +++ b/scripts/build_pdm.ps1 @@ -0,0 +1 @@ +pdm build -d build/ \ No newline at end of file