-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-ci.sh
More file actions
executable file
·116 lines (97 loc) · 3.2 KB
/
run-ci.sh
File metadata and controls
executable file
·116 lines (97 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
set -euo pipefail
# Local CI runner that mirrors .github/workflows/ci.yml inside Docker
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
IMAGE_NAME="siderust-cpp-ci"
IMAGE_TAG="local"
IMAGE="${IMAGE_NAME}:${IMAGE_TAG}"
bold() { printf '\e[1m%s\e[0m\n' "$*"; }
build_image() {
bold "Building Docker image (${IMAGE})"
docker build -t "${IMAGE}" "${ROOT_DIR}"
}
run_container() {
local cmd=$1
local flags=(--rm --init -v "${ROOT_DIR}:/workspace")
if [ -t 1 ]; then
flags+=(-it)
fi
docker run "${flags[@]}" "${IMAGE}" bash -lc "${cmd}"
}
container_script() {
cat <<'EOS'
set -euo pipefail
export CARGO_TERM_COLOR=always
export CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_BUILD_PARALLEL_LEVEL:-2}
cd /workspace
echo "==> Selected dependency revisions"
git submodule status --recursive
echo
echo "siderust-ffi: $(git -C siderust/siderust-ffi rev-parse HEAD) ($(git -C siderust/siderust-ffi describe --tags --always 2>/dev/null || true))"
echo "siderust: $(git -C siderust rev-parse HEAD) ($(git -C siderust describe --tags --always 2>/dev/null || true))"
run_lint() {
echo "==> Lint: configure + clang-format + clang-tidy"
rm -rf build
cmake -S . -B build -G Ninja -DSIDERUST_BUILD_DOCS=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
mapfile -t format_files < <(git ls-files '*.hpp' '*.cpp')
if [ ${#format_files[@]} -gt 0 ]; then
clang-format --dry-run --Werror "${format_files[@]}"
else
echo "No C++ files to format"
fi
mapfile -t tidy_files < <(git ls-files '*.cpp')
if [ ${#tidy_files[@]} -gt 0 ]; then
for f in "${tidy_files[@]}"; do
echo "clang-tidy: ${f}"
clang-tidy -p build --warnings-as-errors='*' "${f}"
done
else
echo "No C++ source files for clang-tidy"
fi
}
run_build_test_docs() {
echo "==> Build + Test + Docs"
rm -rf build
cmake -S . -B build -G Ninja -DSIDERUST_BUILD_DOCS=ON
cmake --build build --target test_siderust
ctest --test-dir build --output-on-failure -L siderust_cpp
cmake --build build --target docs
}
run_coverage() {
echo "==> Coverage"
rm -rf build-coverage coverage.xml coverage_html code-coverage-results.md
cmake -S . -B build-coverage -G Ninja \
-DSIDERUST_BUILD_DOCS=OFF \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="--coverage" \
-DCMAKE_EXE_LINKER_FLAGS="--coverage"
cmake --build build-coverage --target test_siderust
ctest --test-dir build-coverage --output-on-failure -L siderust_cpp
mkdir -p coverage_html
gcovr \
--root . \
--exclude 'build-coverage[^/]*/.*' \
--exclude 'siderust/.*' \
--exclude 'tempoch-cpp/.*' \
--exclude 'tests/.*' \
--exclude 'examples/.*' \
--xml \
--output coverage.xml
gcovr \
--root . \
--exclude 'build-coverage[^/]*/.*' \
--exclude 'siderust/.*' \
--exclude 'tempoch-cpp/.*' \
--exclude 'tests/.*' \
--exclude 'examples/.*' \
--html-details \
--output coverage_html/index.html
}
run_lint
run_build_test_docs
run_coverage
echo "==> All CI steps completed"
EOS
}
build_image
run_container "$(container_script)"