diff --git a/.github/workflows/build-and-test-windows.yml b/.github/workflows/build-and-test-windows.yml index 9b488e716d46..e8b469c413a2 100644 --- a/.github/workflows/build-and-test-windows.yml +++ b/.github/workflows/build-and-test-windows.yml @@ -69,6 +69,9 @@ jobs: ~\go\pkg\mod ~\AppData\Local\go-build key: go-build-cache-${{ runner.os }}-${{ matrix.group }}-go-${{ hashFiles('**/go.sum') }} + - name: Ensure required ports in the dynamic range are available + run: | + & ${{ github.workspace }}\.github\workflows\scripts\win-required-ports.ps1 - name: Run Unit tests run: make -j2 gotest GROUP=${{ matrix.group }} windows-unittest: diff --git a/.github/workflows/scripts/win-required-ports.ps1 b/.github/workflows/scripts/win-required-ports.ps1 new file mode 100644 index 000000000000..ef209792de8d --- /dev/null +++ b/.github/workflows/scripts/win-required-ports.ps1 @@ -0,0 +1,20 @@ +<# +.SYNOPSIS + This script ensures that the ports required by the default configuration of the collector are available. +.DESCRIPTION + Certain runs on GitHub Actions sometimes have ports required by the default configuration reserved by other + applications via the WinNAT service. +#> + +#Requires -RunAsAdministrator + +netsh interface ip show excludedportrange protocol=tcp + +Stop-Service winnat + +# Only port in the dynamic range that is being, from time to time, reserved by other applications. +netsh interface ip add excludedportrange protocol=tcp startport=55678 numberofports=2 + +Start-Service winnat + +netsh interface ip show excludedportrange protocol=tcp