github-actions - 减少 GitHub Actions 步骤中的样板文件
问题描述
最近,GitHub删除了几个默认安装在其运行器上的 C 和 C++ 编译器。
现在我需要在构建步骤中根据需要安装这些编译器。我使用以下两个步骤,一个用于 C,一个用于 C++。
- name: Install C Compiler
if: ${{ startsWith(matrix.c_compiler, 'gcc-') || startsWith(matrix.c_compiler, 'clang-') }}
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.c_compiler }}
- name: Install C++ Compiler
if: ${{ startsWith(matrix.cpp_compiler, 'g++-') || startsWith(matrix.cpp_compiler, 'clang++-') }}
run: |
sudo apt-get update
sudo apt-get install -y ${{ matrix.cpp_compiler }}
该if
条件检查我们是否实际使用版本化编译器,gcc-8
而不是默认的gcc
(不需要安装1)。
我想减少这个样板。例如,这两个步骤几乎相同,除了它们检查的变量matrix.c_compiler
vs matrix.cpp_compiler
、它们的名称和编译器的预期形式gcc-
vs g++-
。
有没有办法避免这种重复?
1 ...实际上尝试安装默认编译器并非无害:install clang clang++
在 GitHub 运行器上失败。
解决方案
推荐阅读
- node.js - 错误 find-up@4.1.0:引擎“节点”与此模块不兼容。预期版本“>=8”。Ember js + Heroku 部署
- c - C中的纯/常量函数
- python - 在python中将数据框从一行排列到多列
- sql - 对存储在 ms sql server 的 char 列中的日期或整数值使用关系运算符是否有效?
- postman - 尝试使用 Postman 对 Coinbase API 进行身份验证时,我收到“无效签名”
- asp.net-mvc - 列嵌套属性的 Kendo 网格 mvc 可过滤选项
- javascript - 当父元素的内部 HTML 被修改时,Javascript 取消事件
- html - 如何修复不可见边距参数?
- python - 降维 - Pyspark
- c++ - 使用 Structs 作为映射中的键,忽略 == 运算符,误报