Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed Feb 12, 2024
1 parent c1a7dde commit 0bb4aed
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/actions/build-and-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build and test
description: "Build the project and run tests via CMake"

runs:
using: "composite"
steps:
- name: Build
run: cmake --build '${{github.workspace}}/build' --parallel "$(nproc)"
shell: bash

- name: Test
working-directory: '${{github.workspace}}/build'
run: |
# https://github.com/DiligentGraphics/github-action/commit/d2f7990b16def1efa337e5cc2fc8fa22b6fae55d
PATH="/c/mingw64/bin:$PATH"
ctest --output-on-failure -j"$(nproc)"
shell: bash
45 changes: 45 additions & 0 deletions .github/actions/cmake/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Setup CMake
description: "Invoke CMake and generate build files"
inputs:
additional_cmake_args:
description: "Additional args to pass to CMake"
default: ""

runs:
using: "composite"
steps:
# Linux deps
- name: Install/cache clazy, and doctest
if: runner.os != 'Windows'
uses: awalsh128/[email protected]
with:
packages: doctest-dev clazy
version: 1.0

# Windows deps
- name: Install Windows deps
if: runner.os == 'Windows'
run: |
vcpkg install doctest:x64-mingw-dynamic
echo cmake_extra_args="'-DCMAKE_TOOLCHAIN_FILE=$VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake' '-DMINGW=ON' '-G MinGW Makefiles'" >> "$GITHUB_ENV"
shell: bash

- name: ccache
uses: hendrikmuhs/[email protected]
with:
key: ${{ github.job }}

- name: Configure CMake
run: |
CFLAGS="-Werror ${CFLAGS}" \
CXXFLAGS="-Werror ${CXXFLAGS}" \
cmake \
-S '${{github.workspace}}' \
-B '${{github.workspace}}/build' \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
${{ env.cmake_extra_args }} \
${{ inputs.additional_cmake_args }}
shell: bash
24 changes: 24 additions & 0 deletions .github/actions/run-linter/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: run-linter
description: "Run a linter on all changed files"
inputs:
lint_program_with_args:
description: "Which program to run"
required: true

runs:
using: "composite"
steps:
- uses: ./.github/actions/cmake

- uses: mjp41/workaround8649@c8550b715ccdc17f89c8d5c28d7a48eeff9c94a8
if: runner.os == 'Linux'
with:
os: ubuntu-latest

- name: Copy compile_commands.json
shell: bash
run: cp build/compile_commands.json compile_commands.json

- name: Run the linter
shell: bash
run: find -name '*.cpp' | parallel --verbose --jobs "$(nproc)" --plus _=[{#}/{##}] ${{ inputs.lint_program_with_args }} {}
41 changes: 41 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# vim: sw=2
name: Lint

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
clang-tidy:
name: clang-tidy / Ubuntu 22.04
runs-on: ubuntu-22.04
env:
CC: clang-15
CXX: clang++-15
steps:
- uses: actions/checkout@v3

- name: Run clang-tidy
uses: ./.github/actions/run-linter
with:
lint_program_with_args: clang-tidy-15 --quiet --warnings-as-errors=*

clazy:
name: clazy / Ubuntu 22.04
runs-on: ubuntu-22.04
env:
CC: clang-15
CXX: clang++-15
steps:
- uses: actions/checkout@v3

- name: Run clazy
uses: ./.github/actions/run-linter
with:
lint_program_with_args: clazy-standalone --checks=level1,no-fully-qualified-moc-types,no-non-pod-global-static,no-range-loop-detach
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# vim: sw=2
name: Test

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
ubuntu-qt5:
name: Qt 5.15.2 / Ubuntu 22.04
runs-on: ubuntu-22.04
env:
CFLAGS: -fsanitize=address,undefined
CXXFLAGS: -fsanitize=address,undefined
steps:
- uses: actions/checkout@v3

- name: Setup CMake
uses: ./.github/actions/cmake

- name: Build and test
uses: ./.github/actions/build-and-test

ubuntu-qt6:
name: Qt 6.5.0 / Ubuntu 22.04
runs-on: ubuntu-22.04
env:
CFLAGS: -fsanitize=address,undefined
CXXFLAGS: -fsanitize=address,undefined
steps:
- uses: actions/checkout@v3

- name: Setup CMake
uses: ./.github/actions/cmake

- name: Build and test
uses: ./.github/actions/build-and-test

windows:
name: Qt 6.5.0 / Windows
runs-on: windows-2022
steps:
- uses: actions/checkout@v3

- name: Setup CMake
uses: ./.github/actions/cmake
with:
additional_cmake_args: |
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY='${{github.workspace}}/build/bin' \
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY='${{github.workspace}}/build/bin'
- name: Build and test
uses: ./.github/actions/build-and-test

0 comments on commit 0bb4aed

Please sign in to comment.