补加以format #6
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: CI | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
include: | |
- os: ubuntu-latest | |
install: | | |
sudo apt-get update | |
sudo apt-get install -y autoconf automake libtool pkg-config | |
sudo apt-get install -y libsdl2-dev libvulkan-dev | |
sudo apt-get install -y clang-format cppcheck lcov | |
sudo apt-get install -y libgtest-dev | |
cd /usr/src/gtest | |
sudo cmake CMakeLists.txt | |
sudo make | |
sudo cp lib/*.a /usr/lib | |
cc: gcc | |
cxx: g++ | |
coverage: true | |
coverage_flags: "--coverage -fprofile-arcs -ftest-coverage" | |
- os: windows-latest | |
install: | | |
choco install autoconf automake libtool pkg-config | |
choco install mingw | |
choco install vulkan-sdk | |
choco install llvm | |
# Install Google Test | |
git clone https://github.com/google/googletest.git | |
cd googletest | |
cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=C:/gtest . | |
mingw32-make | |
mingw32-make install | |
cd .. | |
cc: gcc | |
cxx: g++ | |
coverage: false | |
coverage_flags: "" | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
deps/build | |
deps/install | |
googletest | |
key: ${{ runner.os }}-deps-${{ hashFiles('deps/download_deps.sh') }} | |
restore-keys: | | |
${{ runner.os }}-deps- | |
- name: Install dependencies | |
run: ${{ matrix.install }} | |
- name: Set up environment | |
shell: bash | |
run: | | |
echo "CC=${{ matrix.cc }}" >> $GITHUB_ENV | |
echo "CXX=${{ matrix.cxx }}" >> $GITHUB_ENV | |
if [ "${{ runner.os }}" = "Windows" ]; then | |
echo "GTEST_ROOT=C:/gtest" >> $GITHUB_ENV | |
fi | |
- name: Code format check | |
if: runner.os == 'Linux' | |
run: | | |
find src tests -name '*.cpp' -o -name '*.h' | xargs clang-format -n -Werror | |
- name: Static analysis | |
if: runner.os == 'Linux' | |
run: | | |
cppcheck --enable=all --error-exitcode=1 --suppress=missingInclude src/ tests/ | |
- name: Generate build system | |
shell: bash | |
run: | | |
./autogen.sh | |
- name: Configure | |
shell: bash | |
run: | | |
if [ "${{ matrix.coverage }}" = "true" ]; then | |
./configure CFLAGS="-Wall -Wextra ${{ matrix.coverage_flags }}" CXXFLAGS="-Wall -Wextra ${{ matrix.coverage_flags }}" --enable-testing | |
else | |
./configure CFLAGS="-Wall -Wextra" CXXFLAGS="-Wall -Wextra" --enable-testing | |
fi | |
- name: Build | |
shell: bash | |
run: | | |
make -j$(nproc) | |
- name: Run tests | |
shell: bash | |
run: | | |
make check | |
- name: Run tests with coverage | |
if: matrix.coverage | |
shell: bash | |
run: | | |
# 运行测试并生成覆盖率报告 | |
make check | |
lcov --capture --directory . --output-file coverage.info | |
lcov --remove coverage.info '/usr/*' --output-file coverage.info | |
lcov --list coverage.info | |
- name: Upload coverage to Coveralls | |
if: matrix.coverage | |
uses: coverallsapp/github-action@v2 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
file: coverage.info | |
format: lcov | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: doom_pp-${{ matrix.os }} | |
path: | | |
doom_pp | |
doom_pp.exe | |
tests/unit/test_runner | |
if-no-files-found: ignore | |
analyze: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event_name == 'pull_request' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Run CodeQL | |
uses: github/codeql-action/init@v2 | |
with: | |
languages: cpp | |
- name: Perform CodeQL Analysis | |
uses: github/codeql-action/analyze@v2 |