Skip to content

Formatting: Run clang-format #818

Formatting: Run clang-format

Formatting: Run clang-format #818

Workflow file for this run

name: CI
on:
[push, workflow_dispatch]
jobs:
build-and-test:
timeout-minutes: 10
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: ubuntu-latest, CXX: cosmoc++, build_type: all}
- {os: ubuntu-latest, CXX: cosmoc++, build_type: release}
- {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/msvc-dev-cmd@v1.13.0
with:
arch: amd64
- name: Setup cosmoc++
if: matrix.config.CXX == 'cosmoc++'
shell: bash
run: |
if [[ "${{ matrix.config.os }}" == "windows-latest" ]]; then
choco install unzip wget -y --no-progress
fi
mkdir -p cosmocc
cd cosmocc
wget https://cosmo.zip/pub/cosmocc/cosmocc.zip -q
unzip -qq cosmocc.zip
git clone https://github.com/jart/cosmopolitan --depth=1
cd cosmopolitan
if [[ "${{ matrix.config.os }}" != "windows-latest" ]]; then
sudo ape/apeinstall.sh
fi
cd ..
cd ..
echo "$(pwd)/cosmocc/bin" >> $GITHUB_PATH
- 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: |
# output 3 to stdin (to close the game) as 'make all' will start the game
echo -e "3" | make CXX=${{ matrix.config.CXX }} all -j2
- name: Make release
if: matrix.config.CXX != 'cmake' && matrix.config.CXX != 'cl' && matrix.config.build_type == 'release'
shell: bash
run: |
make release CXX=${{ matrix.config.CXX }} -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 "1\ntest\nX\nY\n" | ./$executable
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
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
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
analyze:
needs: build-and-test
name: CodeQL Analysis (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
security-events: write
packages: read
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: c-cpp
build-mode: autobuild
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
clang-format:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Make check
run: |
make check