Windows Build and Unit Tests with MinGW #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Windows Build and Unit Tests with MinGW | |
on: | |
workflow_dispatch: | |
jobs: | |
build_and_test_windows_mingw: | |
runs-on: windows-latest | |
name: Build and Test with MinGW | |
strategy: | |
matrix: | |
arch: | |
- { arch: "i686", file: "i686-14.2.0-release-win32-dwarf-msvcrt-rt_v12-rev0.7z" } | |
- { arch: "x86_64", file: "x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev0.7z" } | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download and Extract MinGW with Git Bash | |
shell: bash | |
run: | | |
MingwFile="${{ matrix.arch.file }}" | |
MingwUrl="https://github.com/niXman/mingw-builds-binaries/releases/download/14.2.0-rt_v12-rev0/$MingwFile" | |
ExtractDir="$RUNNER_TEMP/mingw_extract" | |
# Create a clean extraction directory | |
mkdir -p "$ExtractDir" | |
# Download the archive | |
echo "Downloading MinGW..." | |
curl -L -o "$RUNNER_TEMP/$MingwFile" "$MingwUrl" | |
# Extract the archive | |
echo "Extracting MinGW..." | |
7z x "$RUNNER_TEMP/$MingwFile" -o"$ExtractDir" | |
# Verify extraction | |
echo "Verifying extracted files..." | |
ls "$ExtractDir" | |
# Dynamically locate the MinGW directory (mingw32 or mingw64) | |
MingwDir=$(find "$ExtractDir" -type d \( -name "mingw32" -o -name "mingw64" \) | head -n 1) | |
if [ -z "$MingwDir" ]; then | |
echo "Error: Could not locate the MinGW directory!" | |
exit 1 | |
fi | |
echo "Using MinGW directory: $MingwDir" | |
# Add bin directory to PATH | |
echo "$MingwDir/bin" >> $GITHUB_PATH | |
- name: Setup GTest | |
shell: bash | |
run: | | |
mkdir -p gtest-build | |
cd gtest-build | |
curl -L -o googletest-release-1.11.0.zip https://github.com/google/googletest/archive/refs/tags/release-1.11.0.zip | |
unzip googletest-release-1.11.0.zip | |
cd googletest-release-1.11.0 | |
cmake -G "MinGW Makefiles" \ | |
-DCMAKE_C_COMPILER=${{ matrix.arch.arch }}-w64-mingw32-gcc \ | |
-DCMAKE_CXX_COMPILER=${{ matrix.arch.arch }}-w64-mingw32-g++ \ | |
-DCMAKE_BUILD_TYPE=Debug \ | |
-DCMAKE_INSTALL_PREFIX="C:/googletest" | |
cmake --build . --config Debug | |
cmake --install . --config Debug | |
cd ../.. | |
- name: Build Project | |
shell: bash | |
run: | | |
cmake -G "MinGW Makefiles" \ | |
-DCMAKE_C_COMPILER=${{ matrix.arch.arch }}-w64-mingw32-gcc \ | |
-DCMAKE_CXX_COMPILER=${{ matrix.arch.arch }}-w64-mingw32-g++ \ | |
-DCMAKE_BUILD_TYPE=Debug \ | |
-DCMAKE_PREFIX_PATH="C:/googletest/lib/cmake/GTest" \ | |
-DTESTING_ENABLED=ON \ | |
. | |
cmake --build . --config Debug | |
- name: Run Unit Tests | |
shell: bash | |
run: | | |
ctest -C Debug --output-on-failure |