我正在嘗試在 Github 上為我的專案設定 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 上建立的),但是情況并沒有改變,或者發生了其他復雜情況:比如我每次安裝依賴項時都必須找到并將它們添加到系統路徑,但由于它們不容易找到,我不得不多次重新啟動作業流進行除錯。
uj5u.com熱心網友回復:
如果下載和構建boost是瓶頸,我認為您可以通過快取該依賴項來獲得顯著的加速,特別是因為它的版本或內容在您的 CI 流程中不會經常更改。我已將您的boost依賴項和專案構建步驟分成 2 個不同的步驟,并將前者快取在下面。在這種情況下,您實際上是在永久快取您的 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 不是很了解,所以如果你有其他依賴項,那么你引入的依賴項本質上是由版本或路徑硬編碼的,你也可以快取它們。
需要注意的 2 個警告是快取資料有 10GB 的限制,并且快取有 1 周的驅逐期。如果您的快取超過該大小限制,您將始終遇到快取未命中,因此將始終執行快取未命中步驟。在這種情況下,我認為您可以boost在快取目錄之前對其進行壓縮(請記住在最后的專案構建步驟中解壓縮)以嘗試低于該大小限制。actions/cache不過,它已經使用了自己的壓縮,所以 ymmv 這實際上有多大幫助(也許嘗試不同的壓縮工具?)。在絕對最壞的情況下,你可以傾倒你的boost如果您在某處有云存盤并將其拉下,則將檔案放入 blob 存盤中,本質上是創建自己的快取 - GitHub Actions 和 Azure 之間的延遲往往非常低,因為許多平臺基礎架構都托管在那里。如果你這樣做,你不需要拆分你的構建步驟本身,你只需要修改你的構建步驟,而不是從你的存盤提供者那里拉取資料。
資料來源:
- GitHub Actions 快取操作:https ://github.com/actions/cache
- 結合 if 條件:https ://docs.github.com/en/actions/learn-github-actions/expressions#operators
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/497137.html
