From f3a641ee6dc9312ff6134c7f376596f2e1a8c229 Mon Sep 17 00:00:00 2001 From: lepapareil Date: Fri, 23 Sep 2022 09:21:44 +0200 Subject: [PATCH] Convert windows ci jobs commands to powershell scripts --- .github/workflows/release.yml | 46 ++++------------- .github/workflows/test.yml | 52 +++----------------- bin/environment.ps1 | 13 +++++ bin/install_prerequisites_windows.ps1 | 12 +++++ bin/release/create_windows64_installer.ps1 | 14 ++++++ bin/release/create_windows64_zip_package.ps1 | 13 +++++ bin/release/release.ps1 | 22 +++++++++ bin/test/test_integ.ps1 | 9 ++++ bin/test/test_prerequisites.ps1 | 17 +++++++ bin/test/test_unit.ps1 | 4 ++ 10 files changed, 121 insertions(+), 81 deletions(-) create mode 100644 bin/environment.ps1 create mode 100644 bin/install_prerequisites_windows.ps1 create mode 100644 bin/release/create_windows64_installer.ps1 create mode 100644 bin/release/create_windows64_zip_package.ps1 create mode 100644 bin/release/release.ps1 create mode 100644 bin/test/test_integ.ps1 create mode 100644 bin/test/test_prerequisites.ps1 create mode 100644 bin/test/test_unit.ps1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52bd31db9..72d50f6fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,8 +60,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/cache@v3 with: - path: | - C:\vcpkg\installed + path: C:\vcpkg\installed key: ${{ runner.os }}-release-windows-x64-${{ github.sha }} restore-keys: ${{ runner.os }}-release-windows-x64- - name: Install Rust @@ -72,44 +71,17 @@ jobs: profile: minimal - name: Environment run: | - $Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture' - Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize - cargo --version + .\bin\environment.ps1 - name: Build run: | - # vcpkg build prequisites - (Get-Command vcpkg).Path - if (Test-Path C:\vcpkg\installed\x64-windows\lib\libcurl.lib) {echo "curl already installed"} else {vcpkg install curl:x64-windows} - if (Test-Path C:\vcpkg\installed\x64-windows\lib\libxml2.lib) {echo "libxml2 already installed"} else {vcpkg install libxml2:x64-windows} - vcpkg update - vcpkg upgrade - vcpkg integrate install - refreshenv - # fix known win build bugs - (Get-Content .\packages\hurl\src\runner\hurl_file.rs).replace('```', '') | Set-Content .\packages\hurl\src\runner\hurl_file.rs - # build release - cargo build --release --verbose - New-Item -ItemType Directory -Name .\target\win-package - Get-ChildItem -Path '.\target\release' -Recurse -Include *.dll -File | Copy-Item -Destination '.\target\win-package' - Get-ChildItem -Path '.\target\release' -Recurse -Include hurl*.exe -File | Copy-Item -Destination '.\target\win-package' - ((.\target\win-package\hurl.exe --version) -Split " ")[1] > .\target\win-package\version.txt - Get-ChildItem .\target\win-package - Get-Content .\target\win-package\version.txt - - name: Create Zip package and win64 installer + .\bin\install_prerequisites_windows.ps1 + .\bin\release\release.ps1 + - name: Create windows64 Zip package run: | - # create zip - $hurl_package_version = Get-Content .\target\win-package\version.txt - cd .\target\win-package - Get-ChildItem -Path *.dll, *hurl.exe, *hurlfmt.exe, *.txt, ../../*.md -Exclude hex_literal* | Compress-Archive -DestinationPath hurl-${hurl_package_version}-win64.zip - Get-ChildItem .\*win64.zip - cd ..\.. - # create installer - choco install --confirm --no-progress nsis - refreshenv - Get-Command Expand-Archive - Expand-Archive -Path '.\bin\windows\EnVar_plugin.zip' -DestinationPath 'C:\Program Files (x86)\NSIS' -Verbose - cd .\target\win-package - makensis.exe /NOCD /V4 ..\..\bin\windows\hurl.nsi + .\bin\release\create_windows64_zip_package.ps1 + - name: Create windows64 installer + run: | + .\bin\release\create_windows64_installer.ps1 - name: Archive production artifacts uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8a324bcc8..9adbf3929 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -232,8 +232,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/cache@v3 with: - path: | - C:\vcpkg\installed + path: C:\vcpkg\installed key: ${{ runner.os }}-test-windows-x64-${{ github.sha }} restore-keys: ${{ runner.os }}-test-windows-x64- - name: Install Rust @@ -244,48 +243,14 @@ jobs: profile: minimal - name: Environment run: | - $Properties = 'Caption', 'CSName', 'Version', 'BuildType', 'OSArchitecture' - Get-CimInstance Win32_OperatingSystem | Select-Object $Properties | Format-Table -AutoSize - cargo --version - $PsVersionTable - - name: Install build and tests prequisites + .\bin\environment.ps1 + - name: Build and test run: | - # vcpkg build prequisites - (Get-Command vcpkg).Path - if (Test-Path C:\vcpkg\installed\x64-windows\lib\libcurl.lib) {echo "curl already installed"} else {vcpkg install curl:x64-windows} - if (Test-Path C:\vcpkg\installed\x64-windows\lib\libxml2.lib) {echo "libxml2 already installed"} else {vcpkg install libxml2:x64-windows} - vcpkg update - vcpkg upgrade - vcpkg integrate install - refreshenv - # install proxy and server - pip3 install --requirement bin/requirements-frozen.txt - - name: Run Tests units - run: | - cd .\integration - Start-Job -Name mitmdump -ScriptBlock { mitmdump --listen-port 8888 --modify-header "/From-Proxy/Hello" } - Start-Job -Name server -ScriptBlock { python server.py > server.log } - Start-Job -Name server -ScriptBlock { python ssl/server.py > server-ssl.log } - Get-Job -Name server - Get-Job -Name mitmdump - Start-Sleep 5 - cd .. - cargo test --features strict --tests - - name: Run Integration tests - run: | - cargo build --release --verbose --locked - target\release\hurl.exe --version - $execdir=[System.Environment]::SystemDirectory - Get-ChildItem -Path ".\target\release" -Recurse -Include *.dll -File | Copy-Item -Destination "${execdir}" - Get-ChildItem -Path ".\target\release" -Recurse -Include hurl*.exe -File | Copy-Item -Destination "${execdir}" - cd .\integration - Start-Job -Name mitmdump -ScriptBlock { mitmdump --listen-port 8888 --modify-header "/From-Proxy/Hello" } - Start-Job -Name server -ScriptBlock { python server.py > server.log } - Start-Job -Name server -ScriptBlock { python ssl/server.py > server-ssl.log } - Get-Job -Name server - Get-Job -Name mitmdump - Start-Sleep 5 - python integration.py + .\bin\install_prerequisites_windows.ps1 + .\bin\test\test_prerequisites.ps1 + .\bin\test\test_unit.ps1 + .\bin\release\release.ps1 + .\bin\test\test_integ.ps1 - name: Archive production artifacts uses: actions/upload-artifact@v3 if: ${{ always() }} @@ -294,4 +259,3 @@ jobs: path: | integration/server.log integration/server-ssl.log - diff --git a/bin/environment.ps1 b/bin/environment.ps1 new file mode 100644 index 000000000..8374ea23a --- /dev/null +++ b/bin/environment.ps1 @@ -0,0 +1,13 @@ +echo "----- context -----" + +# get windows infos +Get-ComputerInfo -Property WindowsProductName,WindowsVersion,OsHardwareAbstractionLayer + +# get vcpkg infos +vcpkg --version + +# get python infos +python -V + +# get cargo info +cargo --version diff --git a/bin/install_prerequisites_windows.ps1 b/bin/install_prerequisites_windows.ps1 new file mode 100644 index 000000000..2abf70686 --- /dev/null +++ b/bin/install_prerequisites_windows.ps1 @@ -0,0 +1,12 @@ +echo "----- install system prerequisites -----" + +# install libxml and libcurl +$vcpkg_dir=(Get-command vcpkg).Source +if (Test-Path $vcpkg_dir\installed\x64-windows\lib\libcurl.lib) {echo "curl already installed"} else {vcpkg install curl:x64-windows} +if (Test-Path $vcpkg_dir\installed\x64-windows\lib\libxml2.lib) {echo "libxml2 already installed"} else {vcpkg install libxml2:x64-windows} +vcpkg update +vcpkg upgrade +vcpkg integrate install + +# update pip +python -m pip install --upgrade pip --quiet diff --git a/bin/release/create_windows64_installer.ps1 b/bin/release/create_windows64_installer.ps1 new file mode 100644 index 000000000..3952ef8e1 --- /dev/null +++ b/bin/release/create_windows64_installer.ps1 @@ -0,0 +1,14 @@ +echo "----- create windows64 installer -----" + +$actual_dir=(Get-Location).Path + +# install NSIS +if (Get-Command makensis) {echo "makensis already installed"} else {choco install --confirm --no-progress nsis} +$nsis_dir=(Get-Command makensis).path | Split-Path -Parent +Expand-Archive -Path "$PSScriptRoot\..\..\bin\windows\EnVar_plugin.zip" -DestinationPath "$nsis_dir" -Verbose + +# create win64 installer +cd $PSScriptRoot\..\..\target\win-package +makensis.exe /NOCD /V4 ..\..\bin\windows\hurl.nsi + +cd $actual_dir diff --git a/bin/release/create_windows64_zip_package.ps1 b/bin/release/create_windows64_zip_package.ps1 new file mode 100644 index 000000000..df240f657 --- /dev/null +++ b/bin/release/create_windows64_zip_package.ps1 @@ -0,0 +1,13 @@ +echo "----- create windows64 zip package -----" + +$actual_dir=(Get-Location).Path + +# get built hurl version +$hurl_package_version = Get-Content .\target\win-package\version.txt + +# create windows64 zip package +cd $PSScriptRoot\..\..\target\win-package +Get-ChildItem -Path *.dll, *hurl.exe, *hurlfmt.exe, *.txt, ../../*.md -Exclude hex_literal* | Compress-Archive -DestinationPath hurl-${hurl_package_version}-win64.zip +Get-ChildItem .\*win64.zip + +cd $actual_dir diff --git a/bin/release/release.ps1 b/bin/release/release.ps1 new file mode 100644 index 000000000..00cd892ac --- /dev/null +++ b/bin/release/release.ps1 @@ -0,0 +1,22 @@ +echo "----- build release -----" + +# build +cargo build --release --verbose --locked + +# create final package +New-Item -ItemType Directory -Name .\target\win-package +Get-ChildItem -Path '.\target\release' -Recurse -Include *.dll -File | Copy-Item -Destination '.\target\win-package' +Get-ChildItem -Path '.\target\release' -Recurse -Include hurl*.exe -File | Copy-Item -Destination '.\target\win-package' +((.\target\win-package\hurl.exe --version) -Split " ")[1] > .\target\win-package\version.txt +Get-Content .\target\win-package\version.txt + +# add hurl to PATH +$hurl_dir=(Get-Location).path +$oldpath=(Get-ItemProperty -Path HKCU:\Environment -Name Path).Path +$newpath="$hurl_dir\target\win-package;$oldpath" +Set-ItemProperty -Path HKCU:\Environment -Name Path -Value $newpath +$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") +(Get-Command hurl).Path + +# test hurl execution +hurl --version diff --git a/bin/test/test_integ.ps1 b/bin/test/test_integ.ps1 new file mode 100644 index 000000000..c74b5ebbc --- /dev/null +++ b/bin/test/test_integ.ps1 @@ -0,0 +1,9 @@ +echo "----- integration tests -----" + +$actual_dir=(Get-Location).Path + +# run integration tests +cd $PSScriptRoot\..\..\integration +python ./integration.py + +cd $actual_dir diff --git a/bin/test/test_prerequisites.ps1 b/bin/test/test_prerequisites.ps1 new file mode 100644 index 000000000..476ee045a --- /dev/null +++ b/bin/test/test_prerequisites.ps1 @@ -0,0 +1,17 @@ +echo "----- install tests prerequisites -----" + +$actual_dir=(Get-Location).Path + +# install python libs +pip3 install --requirement bin\requirements-frozen.txt + +# start mock servers +cd $PSScriptRoot\..\..\integration +Start-Job -Name mitmdump -ScriptBlock { mitmdump --listen-port 8888 --modify-header "/From-Proxy/Hello" } +Start-Job -Name server -ScriptBlock { python server.py > server.log } +Start-Job -Name server -ScriptBlock { python ssl/server.py > server-ssl.log } +Get-Job -Name server +Get-Job -Name mitmdump +Start-Sleep 5 + +cd $actual_dir diff --git a/bin/test/test_unit.ps1 b/bin/test/test_unit.ps1 new file mode 100644 index 000000000..fb84db078 --- /dev/null +++ b/bin/test/test_unit.ps1 @@ -0,0 +1,4 @@ +echo "----- unit tests -----" + +# run test units +cargo test --release --features strict --tests