0

Currently I have a job on linux with a fairly complex matrix.

jobs:
  linux:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-22.04, ...]
        compiler: [{cc: gcc, cxx: g++}, {cc:clang, cxx:clang++}]
        config: [debug, release]
        cpp_std: [17, 20]
        ... # Address sanitizer, thread sanitizer, etc.

And I'm using ccache. So I need to make a unique key for the job. However, the more I complicate the matrix the more complicated the key gets.

Here is what I mean

- name: Setup ccache
  uses: hendrikmuhs/ccache-action@v1.2
  with:
    key: ${{ matrix.os }}-${{ matrix.config }}-${{ matrix.compiler.cc }}-${{ matrix.compiler.cxx }}-${{ matrix.cpp_std }}-${{ matrix.flags.c }}-${{ matrix.flags.ld }}

The key is over 158 characters and is very easy to forget to update correctly.

Is there a better way to write this?

jpr42
  • 718
  • 3
  • 14
  • Are you showing a simplified matrix? As far as I can tell, only `config` has more than one value, everything else has just one? – Benjamin W. Jun 21 '23 at 22:33
  • I'm showing a simplified matrix. I can edit the post if showing the full matrix would help. I just thought it would clutter the question. – jpr42 Jun 21 '23 at 22:44
  • You can automate this. You can generate the key automatically by converting `matrix` to JSON using [`toJson`](https://docs.github.com/en/actions/learn-github-actions/expressions#tojson) function, get keys recursively with [`jq`](https://jqlang.github.io/jq/), retrieve their respective values, combine those, and set the final value as an env var or an output parameter to be used with `key` of `ccache`. You might have to modify your matrix to make this work. Depends on your handling though. – Azeem Jun 23 '23 at 06:05

0 Answers0