-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (118 loc) · 3.91 KB
/
Copy pathcpp-ci.yml
File metadata and controls
131 lines (118 loc) · 3.91 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: cpp-ci
# Reusable C/C++ CI for BOTH tiers: optional apt packages and
# ccache, clang-format + cppcheck static gates, and caller-provided
# configure/build/test commands passed via env. Defaults target a CMake project;
# override the commands for Make/Meson/Bazel.
on:
workflow_call:
inputs:
runner:
type: string
default: 'amsterdam'
working_directory:
type: string
default: '.'
apt_packages:
description: 'Extra apt packages (space-separated), e.g. "cppcheck clang-tidy ninja-build".'
type: string
default: ''
enable_ccache:
description: 'Restore/save a ccache cache (wire -DCMAKE_CXX_COMPILER_LAUNCHER=ccache to use it).'
type: boolean
default: false
ccache_key:
type: string
default: 'cpp-ci'
configure_command:
description: 'Configure command (bash). Empty to skip.'
type: string
default: 'cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug'
build_command:
description: 'Build command (bash). Empty to skip.'
type: string
default: 'cmake --build build --parallel'
test_command:
description: 'Test command (bash). Empty to skip.'
type: string
default: 'ctest --test-dir build --output-on-failure'
format_check:
description: 'Run clang-format --dry-run -Werror over format_paths.'
type: boolean
default: false
format_paths:
description: 'Space-separated globs for clang-format when format_check is true.'
type: string
default: 'src/**/*.cpp src/**/*.hpp'
cppcheck:
description: 'Run cppcheck (add "cppcheck" to apt_packages).'
type: boolean
default: false
cppcheck_args:
type: string
default: '--enable=warning,portability --error-exitcode=1 .'
timeout_minutes:
type: number
default: 30
permissions: {}
defaults:
run:
shell: bash
jobs:
cpp:
name: cpp
runs-on: ${{ inputs.runner }}
timeout-minutes: ${{ inputs.timeout_minutes }}
permissions:
contents: read
defaults:
run:
working-directory: ${{ inputs.working_directory }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Install apt packages
if: ${{ inputs.apt_packages != '' }}
env:
APT_PACKAGES: ${{ inputs.apt_packages }}
run: |
sudo apt-get update
# shellcheck disable=SC2086
sudo apt-get install -y --no-install-recommends $APT_PACKAGES
- name: Set up ccache
if: ${{ inputs.enable_ccache }}
uses: hendrikmuhs/ccache-action@d62db5f07c26379fc4b4e0916f098a92573c3b03 # v1.2.23
with:
key: ${{ inputs.ccache_key }}
- name: Format check
if: ${{ inputs.format_check }}
env:
FORMAT_PATHS: ${{ inputs.format_paths }}
run: |
# shellcheck disable=SC2086
clang-format --dry-run -Werror $FORMAT_PATHS
- name: Configure
if: ${{ inputs.configure_command != '' }}
env:
CONFIGURE_COMMAND: ${{ inputs.configure_command }}
run: bash -c "$CONFIGURE_COMMAND"
- name: Build
if: ${{ inputs.build_command != '' }}
env:
BUILD_COMMAND: ${{ inputs.build_command }}
run: bash -c "$BUILD_COMMAND"
- name: cppcheck
if: ${{ inputs.cppcheck }}
env:
CPPCHECK_ARGS: ${{ inputs.cppcheck_args }}
run: |
# shellcheck disable=SC2086
cppcheck $CPPCHECK_ARGS
- name: Test
if: ${{ inputs.test_command != '' }}
env:
TEST_COMMAND: ${{ inputs.test_command }}
run: bash -c "$TEST_COMMAND"
- name: Summary
run: echo "C/C++ CI (configure + build + test) passed." >> "$GITHUB_STEP_SUMMARY"