总共3个配置.我不想使用所有C和C ++编译器版本的 product 构建.没有gcc/g ++-8等.如何指定具有这三种配置的矩阵,每种配置都设置两个变量?当前我正在使用它(请注意,由于指定了2个操作系统,因此总共有6个配置): 策略:矩阵:操作系统:[ubuntu-16.04,最新的ubuntu]cpp_compiler:[g ++,g ++-8,clang ++]包括:-c_compiler:gcc-cpp_ompiler:g ++-8c_compiler:gcc-8-cpp_compiler:++++c_compiler:c 本质上,C ++编译器( cpp_compiler )被用作主版本,然后 include 以一种怪异的方式被用来设置 c_compiler 基于 cpp_compiler 版本,但必须有更好的选择... 解决方案我刚刚尝试了一下,结果发现您可以将数组嵌套在构建矩阵中,但是未记录.因此,您可以在 job.matrix 中创建一个包含编译器数组的数组.我们称之为 compiler-version : compiler-version:[[g ++,gcc],[g ++-8,gcc-8],[clang ++,clang]] .然后,您可以使用零索引访问 compiler-version 数组的每个元素中的每个值:C ++编译器的 matrix.compiler-version [0] 和 matrix.compiler-version [1] 及其C对应版本.您的工作流程将变为: 策略:矩阵:操作系统:[ubuntu-16.04,最新的ubuntu]编译器版本:[[g ++,gcc],[g ++-8,gcc-8],[clang ++,clang]]脚步:#....结帐步骤-名称:使用C ++编译器编译文件环境:编译器:$ {{matrix.compiler-version [0]}}运行:$ COMPILER file.c./a.out-名称:使用C编译器编译文件环境:编译器:$ {{matrix.compiler-version [1]}}运行:$ COMPILER file.c./a.out 我用2个Python版本和2个Ubuntu版本组成了一个最小示例,其中3.7与Ubuntu-18.04配对,而3.8与Ubuntu-20.04配对.您可以在此处看到工作流程文件及其相应的运行此处.此解决方案避免了必须在工作流文件的2个位置定义C ++选项的尴尬.即使它没有记录,我也认为它是稳定的,因为GitHub Actions上下文对象是(或至少像JavaScript对象一样),因此我们实际上只是将数组文字定义为矩阵对象属性并访问它们的值.I want to build against three compiler versions for a C and C++ project: gcc, gcc-8 and clang (for the C compiler), which should use g++, g++-8 and clang++ respectively for the C++ compiler.That's 3 configurations total. I won't want to build with the product of all C and C++ compiler versions, i.e,. no gcc/g++-8, etc.How can I specify a matrix with those three configurations, each which sets two variables?Currently I'm using this (note that 2 OSes are specified, so it's 6 configs in total): strategy: matrix: os: [ubuntu-16.04, ubuntu-latest] cpp_compiler: [g++, g++-8, clang++] include: - c_compiler: gcc - cpp_ompiler: g++-8 c_compiler: gcc-8 - cpp_compiler: clang++ c_compiler: clangEssentially, the C++ compiler (cpp_compiler) is used as the master version, and then include is used in a hacky way to set c_compiler based on the cpp_compiler version, but there must be something better... 解决方案 I just tried this out and it turns out you can nest arrays in a build matrix, but it's undocumented. Therefore, you can create an array of arrays of compilers in your job.matrix. Let's call it compiler-version: compiler-version: [[g++, gcc], [g++-8, gcc-8], [clang++, clang]]. Then you can access each value in each element of the compiler-version array with zero-indexing: matrix.compiler-version[0] for the C++ compiler, and matrix.compiler-version[1] its C counterpart.Your workflow would become: strategy: matrix: os: [ubuntu-16.04, ubuntu-latest] compiler-version: [[g++, gcc], [g++-8, gcc-8], [clang++, clang]] steps: # .... checkout steps - name: Compile file with C++ compiler env: COMPILER: ${{ matrix.compiler-version[0] }} run: | $COMPILER file.c ./a.out - name: Compile file with C compiler env: COMPILER: ${{ matrix.compiler-version[1] }} run: | $COMPILER file.c ./a.outI've worked up a minimal example with a matrix of 2 Python versions and 2 Ubuntu versions, where 3.7 is paired with Ubuntu-18.04, and 3.8 is paired with Ubuntu-20.04. You can see the workflow file here and its corresponding run here.This solution gets around the awkwardness of having to define your C++ options in 2 places in the workflow file. Even though it's undocumented, I assume it's stable since GitHub Actions context objects are (or at least are treated like) JavaScript objects, so we're really just defining array literals as the matrix object attributes and accessing their values. 这篇关于github动作矩阵中的配对值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 13:19