gpt4 book ai didi

github-actions - github Action 矩阵中的配对值

转载 作者:行者123 更新时间:2023-12-04 00:51:36 24 4
gpt4 key购买 nike

我想针对 C 和 C++ 项目的三个编译器版本进行构建:gcc、gcc-8 和 clang(对于 C 编译器),对于 C++ 编译器,它们应该分别使用 g++、g++-8 和 clang++。
总共3个配置。我不想使用所有 C 和 C++ 编译器版本的产品进行构建,即。没有 gcc/g++-8 等。
如何指定具有这三种配置的矩阵,每种配置都设置两个变量?
目前我正在使用它(请注意,指定了 2 个操作系统,因此总共有 6 个配置):

    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: clang
本质上,C++ 编译器( cpp_compiler )用作主版本,然后是 include以一种骇人听闻的方式用于设置 c_compiler基于 cpp_compiler版本,但必须有更好的东西......

最佳答案

我刚刚尝试了这个,结果证明你可以在构建矩阵中嵌套数组,但它没有记录。因此,您可以在 job.matrix 中创建编译器数组的数组。 .我们叫它compiler-version :compiler-version: [[g++, gcc], [g++-8, gcc-8], [clang++, clang]] .然后你可以访问 compiler-version 的每个元素中的每个值零索引数组:matrix.compiler-version[0]对于 C++ 编译器,和 matrix.compiler-version[1]它的 C 对应物。
您的工作流程将变成:

    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.out
我已经用 2 个 Python 版本和 2 个 Ubuntu 版本的矩阵编写了一个最小示例,其中 3.7 与 Ubuntu-18.04 配对,3.8 与 Ubuntu-20.04 配对。可以看到工作流文件 here及其对应的运行 here .
此解决方案解决了必须在工作流文件中的 2 个位置定义 C++ 选项的尴尬。即使它没有记录,我认为它是稳定的,因为 GitHub Actions 上下文对象是(或至少被视为)JavaScript 对象,所以我们实际上只是将数组文字定义为矩阵对象属性并访问它们的值。

关于github-actions - github Action 矩阵中的配对值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66025220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com