fix sonar scan not running against PR merge branch #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check, Build and Test | |
on: | |
pull_request: | |
push: | |
# # Debug setup: | |
# env: | |
# OGDF_UTILS_PREQUEL: "set -x" | |
# CCACHE_DEBUG: 1 | |
# CCACHE_DEBUGDIR: ${{ github.workspace }}/ccache-debug | |
# VERBOSE: 1 | |
jobs: | |
# We don't want to run the CI twice for PRs from branches within the repo, so for a push event we only run the CI if | |
# the push was to the master branch or to a fork of the repo, while running the CI for all (in- and cross-repo) PRs. | |
# Workflows skipped due to filters block PRs from being merged (their required jobs count as "pending"), | |
# while jobs skipped due to conditions still count as success, so we apply the filter here. | |
precheck: | |
name: "Check whether to run the CI" | |
runs-on: ubuntu-latest | |
if: github.event.repository.full_name != 'ogdf/ogdf' || github.event_name != 'push' || github.event.ref == 'refs/heads/master' | |
steps: | |
- run: echo "Running CI pipeline!" | |
style: | |
needs: [ precheck ] | |
name: "Check code style" | |
runs-on: ubuntu-latest | |
container: docker.io/ogdf/clang:15 | |
steps: | |
- name: "Add workspace as a safe directory in containers" | |
run: git config --system --add safe.directory $GITHUB_WORKSPACE | |
- uses: actions/checkout@v4 | |
- name: Run style checks | |
run: util/style/test_all.sh | |
- name: Generate patch with style fixes upon failure | |
run: | | |
echo "Please download the artifact and apply style-fixes.patch to fix code style problems." | |
util/style/test_all.sh -f | |
git diff > style-fixes.patch | |
git status | |
if: failure() | |
- name: Store patch with style fixes | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: style-fixes | |
path: style-fixes.patch | |
dirs: | |
needs: [ precheck ] | |
name: "Check directory structure" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Test directory structure | |
run: util/test_directory_structure.sh | |
docs: | |
needs: [ precheck ] | |
name: "Check Doxygen" | |
runs-on: ubuntu-latest | |
container: docker.io/ogdf/clang:15 | |
steps: | |
- uses: actions/checkout@v4 | |
- run: util/test_doxygen.sh | |
self-sufficiency: | |
needs: [ precheck ] | |
name: "Test self-sufficiency" | |
runs-on: ubuntu-latest | |
env: | |
CCACHE_COMPILERCHECK: "%compiler% -v" | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set-up ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ${{ github.job }} | |
- name: Test self-sufficiency | |
run: | | |
# the script calls gcc directly, so ensure that it finds the ccache version instead | |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH" | |
util/test_self-sufficiency.sh | |
- uses: actions/upload-artifact@v4 | |
name: Upload ccache debug info | |
if: ${{ env.CCACHE_DEBUG == 1 }} | |
with: | |
name: ${{ github.job }} | |
path: ${{ github.workspace }}/ccache-debug | |
static-analysis: | |
name: "Static Analysis" | |
runs-on: ubuntu-latest | |
container: docker.io/ogdf/clang:15 | |
needs: [ style, dirs, self-sufficiency, docs ] | |
env: | |
CCACHE_COMPILERCHECK: "%compiler% -v" | |
steps: | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
STEPS_CONTEXT: ${{ toJson(steps) }} | |
RUNNER_CONTEXT: ${{ toJson(runner) }} | |
STRATEGY_CONTEXT: ${{ toJson(strategy) }} | |
run: | | |
env | |
- name: "Add workspace as a safe directory in containers" | |
run: git config --system --add safe.directory $GITHUB_WORKSPACE | |
- uses: actions/checkout@v4 | |
- name: Set-up ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ${{ github.job }} | |
- name: Restore clang-tidy cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ github.workspace }}/.ctcache | |
key: clang-tidy-cache-${{ github.run_id }}.${{ github.run_attempt }} | |
restore-keys: clang-tidy-cache | |
- name: Run analysis | |
env: | |
CTCACHE_LOCAL: 1 | |
CTCACHE_DIR: ${{ github.workspace }}/.ctcache | |
CTCACHE_SAVE_OUTPUT: 1 | |
CTCACHE_IGNORE_OUTPUT: 1 | |
# CTCACHE_DUMP: ${{ env.CCACHE_DEBUG }} # defining the var is enough to enable | |
# CTCACHE_DUMP_DIR: ${{ github.workspace }}/ctcache-debug | |
run: | | |
clang-tidy-cache --zero-stats | |
util/test_static_analysis.sh -DOGDF_ARCH=haswell -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
cat static-analysis/clang-tidy.txt | python3 -m clang_tidy_converter sq > static-analysis/clang-tidy.json | |
clang-tidy-cache --show-stats | |
du -sh $CTCACHE_DIR | |
find .ctcache -mindepth 1 -type f -atime +7 -delete | |
find .ctcache -mindepth 1 -type d -empty -delete | |
du -sh $CTCACHE_DIR | |
shell: bash | |
- name: Report unused files | |
run: | | |
cat static-analysis/unused-headers.txt | |
- name: Save PR number | |
if: github.event_name == 'pull_request' | |
run: | | |
echo ${{ github.event.number }} > static-analysis/PR-NUMBER | |
- name: Store static analysis results | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: static-analysis | |
path: static-analysis/ | |
- name: Clean binaries | |
run: | | |
cd build-static-analysis | |
make clean | |
- name: Store static analysis results | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: build-static-analysis | |
path: build-static-analysis/ | |
- uses: actions/upload-artifact@v4 | |
name: Upload ccache debug info | |
if: ${{ env.CCACHE_DEBUG == 1 || env.CTCACHE_DUMP == 1 }} | |
with: | |
name: ${{ github.job }} | |
path: | | |
${{ github.workspace }}/ccache-debug | |
${{ github.workspace }}/ctcache-debug | |
- name: Save clang-tidy cache | |
uses: actions/cache/save@v4 | |
if: always() | |
with: | |
path: ${{ github.workspace }}/.ctcache | |
key: clang-tidy-cache-${{ github.run_id }}.${{ github.run_attempt }} | |
coverage: | |
name: "Analyze Test Coverage" | |
runs-on: ubuntu-latest | |
container: docker.io/ogdf/clang:18 | |
needs: [ style, dirs, self-sufficiency, docs ] | |
env: | |
CCACHE_COMPILERCHECK: "%compiler% -v" | |
steps: | |
- name: "Add workspace as a safe directory in containers" | |
run: git config --system --add safe.directory $GITHUB_WORKSPACE | |
- uses: actions/checkout@v4 | |
- name: Set-up ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ${{ github.job }} | |
- name: Run analysis | |
run: | | |
util/test_coverage.sh -DOGDF_ARCH=haswell -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
shell: bash | |
- name: Store coverage data | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: coverage | |
path: coverage/ | |
- uses: actions/upload-artifact@v4 | |
name: Upload ccache debug info | |
if: ${{ env.CCACHE_DEBUG == 1 }} | |
with: | |
name: ${{ github.job }} | |
path: ${{ github.workspace }}/ccache-debug | |
build-linux: | |
name: "Test ${{ matrix.mode }} build on Linux with ${{ matrix.compiler }}" | |
strategy: | |
matrix: # when updating compilers, also update the prune-all-caches script | |
mode: [ debug, release ] | |
compiler: [ 'gcc:9', 'gcc:13', 'clang:15' ] | |
runs-on: ubuntu-latest | |
container: docker.io/ogdf/${{ matrix.compiler }} | |
needs: [ style, dirs, self-sufficiency, docs ] | |
env: | |
CCACHE_COMPILERCHECK: "%compiler% -v" | |
steps: | |
- name: Process compiler name | |
# artifact names may not contain colons and GHA has no string splitting function, so we do it in bash | |
run: | | |
S="${{ matrix.compiler }}" | |
A=(${S//:/ }) | |
echo "GH_COMPILER_NAME=${A[0]}" >> "$GITHUB_ENV" | |
echo "GH_COMPILER_VER=${A[1]}" >> "$GITHUB_ENV" | |
shell: bash | |
- name: "Add workspace as a safe directory in containers" | |
run: git config --system --add safe.directory $GITHUB_WORKSPACE | |
- uses: actions/checkout@v4 | |
- name: Set-up ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ${{ github.job }}-${{ matrix.compiler }}-${{ matrix.mode }} | |
- name: Check ccache version | |
run: ccache --version | |
- name: Check CPU model | |
run: | | |
lscpu | |
echo "Hard limits" | |
ulimit -Ha | |
echo | |
echo "Soft limits" | |
ulimit -Sa | |
- name: Test ${{ matrix.mode }} build with ${{ matrix.compiler }} and run | |
run: | | |
util/test_build_and_run.sh \ | |
${{ matrix.compiler == 'gcc:9' && 'dynamic' || 'static' }} \ | |
${{ matrix.mode }} \ | |
${{ env.GH_COMPILER_NAME }} \ | |
default_s \ | |
${{ matrix.compiler != 'clang:15' && '-DOGDF_INCLUDE_CGAL=ON -DOGDF_USE_ASSERT_EXCEPTIONS=ON' || '' }} \ | |
-DOGDF_USE_ASSERT_EXCEPTIONS=ON -DOGDF_ARCH=haswell \ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
# extra flags used when collecting coverage (on clang:15) are disabled here | |
# --- | |
# see "Cloud hosts used by GitHub-hosted runners" in the GH Actions docs | |
# for the oldest used microarchitecture to use with OGDF_ARCH | |
- uses: actions/upload-artifact@v4 | |
name: Upload ccache debug info | |
if: ${{ env.CCACHE_DEBUG == 1 }} | |
with: | |
# artifact names may not contain colons, so we need to be more careful with the compiler variable | |
name: ${{ github.job }}-${{ env.GH_COMPILER_NAME }}-${{ env.GH_COMPILER_VER }}-${{ matrix.mode }} | |
path: ${{ github.workspace }}/ccache-debug | |
- name: Store failed test reports | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: failed-tests-logs-${{ github.job }}-${{ env.GH_COMPILER_NAME }}-${{ env.GH_COMPILER_VER }}-${{ matrix.mode }} | |
path: "./failed-tests-logs" | |
build-macos: | |
name: "Test ${{ matrix.mode }} build on ${{ matrix.os }}" | |
strategy: | |
matrix: # when updating macos versions, also update the prune-all-caches script | |
mode: [ debug, release ] | |
os: [ macos-13 ] # latest/14 is with M1, while macos-13 is intel | |
runs-on: ${{ matrix.os }} | |
needs: [ style, dirs, self-sufficiency, docs ] | |
steps: | |
- uses: actions/checkout@v4 | |
- run: brew install coreutils findutils | |
- name: Set-up ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: build-${{ matrix.os }}-${{ matrix.mode }} | |
- name: Check CPU model | |
run: | | |
uname -av | |
sysctl machdep.cpu | |
system_profiler system_profiler SPSoftwareDataType SPHardwareDataType | |
echo "Hard limits" | |
ulimit -Ha | |
echo | |
echo "Soft limits" | |
ulimit -Sa | |
- name: Test ${{ matrix.mode }} build and run | |
run: | | |
util/test_build_and_run.sh \ | |
static \ | |
${{ matrix.mode }} \ | |
default_c \ | |
default_s \ | |
-DOGDF_USE_ASSERT_EXCEPTIONS=ON -DOGDF_ARCH=ivybridge \ | |
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache | |
# ivybridge is the oldest arch we encountered from SIGILL ccaching problems | |
- uses: actions/upload-artifact@v4 | |
name: Upload ccache debug info | |
if: ${{ env.CCACHE_DEBUG == 1 }} | |
with: | |
name: build-${{ matrix.os }}-${{ matrix.mode }} | |
path: ${{ github.workspace }}/ccache-debug | |
- name: Store failed test reports | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: failed-tests-logs-build-${{ matrix.os }}-${{ matrix.mode }} | |
path: "./failed-tests-logs" | |
build-windows: | |
name: "Test ${{ matrix.mode }} build on Windows" | |
strategy: | |
matrix: | |
mode: [ debug, release ] | |
runs-on: windows-latest | |
needs: [ style, dirs, self-sufficiency, docs ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: microsoft/setup-msbuild@v2 | |
- name: Set-up ccache | |
uses: hendrikmuhs/[email protected] | |
with: | |
key: ${{ github.job }}-${{ matrix.mode }} | |
- name: Test ${{ matrix.mode }} build and run | |
run: powershell util\test_build_and_run.ps1 ${{ matrix.mode == 'debug' && '-debug' }} | |
env: | |
CMAKE_C_COMPILER_LAUNCHER: ccache.exe | |
CMAKE_CXX_COMPILER_LAUNCHER: ccache.exe | |
- uses: actions/upload-artifact@v4 | |
name: Upload ccache debug info | |
if: ${{ env.CCACHE_DEBUG == 1 }} | |
with: | |
name: ${{ github.job }}-${{ matrix.mode }} | |
path: ${{ github.workspace }}/ccache-debug | |
# this is mostly used to keep the required status checks for PR merging simple | |
summary: | |
needs: [ build-linux, build-macos, build-windows, static-analysis, coverage ] | |
name: "All tests succeeded" | |
runs-on: ubuntu-latest | |
steps: | |
- run: echo "Everything worked!" |