From 12d8ed3fddf6911d8b7b5e8a92b4b91fba0c1b81 Mon Sep 17 00:00:00 2001 From: capo-at-the-5th-fret Date: Tue, 19 Nov 2024 09:42:45 -0500 Subject: [PATCH] Updated workflow with caching --- .github/workflows/ci.yml | 102 ++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 243665e..ca0954a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,77 +6,67 @@ on: branches: [ "main", "fix*" ] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) BUILD_TYPE: Release + SCCACHE_GHA_ENABLED: "true" jobs: Test: - runs-on: ${{ matrix.os }} + name: ${{ matrix.config.os }} ${{ matrix.config.compiler }} + runs-on: ${{ matrix.config.os }} strategy: fail-fast: false matrix: - os: - - windows-2022 - - ubuntu-24.04 - - macos-14 - compiler: - - llvm - - gcc - include: - - os: "windows-2022" - compiler: "msvc" - exclude: - - os: "macos-14" - compiler: "llvm" + config: + # Reference: https://github.com/actions/runner-images + - { os: "ubuntu-24.04", compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "/usr/bin/g++-14", cmake_cxx_launcher: "ccache" } + - { os: "ubuntu-24.04", compiler: "llvm", cmake_gen: Ninja Multi-Config, cmake_cxx: "/usr/lib/llvm-18/bin/clang++", cmake_cxx_launcher: "ccache" } + # project won't compile using g++ on macos-15; can use macos-14 instead + #- { os: "macos-15", compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "g++-14", cmake_cxx_launcher: "ccache" } + - { os: "macos-14", compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "g++-14", cmake_cxx_launcher: "ccache" } + - { os: "macos-15", compiler: "llvm", cmake_gen: "Ninja Multi-Config", cmake_cxx: "$(brew --prefix llvm@18)/bin/clang++", cmake_cxx_launcher: "ccache" } + - { os: windows-2022, compiler: "msvc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "cl", cmake_cxx_launcher: "sccache" } + - { os: windows-2022, compiler: "llvm", cmake_gen: "Ninja Multi-Config", cmake_cxx: "clang++", cmake_cxx_launcher: "sccache" } + - { os: windows-2022, compiler: "gcc", cmake_gen: "Ninja Multi-Config", cmake_cxx: "g++", cmake_cxx_launcher: "sccache" } + #- { os: "macos-14", compiler: "llvm", cmake_gen: "Ninja Multi-Config", cmake_cxx: "clang++", cmake_cxx_launcher: "ccache" } + steps: - - uses: actions/checkout@v3 - - name: Cache - uses: actions/cache@v3 - with: - path: | - ./build/ - ~/vcpkg - ~/.cache/vcpkg/archives - ${{ env.LOCALAPPDATA }}/vcpkg/archives - ${{ env.APPDATA }}/vcpkg/archives - ${{ env.XDG_CACHE_HOME }}/vcpkg/archives - ~/.cache/ccache - ~/.ccache - ~/.config/ccache - ~/Library/Caches/ccache - ${{ env.LOCALAPPDATA }}/ccache - ${{ env.XDG_CACHE_HOME }}/ccache - key: ${{ runner.os }}-${{ matrix.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt', './vcpkg.json') }} - restore-keys: | - ${{ runner.os }}-${{ env.BUILD_TYPE }}- + - uses: actions/checkout@v4 + + # NOTE: This cache is faster for non-Windows builds than ccache, but it + # may not work over time? It doesn't work well for Windows builds + # Recommend: use ccache for non-Windows and sccache for Windows (ccache is + # also flakey on Windows) + # + # - name: Cache (non-Windows) + # if: runner.os != 'Windows' + # uses: actions/cache@v4 + # with: + # path: | + # ./build + # key: ${{ runner.os }}-${{ matrix.config.compiler }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt', './vcpkg.json') }} + # restore-keys: | + # ${{ runner.os }}-${{ matrix.config.compiler }}-${{ env.BUILD_TYPE }}- + + - name: Cache (non-Windows) + if: runner.os != 'Windows' + uses: hendrikmuhs/ccache-action@v1.2 - - name: Setup Cpp + - name: Cache (Windows) + if: runner.os == 'Windows' + uses: mozilla-actions/sccache-action@v0.0.6 + + - name: Install C++ Tools uses: aminya/setup-cpp@v1 with: - compiler: ${{ matrix.compiler }} - vcvarsall: ${{ contains(matrix.os, 'windows') }} - cmake: true + vcvarsall: ${{ runner.os == 'Windows' && matrix.config.compiler == 'msvc' }} ninja: true - vcpkg: false - cppcheck: false - clang-tidy: false - - name: Configure CMake (non-Windows) - if: runner.os != 'Windows' - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - - - name: Configure CMake (Windows) - if: runner.os == 'Windows' - run: cmake -B ${{github.workspace}}/build + - name: Configure CMake + run: cmake -B ./build -G "${{matrix.config.cmake_gen}}" -DCMAKE_CXX_COMPILER="${{matrix.config.cmake_cxx}}" -DCMAKE_CXX_COMPILER_LAUNCHER="${{matrix.config.cmake_cxx_launcher}}" - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ./build --config ${{env.BUILD_TYPE}} - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + working-directory: ./build run: ctest -C ${{env.BUILD_TYPE}}