Skip to content

Commit c9cbc52

Browse files
committed
[ci] Add basic github actions infrastructure
1 parent b412d66 commit c9cbc52

File tree

4 files changed

+177
-0
lines changed

4 files changed

+177
-0
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
name: ${{ matrix.compiler }}
16+
runs-on: ubuntu-latest
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
compiler: [gcc, clang]
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: 3.11
29+
30+
- name: Install dependencies
31+
run: |
32+
sudo apt-get update
33+
if [ "${{ matrix.compiler }}" = "gcc" ]; then
34+
sudo apt-get install -y gcc g++ cmake make
35+
echo "CC=gcc" >> $GITHUB_ENV
36+
echo "CXX=g++" >> $GITHUB_ENV
37+
else
38+
sudo apt-get install -y clang cmake make
39+
echo "CC=clang" >> $GITHUB_ENV
40+
echo "CXX=clang++" >> $GITHUB_ENV
41+
fi
42+
43+
- name: Configure project
44+
run: |
45+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
46+
47+
- name: Build project
48+
run: |
49+
cmake --build build -- -j$(nproc)
50+
51+
- name: Run tests
52+
run: |
53+
ctest --test-dir build --output-on-failure

.github/workflows/clang-format.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: clang-format
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.h'
7+
- '**/*.cpp'
8+
- '**/*.cc'
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
precheckin:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout PR branch
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
fetch-depth: 0
23+
24+
- name: Install clang-format
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y clang-format-18
28+
clang-format-18 --version
29+
30+
- name: Run git-clang-format
31+
run: |
32+
PR_BASE=$(git rev-list ${{ github.event.pull_request.head.sha }} ^${{ github.event.pull_request.base.sha }} | tail --lines 1 | xargs -I {} git rev-parse {}~1)
33+
echo "running git clang-format against $PR_BASE commit"
34+
GIT="git -c color.ui=always -c diff.wsErrorHighlight=all -c color.diff.whitespace='red reverse'"
35+
36+
if ! $GIT clang-format-18 --diff --binary clang-format-18 $PR_BASE; then
37+
echo "::error::Code is not properly formatted. Please run 'git clang-format-18 HEAD~' locally. \n
38+
for multiple commits we should place the formatting changes in the related commit with:\n
39+
\t\tgit rebase -i -x 'git-clang-format-18 master && git commit -a --allow-empty --fixup=HEAD' --strategy-option=theirs origin/master\n
40+
\t\t Then inspect the results with: git log --oneline\n
41+
\t\t Then squash without poluting the history with: git rebase --autosquash -i master\n"
42+
exit 1
43+
fi
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Post clang-tidy review comments
2+
3+
on:
4+
workflow_run:
5+
workflows: ["clang-tidy-review"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
checks: write
11+
pull-requests: write
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Post review comments
23+
id: post-review
24+
uses: ZedThree/clang-tidy-review/[email protected]
25+
with:
26+
max_comments: 10
27+
28+
# If there are any comments, fail the check
29+
- if: steps.post-review.outputs.total_comments > 0
30+
run: exit 1
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: clang-tidy-review
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.h'
7+
- '**.cpp'
8+
- '**.cc'
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
review:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout PR branch
19+
uses: actions/checkout@v4
20+
21+
- name: Install LLVM and Clang
22+
uses: KyleMayes/install-llvm-action@v2
23+
with:
24+
version: "20"
25+
26+
- name: install lit
27+
run: pip install lit
28+
29+
- name: run git config command
30+
run: |
31+
git config --global --add safe.directory /github/workspace
32+
33+
- name: Run clang-tidy
34+
uses: ZedThree/[email protected]
35+
id: review
36+
with:
37+
build_dir: build
38+
apt_packages: cmake,libxml2,libxml2-dev,libtinfo-dev,zlib1g-dev,libzstd-dev
39+
exclude: "test/*,unittests/*"
40+
split_workflow: true
41+
config_file: .clang-tidy
42+
cmake_command: >
43+
CC=$GITHUB_WORKSPACE/llvm/bin/clang CXX=$GITHUB_WORKSPACE/llvm/bin/clang++
44+
cmake . -B build -DLLVM_DIR="$GITHUB_WORKSPACE/llvm"
45+
-DClang_DIR="$GITHUB_WORKSPACE/llvm"
46+
-DCMAKE_BUILD_TYPE="Release"
47+
-DLLVM_EXTERNAL_LIT="`which lit`"
48+
-DCMAKE_EXPORT_COMPILE_COMMANDS=On
49+
50+
- name: Upload artifacts
51+
uses: ZedThree/clang-tidy-review/[email protected]

0 commit comments

Comments
 (0)