Skip to content

Fix test cases script properly (#131) #765

Fix test cases script properly (#131)

Fix test cases script properly (#131) #765

Workflow file for this run

name: CI
on:
[push, workflow_dispatch]
#concurrency:
# group: "make"
# cancel-in-progress: false
jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Make check
run: |
make check
build-and-test:
# runs-on: self-hosted
timeout-minutes: 5
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, CXX: g++, build_type: all}
- {os: ubuntu-latest, CXX: g++, build_type: release}
- {os: ubuntu-latest, CXX: clang++, build_type: all}
- {os: ubuntu-latest, CXX: clang++, build_type: release}
- {os: ubuntu-latest, CXX: cmake, build_type: Debug}
- {os: windows-latest, CXX: cl, build_type: Debug}
- {os: windows-latest, CXX: g++, build_type: all}
- {os: windows-latest, CXX: g++, build_type: release}
- {os: windows-latest, CXX: clang++, build_type: all}
- {os: windows-latest, CXX: clang++, build_type: release}
- {os: windows-latest, CXX: cmake, build_type: Debug}
# macos-12 is for x64, while macos-14 is for arm64 (M1)
- {os: macos-12, CXX: g++, build_type: all}
- {os: macos-12, CXX: g++, build_type: release}
- {os: macos-12, CXX: clang++, build_type: all}
- {os: macos-12, CXX: clang++, build_type: release}
- {os: macos-12, CXX: cmake, build_type: Debug}
- {os: macos-latest, CXX: g++, build_type: all}
- {os: macos-latest, CXX: g++, build_type: release}
- {os: macos-latest, CXX: clang++, build_type: all}
- {os: macos-latest, CXX: clang++, build_type: release}
- {os: macos-latest, CXX: cmake, build_type: Debug}
name: "${{ matrix.config.os }} ${{ matrix.config.CXX }} ${{ matrix.config.build_type }}"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup LLVM on Windows
# https://github.com/actions/runner-images/issues/10001
if: matrix.config.CXX == 'clang++' && matrix.config.os == 'windows-latest'
run: |
choco upgrade llvm -y
echo "LLVM_PATH=C:\Program Files\LLVM\bin" >> $GITHUB_ENV
- name: Set up Microsoft Dev Cmd
if: matrix.config.os == 'windows-latest' && matrix.config.CXX == 'cl'
uses: ilammy/[email protected]
with:
arch: amd64
- name: Output compiler version
shell: bash
run: |
if [[ "${{ matrix.config.CXX }}" == "cl" ]]; then
cl
else \
${{ matrix.config.CXX }} --version
fi
- name: Make all
if: matrix.config.CXX != 'cmake' && matrix.config.CXX != 'cl' && matrix.config.build_type == 'all'
shell: bash
run: |
# Enabling optimization checks -Wmaybe-uninitialized from -Wall
# output 3 to stdin (to close the game) as 'make all' will start the game
echo -e "3" | CXXFLAGS=-O2 CXX=${{ matrix.config.CXX }} make all -j2
- name: Make release
if: matrix.config.CXX != 'cmake' && matrix.config.CXX != 'cl' && matrix.config.build_type == 'release'
shell: bash
run: |
CXX=${{ matrix.config.CXX }} make release -j 2
- name: CMake
if: matrix.config.CXX == 'cmake'
shell: bash
run: |
cmake -B build -S . -DOUTPUT_NAME=stocksim-cmake -Werror=dev -Werror=deprecated --fresh
cmake --build build --parallel 2 --config ${{ matrix.config.build_type }} --clean-first
cmake --install build --prefix . --config ${{ matrix.config.build_type }}
- name: Compile with cl
if: matrix.config.os == 'windows-latest' && matrix.config.CXX == 'cl'
shell: cmd
run: |
make msvc
- name: Run test cases
shell: bash
run: |
if [[ "${{ matrix.config.CXX }}" == "cmake" ]]; then
executable="stocksim-cmake"
elif [[ "${{ matrix.config.CXX }}" == "cl" ]]; then
executable="stocksim-msvc"
elif [[ "${{ matrix.config.build_type }}" == "release" ]]; then
executable="stocksim-release"
else
executable="stocksim"
fi
echo -e "0\n saves\nsaves\nB\n1\n1\nN\nY\nN\nY\nN\nY\nT\n0\nT\n1\nT\n2\nE\nT\nX\nY\n" | ./$executable
# test for loading saves
echo -e "1\nsaves\nN\nY\nN\nY\nN\nY\nN\nY\nT\n0\nT\nT\n3\nT\n4\nT\nS\n1\n1\nX\nY\n" | ./$executable
# test for deleting saves
echo -e "2\nsaves\nY\n3\n" | ./$executable
- name: Upload executable
uses: actions/upload-artifact@v4
with:
# suppose we compiled our game and named it 'stocksim'
# use wildcard to match the executable for all platforms
# name: stocksim
name: stocksim-${{ matrix.config.os }}-${{ matrix.config.CXX }}-${{ matrix.config.build_type }}
path: stocksim*
compression-level: 9
if-no-files-found: error