Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Enable cached builds #2

Merged
merged 7 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 76 additions & 5 deletions .github/workflows/knut-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
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

Expand Down Expand Up @@ -59,11 +71,70 @@ jobs:
- 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 --preset=ci
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
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 3.15)
# This enables the use of CMAKE_MSVC_DEBUG_INFORMATION_FORMAT as required by the CI preset
cmake_policy(SET CMP0141 NEW)

# This file is part of Knut.
#
# SPDX-FileCopyrightText: 2024 Klarälvdalens Datakonsult AB, a KDAB Group
Expand Down Expand Up @@ -64,13 +67,11 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
message(STATUS "GIT not found!?")
endif()
endif()
add_definitions(-DKNUT_VERSION_STRING="${KNUT_VERSION_STRING}")

# Generate build date for the about dialog Note: This is the simplest way to get
# a build date out of CMake Drawbacks: The timestamp is only updated when CMake
# is rerun. But this should sufficient for our use-case.
string(TIMESTAMP KNUT_BUILDDATE "%Y-%m-%d")
add_definitions(-DKNUT_BUILDDATE="${KNUT_BUILDDATE}")

# Qt
# ##############################################################################
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"generator": "Ninja",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "Embedded",
"KNUT_ERROR_ON_WARN": "ON"
}
},
Expand Down
4 changes: 4 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

project(knut-core LANGUAGES CXX)

configure_file(version.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)

set(PROJECT_SOURCES
astnode.h
astnode.cpp
Expand Down Expand Up @@ -104,6 +106,8 @@ set(PROJECT_SOURCES
userdialog.cpp
utils.h
utils.cpp
version.h
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
core.qrc)

add_library(${PROJECT_NAME} STATIC ${PROJECT_SOURCES})
Expand Down
12 changes: 12 additions & 0 deletions src/core/version.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "core/version.h"

namespace core {
QString knut_version()
{
return "${KNUT_VERSION_STRING}";
}

QString knut_build_date() {
return "${KNUT_BUILDDATE}";
}
}
8 changes: 8 additions & 0 deletions src/core/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <QString>

namespace core {
QString knut_version();
QString knut_build_date();
}
3 changes: 2 additions & 1 deletion src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "core/slintdocument.h"
#include "core/textdocument.h"
#include "core/uidocument.h"
#include "core/version.h"
#include "documentpalette.h"
#include "guisettings.h"
#include "historypanel.h"
Expand Down Expand Up @@ -572,7 +573,7 @@ Build date: %2<br/><br/>
Knut name has nothing to do with Knut Irvin, nor with Knut the polar bear.<br/>
The name Knut is coming from St Knut, which marks the end of the Christmas and holiday season in Sweden.<br/>
See Wikipedia article: <a href="https://en.wikipedia.org/wiki/Saint_Knut%27s_Day">Saint Knut's Day</a>.)")
.arg(KNUT_VERSION_STRING, KNUT_BUILDDATE);
.arg(core::knut_version(), core::knut_build_date());
QMessageBox dialog(QMessageBox::Information, tr("About Knut"), text, QMessageBox::Ok, this);
dialog.setIconPixmap(QPixmap(":/gui/icons/knut-64.png"));
dialog.exec();
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Contact KDAB at <[email protected]> for commercial licensing options.
*/

#include "core/version.h"
#include "gui/knutmain.h"

#include <QApplication>
Expand All @@ -19,7 +20,7 @@ int main(int argc, char *argv[])

QApplication::setOrganizationName("KDAB");
QApplication::setApplicationName("knut");
QApplication::setApplicationVersion(KNUT_VERSION_STRING);
QApplication::setApplicationVersion(core::knut_version());
QApplication::setWindowIcon(QIcon(":/gui/icons/knut-64.png"));

Q_INIT_RESOURCE(core);
Expand Down
Loading