我正在尝试为我的项目设置一个CodeQL分析工作流。我想一起分析Windows、Ubuntu和MacOS的代码,因此我决定将编译部分分成三种并行的方式,因为我必须对每个操作系统分别运行分析。到目前为止,我以这样的方式设置了工作流:
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: '45 22 * * 0'
jobs:
analyze:
name: Analyze
runs-on: ${{ matrix.os }}
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
language: [ 'cpp' ]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
- name: Installing extra dependencies and compiling (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install build-essential g++ libboost-all-dev wget unzip doctest-dev
exprtk_sha1=ca5c577917646ddba3f71ce6d5dd7d01f351ee80
wget https://github.com/ArashPartow/exprtk/archive/$exprtk_sha1.zip
mv $exprtk_sha1.zip exprtk-$exprtk_sha1.zip
unzip exprtk-$exprtk_sha1.zip
sudo cp exprtk-$exprtk_sha1/exprtk.hpp /usr/include/
rm -rf exprtk-*
make
- name: Installing extra dependencies and compiling (MacOS)
if: matrix.os == 'macos-latest'
run: |
brew install boost doctest
exprtk_sha1=ca5c577917646ddba3f71ce6d5dd7d01f351ee80
wget https://github.com/ArashPartow/exprtk/archive/$exprtk_sha1.zip
mv $exprtk_sha1.zip exprtk-$exprtk_sha1.zip
unzip exprtk-$exprtk_sha1.zip
sudo cp exprtk-$exprtk_sha1/exprtk.hpp /usr/local/include
rm -rf exprtk-*
make
- name: Installing extra dependencies and compiling (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install unzip wget
mkdir C:/install
cd C:/install
wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.zip | Out-Null
unzip boost_1_79_0.zip | Out-Null
mkdir C:/boost-build
mkdir C:/install/boost_1_79_0/boost-build
mkdir C:/boost
cd -
cd C:/install/boost_1_79_0/tools/build
.\bootstrap.bat gcc
.\b2 --prefix="C:/boost-build" install
$Env:PATH+=";C:/boost-build/bin"
cd -
cd C:/install/boost_1_79_0
b2 --build-dir="C:/install/boost_1_79_0/build" --build-type=complete --prefix="C:/boost" toolset=gcc install
cd -
cp -r C:/boost/include/boost-1_79/boost C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++
cp C:/boost/lib/* C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib
$Env:PATH+=";C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++"
$Env:PATH+=";C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib"
$Env:PATH+=";C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++"
$Env:PATH+=";C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib"
rd -r C:/install
rd -r C:/boost-build
wget https://github.com/doctest/doctest/archive/refs/heads/master.zip | Out-Null
unzip master.zip | Out-Null
mkdir C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/doctest
cp doctest-master/doctest/doctest.h C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/doctest
rd -r doctest-master
make
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2它运行良好,但问题是,在Windows部分中,它需要超过4个小时才能完成,因为我每次都必须下载和构建boost库,以便正确编译代码。
有办法加快进程吗?
我已经尝试过使用包管理器(即使许多库不是建立在Windows上的),但是情况并没有改变,或者出现了其他复杂情况:比如每次安装依赖项并将它们添加到系统路径时,我都必须找到它们,但是由于它们不容易找到,所以我不得不多次多次重新启动工作流来进行调试。
发布于 2022-06-27 14:27:29
如果下载和构建boost是瓶颈,我认为通过缓存该依赖可以大大加快速度,特别是因为它的版本或内容在CI流中并不经常更改。我已经将您的boost依赖项和项目构建步骤划分为两个不同的步骤,并缓存了前面的步骤。在本例中,您本质上是perma缓存您的boost依赖项,因为您有版本和它的路径硬编码,所以缓存键是任意的-我只是使用它的路径作为字符串,所以如果您在将来更新您的boost版本,很容易找到和替换它。在缓存命中和加载或缓存丢失以及重新下载和重建之后,您的工作流程将继续执行其余的构建步骤。
- name: Cache boost
if: matrix.os == 'windows-latest'
id: cache-boost
uses: actions/cache@v3
with:
path: C:/boost/include/boost-1_79/boost
key: 'C:/boost/include/boost-1_79/boost' # this key is arbitrary
- name: Installing boost upon cache miss (Windows)
if: matrix.os == 'windows-latest' && steps.cache-boost.outputs.cache-hit != 'true'
run: |
choco install unzip wget
mkdir C:/install
cd C:/install
wget https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.zip | Out-Null
unzip boost_1_79_0.zip | Out-Null
mkdir C:/boost-build
mkdir C:/install/boost_1_79_0/boost-build
mkdir C:/boost
cd -
cd C:/install/boost_1_79_0/tools/build
.\bootstrap.bat gcc
.\b2 --prefix="C:/boost-build" install
$Env:PATH+=";C:/boost-build/bin"
cd -
cd C:/install/boost_1_79_0
b2 --build-dir="C:/install/boost_1_79_0/build" --build-type=complete --prefix="C:/boost" toolset=gcc install
cd -
- name: Other build steps
if: matrix.os == 'windows-latest'
run: |
cp -r C:/boost/include/boost-1_79/boost C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++
cp C:/boost/lib/* C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib
$Env:PATH+=";C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++"
$Env:PATH+=";C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib"
$Env:PATH+=";C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++"
$Env:PATH+=";C:/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib"
rd -r C:/install
rd -r C:/boost-build
wget https://github.com/doctest/doctest/archive/refs/heads/master.zip | Out-Null
unzip master.zip | Out-Null
mkdir C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/doctest
cp doctest-master/doctest/doctest.h C:/ProgramData/Chocolatey/lib/mingw/tools/install/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/doctest
rd -r doctest-master我对C++不是很了解,所以如果您有其他的依赖项,这些依赖项本质上是按版本或路径硬编码的,那么您也可以缓存这些依赖项。
需要注意的是,有一个缓存数据的10 on限制,缓存上有一个为期一周的逐出。如果您的缓存超过了该大小限制,则始终会得到缓存丢失,因此缓存丢失步骤将始终执行。在这个场景中,我认为您可以在缓存boost目录之前压缩它(记得在最后的项目构建步骤中进行解压缩),以尝试达到这个大小限制。不过,actions/cache已经使用了自己的压缩,所以ymmv的实际帮助有多大(也许可以尝试另一种压缩工具?)在绝对最坏的情况下,如果您有云存储并将其解压缩,您可以将boost文件转储到blob存储中,这实际上是创建您自己的缓存-- GitHub操作和Azure之间的延迟往往很低,因为很多平台基础设施都托管在那里。如果这样做,您不需要拆分构建步骤本身,您只需要修改构建步骤就可以从存储提供程序中提取数据。
资料来源:
https://stackoverflow.com/questions/72769164
复制相似问题