From 8e3fdd10ff4116de86de756f20f0ab37e280394e Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Fri, 3 May 2024 11:01:21 +0200 Subject: [PATCH] Run all tests on Windows (#356) * Run all tests on Windows * Forgot to actually install wpcap * Pass secrets to coverage workflow too * But cannot really require it * But must still state them * Secrets not available on forks --- .github/workflows/00-windows.yml | 3 +++ .../workflows/01-build-and-test-windows.yml | 20 ++++++++--------- .github/workflows/02-coverage.yml | 22 ++++++++++++------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/00-windows.yml b/.github/workflows/00-windows.yml index 2eaf1026..87f6cc35 100644 --- a/.github/workflows/00-windows.yml +++ b/.github/workflows/00-windows.yml @@ -32,6 +32,9 @@ jobs: uses: './.github/workflows/02-coverage.yml' with: os: 'windows-latest' + secrets: + NPCAP_OEM_PASSWORD: ${{ secrets.NPCAP_OEM_PASSWORD }} + NPCAP_OEM_USERNAME: ${{ secrets.NPCAP_OEM_USERNAME }} windows-lint-stable: uses: './.github/workflows/03-lint.yml' diff --git a/.github/workflows/01-build-and-test-windows.yml b/.github/workflows/01-build-and-test-windows.yml index c6716d20..0f2bee0d 100644 --- a/.github/workflows/01-build-and-test-windows.yml +++ b/.github/workflows/01-build-and-test-windows.yml @@ -21,6 +21,7 @@ env: RUST_BACKTRACE: 1 CARGO_TERM_VERBOSE: true CARGO_TERM_COLOR: always + PCAP_CI_TEST_TARGETS: ${{ (github.event_name == 'pull_request') && '--lib' || '--all-targets' }} jobs: build-and-test: @@ -44,18 +45,17 @@ jobs: rustup override set ${{ inputs.toolchain }} - if: inputs.msrv run: cp msrv.lock Cargo.lock - # Until #275 is resolved, we will not run integration tests on Windows. Note that since - # secrets are not passed to workflows triggered by a pull request from a fork, it will still - # not be possible to run integration tests on pull requests. + # Note that since secrets are not passed to workflows triggered by a pull request from a fork, + # it is not possible to run integration tests on pull requests. - run: cargo build --all-targets - - run: cargo test --lib - - run: cargo build --all-targets --release - - run: cargo test --lib --release + - run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} + - run: cargo build --all-targets --release + - run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --release - if: ${{ ! inputs.msrv }} - run: cargo build --all-targets --all-features + run: cargo build --all-targets --all-features - if: ${{ ! inputs.msrv}} - run: cargo test --lib --all-features + run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --all-features - if: ${{ ! inputs.msrv }} - run: cargo build --all-targets --release --all-features + run: cargo build --all-targets --release --all-features - if: ${{ ! inputs.msrv}} - run: cargo test --lib --release --all-features + run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --release --all-features diff --git a/.github/workflows/02-coverage.yml b/.github/workflows/02-coverage.yml index 3aedde01..2284b408 100644 --- a/.github/workflows/02-coverage.yml +++ b/.github/workflows/02-coverage.yml @@ -4,11 +4,17 @@ on: os: required: true type: string + secrets: + NPCAP_OEM_PASSWORD: + required: false + NPCAP_OEM_USERNAME: + required: false env: RUST_BACKTRACE: 1 CARGO_TERM_VERBOSE: true CARGO_TERM_COLOR: always + PCAP_CI_TEST_TARGETS: ${{ contains(inputs.os, 'windows') && (github.event_name == 'pull_request') && '--lib' || '--all-targets' }} PCAP_CI_GRCOV_CMD: >- ${{ contains(inputs.os, 'windows') && 'C:/grcov' || './grcov' }} target/debug/profraw @@ -45,6 +51,12 @@ jobs: Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-sdk-1.13.zip" -OutFile "C:/npcap-sdk.zip" Expand-Archive -LiteralPath C:/npcap-sdk.zip -DestinationPath C:/npcap-sdk echo "LIB=C:/npcap-sdk/Lib/x64" >> $env:GITHUB_ENV + - if: ${{ contains(inputs.os, 'windows') && (github.event_name != 'pull_request') }} + run: | + $SecPassword = ConvertTo-SecureString "${{ secrets.NPCAP_OEM_PASSWORD }}" -AsPlainText -Force + $CredObject = New-Object System.Management.Automation.PSCredential ("${{ secrets.NPCAP_OEM_USERNAME }}", $SecPassword) + Invoke-WebRequest -Uri "https://npcap.com/oem/dist/npcap-1.71-oem.exe" -OutFile C:/npcap-oem.exe -Credential $CredObject + C:/npcap-oem.exe /S # No installation of actuall library since we cannot install OEM pcap on pull request branches # anyway. We'll just be running unit tests on Windows. No integration tests. - run: | @@ -64,10 +76,7 @@ jobs: Invoke-WebRequest -Uri "https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-pc-windows-msvc.zip" -OutFile C:/grcov.zip Expand-Archive -LiteralPath C:/grcov.zip -DestinationPath C:/ # Coverage without features. - - if: ${{ contains(inputs.os, 'windows') }} - run: cargo test --lib --no-fail-fast - - if: ${{ ! contains(inputs.os, 'windows') }} - run: cargo test --all-targets --no-fail-fast + - run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --no-fail-fast - run: ${{ env.PCAP_CI_GRCOV_CMD }} - run: ${{ env.PCAP_CI_COV_CMD }} --fail-under ${{ env.PCAP_CI_COV_FAIL_UNDER_NO_FEATURES }} # Clean up coverage artifacts. @@ -79,10 +88,7 @@ jobs: run: rm -rf ./target/debug/{coverage,profraw} - run: cargo clean -p pcap # Coverage with features. - - if: ${{ contains(inputs.os, 'windows') }} - run: cargo test --lib --all-features --no-fail-fast - - if: ${{ ! contains(inputs.os, 'windows') }} - run: cargo test --all-targets --all-features --no-fail-fast + - run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --all-features --no-fail-fast - run: ${{ env.PCAP_CI_GRCOV_CMD }} - run: ${{ env.PCAP_CI_COV_CMD }} --fail-under ${{ env.PCAP_CI_COV_FAIL_UNDER_ALL_FEATURES }} # On push to main push results to coverage branch.