ci: Only update caches from main repository #64
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
# SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | |
# | |
# SPDX-License-Identifier: MIT | |
name: knut tests | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- name: Ubuntu | |
os: ubuntu-latest | |
compiler_cache_path: /home/runner/.cache/sccache | |
- name: Windows | |
os: windows-latest | |
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache | |
- name: MacOS | |
os: macos-latest | |
compiler_cache_path: /Users/runner/Library/Caches/Mozilla.sccache | |
env: | |
SCCACHE_CACHE_SIZE: "2G" | |
steps: | |
- name: Inspect Environment Variables | |
run: env | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
# Note: Once we're able to access photonwidgets and mfc-utils, this can simply be replaced by | |
# setting | |
# with: | |
# submodules: recursive | |
# on the "Checkout sources" step | |
- name: Checkout submodules | |
run: | | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/extra-cmake-modules' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/kdalgorithms' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/ksyntaxhighlighting' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/nlohmann-json' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/pugixml' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/spdlog' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/tree-sitter' | |
git submodule update --init --force --depth=1 --recursive -- '3rdparty/tree-sitter-cpp' | |
# git submodule update --init --force --depth=1 --recursive -- '3rdparty/photonwidgets' | |
# git submodule update --init --force --depth=1 --recursive -- '3rdparty/mfc-utils' | |
- name: Install ninja-build tool | |
uses: aseprite/get-ninja@main | |
- name: Install Qt 6 | |
uses: jurplel/install-qt-action@v4 | |
with: | |
version: 6.5.* # 6.5 is the current LTS (as of 2024-06-06) | |
cache: true | |
- name: Make sure MSVC is found when Ninja generator is in use | |
uses: ilammy/msvc-dev-cmd@v1 | |
# Note: The Compiler cache steps were adapted from the CXX-Qt repository (https://github.com/kdab/cxx-qt) | |
# | |
# We want our compiler cache to always update to the newest state. | |
# The best way for us to achieve this is to **always** update the cache after every landed commit. | |
# That way it will closely follow our development. | |
# And if a PR diverges a lot with its cache that's not a big deal, as it will be merged eventually. | |
# | |
# This is a workaround for the fact that GH doesn't support updating existing caches. | |
# See: https://github.com/azu/github-actions-overwrite-cache-example | |
# | |
# Ideally we'd like to use this: | |
# - name: "Compiler cache" | |
# uses: actions/cache@v4 | |
# with: | |
# update: true <------- THIS DOESN'T EXIST YET | |
# path: ${{ matrix.compiler_cache_path }} | |
# key: ${{ matrix.name }}_compiler_cache | |
- name: "Restore Compiler Cache" | |
id: compiler-cache-restore | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ matrix.compiler_cache_path }} | |
key: ${{ matrix.os }}_compiler_cache | |
- name: Run sccache-cache | |
uses: mozilla-actions/[email protected] | |
- name: Configure project | |
run: cmake -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache --preset=ci | |
- name: Build Project | |
run: cmake --build --preset=ci | |
- name: Run tests | |
run: ctest --preset=ci | |
# We only upload artifacts if building or testing has failed | |
# That way we can debug if necessary, but don't pay the 30s-60s | |
# of upload time if everything is going well. | |
- name: Output the build results as an artifact | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: knut-binaries-${{ matrix.os }}-${{ github.head_ref || github.ref_name }} | |
path: build-ci/bin/ | |
overwrite: true | |
# This is a workaround for the fact that GH doesn't support updating existing caches. | |
# See: https://github.com/azu/github-actions-overwrite-cache-example | |
- name: "Delete previous compiler cache" | |
# Updating th cache doesn't work from forks | |
# So update it once it's merged into the repo | |
if: ${{ steps.compiler-cache-restore.outputs.cache-hit && github.event_name == 'push' }} | |
continue-on-error: true | |
run: | | |
gh extension install actions/gh-actions-cache | |
gh actions-cache delete "${{ matrix.os }}_compiler_cache" --confirm | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Save Compiler Cache" | |
uses: actions/cache/save@v4 | |
# Updating th cache doesn't work from forks | |
# So update it once it's merged into the repo | |
if: ${{ github.event_name == 'push' }} | |
with: | |
path: ${{ matrix.compiler_cache_path }} | |
key: ${{ matrix.os }}_compiler_cache |