Skip to content

feat: initial CI

feat: initial CI #6

Workflow file for this run

name: CI
on:
pull_request:
push:
branches:
- main
concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build_and_test_nix:
name: Build and test
timeout-minutes: 30
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
name: [ubuntu-latest, macOS-arm-latest]
rust: [stable]
include:
- name: ubuntu-latest
os: ubuntu-latest
release-os: linux
release-arch: amd64
runner: [self-hosted, linux, X64]
- name: macOS-arm-latest
os: macOS-latest
release-os: darwin
release-arch: aarch64
runner: [self-hosted, macOS, ARM64]
steps:
- name: checkout
uses: actions/checkout@v4
- name: Install ${{ matrix.rust }} rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: run tests
run: |
cargo nextest run --all-features --lib --bins --tests --no-fail-fast
env:
RUST_LOG: "TRACE"
- name: build
run: |
cargo build --release
cargo run --features headers --bin generate_headers --release
- name: build test binary
run: |
cc -o main{,.c} -L target/release -l iroh_net_ffi -lc -lm
env:
LD_LIBRARY_PATH: target/release
- name: test run
run: |
./main server --json > server_output.json &
# Wait for the server to start
sleep 2
# Read the second line of the file
line=$(sed -n '2p' server_output.json)
# Check if the line is empty
if [[ -z "$line" ]]; then
echo "Error: server_output.json does not have at least 2 lines"
exit 1
fi
# Parse the JSON
json_output=$(echo $line | jq .)
# Store variables
node_id=$(echo $json_output | jq -r '.node_id')
derp=$(echo $json_output | jq -r '.derp')
addrs=$(echo $json_output | jq -r '.addrs[]')
./main client $node_id $derp ${addrs[@]}
sleep 1
# Read the last line of the file
last_line=$(tail -n 1 server_output.json)
# Parse the JSON
json_output=$(echo $last_line | jq -r '.data')
# Ensure json_output is as expected
if [[ "$json_output" != "hello world from C" ]]; then
echo "Error: Unexpected output"
exit 1
fi
echo "Success"
- name: check headers
run: |
cp irohnet.h irohnet.h.orig
./target/release/generate_headers
diff_output=$(diff irohnet.h irohnet.h.orig)
# Check if the diff_output is not empty
if [[ -n "$diff_output" ]]; then
echo "Error: Differences were found compared to the checked in headers"
echo "$diff_output"
exit 1
fi
env:
CARGO_CRATE_NAME: iroh-net-ffi
cargo_deny:
timeout-minutes: 30
name: cargo deny
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
arguments: --all-features
command: check
command-arguments: "-Dwarnings"
check_fmt_and_docs:
timeout-minutes: 30
name: Checking fmt and docs
runs-on: ubuntu-latest
env:
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "on"
steps:
- uses: actions/checkout@master
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Install sccache
uses: mozilla-actions/[email protected]
- name: fmt
run: cargo fmt --all -- --check
- name: Docs
run: cargo doc --workspace --all-features --no-deps --document-private-items
clippy_check:
timeout-minutes: 30
runs-on: ubuntu-latest
env:
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "on"
steps:
- uses: actions/checkout@master
# Can be switched back to stable once 1.75 lands
# https://github.com/rust-lang/cargo/issues/12115#issuecomment-1768170381
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2023-12-06
components: clippy
- name: Install sccache
uses: mozilla-actions/[email protected]
# TODO: We have a bunch of platform-dependent code so should
# probably run this job on the full platform matrix
- name: clippy check (all features)
run: cargo clippy --workspace --all-features --all-targets --bins --tests --benches
- name: clippy check (no features)
run: cargo clippy --workspace --no-default-features --lib --bins --tests
- name: clippy check (default features)
run: cargo clippy --workspace --all-targets