Skip to content

Commit d5094c8

Browse files
authored
Add dynamic matrix generation for winpcap / npcap backends. (#1950)
* Add debug jobs for selecting winpcap or npcap matrix. * Update step so it does not use secrets directly in bash. * Fix syntax. * Fix condition. * Attempt to fix again. * Fix quotes. * Fix expression again... * temp remove the secret check * Fix case? * Fix step outputs. * Test dynamic matrix on mingw job. * Expand matrices on windows and mingw. * Rename matrix generation job. * Add step to enable Npcap backend if OEM credentials are available. * Fix conditional. * Updated step desc. * Improve comments. * Lint * Fix case. * Add step explaining why NPcap is unavailable. * Fix quotes. * Add another output that prefers Npcap backend but will use Winpcap if Npcap is not available. * Rollback windows jobs to a partial matrix. - Use Npcap backend for x64 jobs if available. * Removed quotation marks from npcap-or-default as it will not be read as a json object. * Rollback mingw jobs to single jobs. * Remove pcap-backends output.
1 parent 92dc742 commit d5094c8

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

.github/workflows/build_and_test.yml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,47 @@ jobs:
504504
path: ${{ env.CCACHE_DIR }}
505505
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}
506506

507+
define-windows-pcap-backend-matrix:
508+
name: Determine Windows Pcap Backend Matrix
509+
runs-on: ubuntu-latest
510+
outputs:
511+
npcap-or-default: ${{ steps.generate-backends.outputs.npcap_or_default}}
512+
steps:
513+
- name: Initialize NPcap backend variable
514+
run: echo "npcap_available=false" >> $GITHUB_ENV
515+
516+
- name: Enable NPcap backend if OEM credentials are available
517+
env: # Secrets can't be accessed directly in 'if' conditionals.
518+
npcap_username: ${{ secrets.NPCAP_USERNAME }}
519+
npcap_password: ${{ secrets.NPCAP_PASSWORD }}
520+
if: ${{ env.npcap_username != '' && env.npcap_password != '' }}
521+
run: echo "npcap_available=true" >> $GITHUB_ENV
522+
523+
- name: NPcap backend is unavailable
524+
if: ${{ env.npcap_available != 'true' }}
525+
run: echo "NPcap backend will be skipped since OEM credentials are missing. NPCAP_USERNAME and NPCAP_PASSWORD are required."
526+
527+
- name: Generate pcap backends matrix
528+
id: generate-backends
529+
run: |
530+
if [[ "${{ env.npcap_available }}" == "true" ]]; then
531+
echo 'npcap_or_default=npcap' >> "$GITHUB_OUTPUT"
532+
else
533+
echo 'npcap_or_default=winpcap' >> "$GITHUB_OUTPUT"
534+
fi
535+
507536
mingw-w64:
508-
runs-on: windows-latest
537+
needs: define-windows-pcap-backend-matrix
509538
strategy:
510539
matrix:
511540
include:
512-
- env: i686
513-
sys: mingw32
541+
- sys: mingw32
542+
env: i686
514543
pcap_lib: "winpcap"
515-
- env: x86_64
516-
sys: mingw64
517-
pcap_lib: "winpcap"
518-
544+
- sys: mingw64
545+
env: x86_64
546+
pcap_lib: ${{ needs.define-windows-pcap-backend-matrix.outputs.npcap-or-default }}
547+
runs-on: windows-latest
519548
steps:
520549
- name: Checkout code
521550
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -596,6 +625,7 @@ jobs:
596625
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
597626

598627
visual-studio:
628+
needs: define-windows-pcap-backend-matrix
599629
strategy:
600630
matrix:
601631
include:
@@ -606,11 +636,11 @@ jobs:
606636
- os: windows-2025
607637
platform: "Visual Studio 17 2022"
608638
arch: "x64"
609-
pcap_lib: "winpcap"
639+
pcap_lib: ${{ needs.define-windows-pcap-backend-matrix.outputs.npcap-or-default }}
610640
- os: windows-2022
611641
platform: "Visual Studio 17 2022"
612642
arch: "x64"
613-
pcap_lib: "winpcap"
643+
pcap_lib: ${{ needs.define-windows-pcap-backend-matrix.outputs.npcap-or-default }}
614644

615645
runs-on: ${{ matrix.os }}
616646
steps:

0 commit comments

Comments
 (0)