Add ccache Github workflow #6
Workflow file for this run
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: CCache Build | |
on: | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
cmake-build: | |
name: CMake Build | |
runs-on: ubuntu-latest | |
container: | |
image: fedora:rawhide | |
strategy: | |
fail-fast: false # don't fail all matrix jobs if one of them fails | |
matrix: | |
compiler: ['gcc', clang] # gcc is the default | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# this step needs to be incorporated in our container that we use for testing | |
- name: Install dependencies | |
run: | | |
dnf install -y ccache clang && dnf builddep -y ./dnf5.spec | |
- name: Configure CC CXX env variables | |
id: configure_compiler | |
run: | | |
if [[ "${{matrix.compiler}}" -eq "clang" ]]; then | |
echo "cxx=/usr/lib64/ccache/clang++" >> "$GITHUB_OUTPUT" | |
echo "cc=/usr/lib64/ccache/clang" >> "$GITHUB_OUTPUT" | |
else | |
echo "cxx=/usr/lib64/ccache/g++" >> "$GITHUB_OUTPUT" | |
echo "cc=/usr/lib64/ccache/gcc" >> "$GITHUB_OUTPUT" | |
fi | |
# make sure that for every build the GitHub Actions cache key is unique | |
- name: Prepare CCache timestamp | |
id: ccache_cache_timestamp | |
run: | |
echo "timestamp=$(date +%Y-%m-%d-%H:%M:%S)-UTC" >> "$GITHUB_OUTPUT" | |
- name: Cache CCache files | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/ccache | |
# cache is saved with this hierarchy | |
# dnf5-ccache-gcc-pr-main-111-2023-01-01-00:00:00-UTC | |
# -clang-pr-main-111-2023-01-01-00:00:00-UTC | |
key: ${{ github.event.repository.name }}-ccache-${{ matrix.compiler }}-pr-${{ github.base_ref }}-${{ github.event.number }}-${{ steps.ccache_cache_timestamp.outputs.timestamp }} | |
# we want to match the latest cache prioritizing the same PR (e.g. | |
# 111), then the same branch (e.g. main), and, in all cases, we want | |
# to match the project-compiler (gcc,clang) match by date is not | |
# needed since caches are always matched by date. | |
# | |
# Example: dnf5-ccache-clang-pr-devel-111-2023-01-01-00:00:00-UTC will | |
# try to fetch cache from the same pr, 111 against devel. if no pr is | |
# found it will try to fetch any pr against devel branch. | |
restore-keys: | | |
${{ github.event.repository.name }}-ccache-${{ matrix.compiler }}pr-${{ github.base_ref }}-${{ github.event.number }}- | |
${{ github.event.repository.name }}-ccache-${{ matrix.compiler }}pr-${{ github.base_ref }}- | |
- name: Zero CCache statistics | |
run: ccache -z | |
- name: Configure DNF5 with CMake | |
run: CXX=${{ steps.configure_compiler.outputs.cxx }} CC=${{ steps.configure_compiler.outputs.cc }} cmake -S . -B build | |
- name: Build DNF5 | |
id: ccache-build | |
run: cmake --build build | |
- name: Display CCache statistics | |
run: ccache -s |