diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..331582d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,94 @@ +name: Tests + +on: + push: + branches: + - main + pull_request: + +jobs: + native: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] # TODO: Add windows-latest when officially supported + runs-on: ${{ matrix.os }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + # Set up Python 3.10 or later + - name: Set up Python 3.10 (Windows) + if: matrix.os == 'windows-latest' + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + # Install C++ Compiler & Build Tools + - name: Set up C++ environment (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -y g++ make cmake + g++ --version + cmake --version + make --version + + - name: Set up C++ environment (macOS) + if: matrix.os == 'macos-latest' + run: | + brew install make cmake + echo 'export PATH="/usr/local/opt/gcc/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile + g++ --version + cmake --version + make --version + + - name: Set up C++ environment (Windows) + if: matrix.os == 'windows-latest' + run: | + choco install mingw --version=8.1.0-1 + choco install make cmake + echo C:\ProgramData\chocolatey\lib\mingw\tools\install\mingw64\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo C:\ProgramData\chocolatey\lib\cmake\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + g++ --version + cmake --version + make --version + + # Install Qt6 + - name: Install Qt6 (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install -y qt6-base-dev + echo 'export PATH="/usr/lib/qt6/bin:$PATH"' >> ~/.bashrc + source ~/.bashrc + + - name: Install Qt6 (macOS) + if: matrix.os == 'macos-latest' + run: | + brew install qt6 + echo 'export PATH="/opt/homebrew/opt/qt6/bin:$PATH"' >> ~/.bash_profile + source ~/.bash_profile + + - name: Install Qt6 (Windows) + if: matrix.os == 'windows-latest' + run: | + python -m pip install aqtinstall + python -m aqt install-qt windows desktop 6.6.0 win64_mingw --outputdir C:\Qt + echo C:\Qt\6.6.0\mingw_64\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + # Build the Project + - name: Build project + run: make build + + - name: Run Unit Tests + run: make test + + docker: + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Run Docker Test + run: | + chmod +x ./run_docker.sh + ./run_docker.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7c3b361 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM ubuntu:24.04 AS builder +WORKDIR / + +# Add dependencies +RUN apt-get update +RUN apt-get install -y --no-install-recommends \ + git \ + ca-certificates \ + g++ \ + cmake \ + make \ + mesa-common-dev \ + qt6-base-dev \ + x11-utils \ + x11-xserver-utils \ + xvfb +RUN rm -rf /var/lib/apt/lists/* + +# Copy CodeAstra into the container +COPY . /CodeAstra +WORKDIR /CodeAstra + +# Run dockerized tests script +RUN chmod +x ./test_with_xvbf.sh + +CMD ["./test_with_xvbf.sh"] diff --git a/Makefile b/Makefile index b0973ed..92474bb 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ PROJECT = CodeAstra -BUILD_DIR = build +BUILD_DIR = $(PWD)/build EXECUTABLE = $(PROJECT) # Set CMake options @@ -45,7 +45,7 @@ uninstall: clean fi # Install the project -install: +install: build @echo "Installing $(PROJECT)..." @cd $(BUILD_DIR) && make @echo "Do you want to create a shortcut on the desktop? (Y/n)" @@ -76,7 +76,10 @@ install: fi @echo "$(PROJECT) installed." -test: +build_tests: build + @cd $(BUILD_DIR)/tests/ && make + +test: build_tests @for test in ./build/tests/test_*; do \ if [ -f $$test ]; then \ echo "Running $$test..."; \ diff --git a/run_docker.sh b/run_docker.sh new file mode 100755 index 0000000..2aa18f5 --- /dev/null +++ b/run_docker.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +docker build -t "code-astra:tester" . +docker run --name "code-astra-tester" "code-astra:tester" +docker rm "code-astra-tester" diff --git a/test_with_xvbf.sh b/test_with_xvbf.sh new file mode 100644 index 0000000..c0b8574 --- /dev/null +++ b/test_with_xvbf.sh @@ -0,0 +1,8 @@ +#!/bin/bash -e + +# Start Xvfb server +Xvfb :99 -screen 0 1024x768x24 & +export DISPLAY=:99 + +# Run tests +make test