Skip to content

Commit 2ea6cc2

Browse files
committed
Add basic unit test GitHub workflow
1 parent 446bdcd commit 2ea6cc2

3 files changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Install cgreen test framework with sudo"
2+
description: "Build and install a cgreen release from source with sudo"
3+
4+
inputs:
5+
hash:
6+
description: "SHA256 hash of the downloaded cgreen archive."
7+
default: "fe6be434cbe280330420106bd5d667f1bc84ae9468960053100dbf17071036b9"
8+
version:
9+
description: "Version of the release to download."
10+
default: "1.6.2"
11+
12+
branding:
13+
icon: "package"
14+
color: "green"
15+
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: "Install dependencies"
20+
shell: bash
21+
run: |
22+
sudo apt-get update && \
23+
sudo apt-get install -y --no-install-recommends --no-install-suggests \
24+
build-essential \
25+
ca-certificates \
26+
cmake \
27+
curl \
28+
gcc \
29+
&& rm -rf /var/lib/apt/lists/*
30+
- name: "Install dependencies"
31+
shell: bash
32+
run: curl -sSL -o cgreen.tar.gz https://github.com/cgreen-devs/cgreen/archive/refs/tags/${{ inputs.version }}.tar.gz
33+
- name: "Validate cgreen archive"
34+
shell: bash
35+
run: |
36+
echo "${{ inputs.hash }} cgreen.tar.gz" | sha256sum -c -
37+
- name: "Build and install cgreen"
38+
shell: bash
39+
run: |
40+
tar -xzf cgreen.tar.gz
41+
cd cgreen-*
42+
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release
43+
sudo cmake --build build -j$(nproc) -- install
44+
sudo ldconfig
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Setup Rust Environment"
2+
description: "Install necessary dependencies and set up Rust stable"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- uses: actions/cache@v4
7+
with:
8+
path: |
9+
~/.cargo/bin/
10+
~/.cargo/registry/index/
11+
~/.cargo/registry/cache/
12+
~/.cargo/git/db/
13+
rust/target/
14+
key: amd64-cargo
15+
- run: sudo apt update || true
16+
shell: bash
17+
- run: sudo apt-get install -y libpcap-dev libclang-dev libsnmp-dev patchelf
18+
shell: bash
19+
- run: rustup update stable && rustup default stable || rustup default stable
20+
shell: bash
21+
- run: rustup component add rustfmt
22+
shell: bash
23+
- run: rustup component add clippy
24+
shell: bash

.github/workflows/unit-tests.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Build and run unit tests"
2+
3+
on: push
4+
5+
jobs:
6+
build-and-run-unit-tests:
7+
runs-on: 'ubuntu-latest'
8+
steps:
9+
- name: Check out repository
10+
uses: actions/checkout@v6
11+
- name: Setup Rust
12+
uses: ./.github/actions/setup-rust
13+
- name: Build and run Rust unit tests
14+
run: cargo test --lib --tests --workspace
15+
- name: Install cgreen
16+
uses: ./.github/actions/install-cgreen-with-sudo
17+
- name: Prepare C build dir
18+
run: |
19+
mkdir build &&
20+
cd build &&
21+
cmake ..
22+
- name: Build and run C unit test
23+
run: |
24+
cd build &&
25+
make tests &&
26+
make test

0 commit comments

Comments
 (0)