Skip to content

Commit 979b3f2

Browse files
committed
ci: add support for rust linting in the ci
Allows building of ci/Dockerfile and uses the image to do rust format and clippy as GitHub actions Signed-off-by: Alan Wandke <[email protected]>
1 parent def6661 commit 979b3f2

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

.dockerignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/rust-lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Rust Format and Clippy
3+
4+
on:
5+
push:
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
13+
container:
14+
image: ghcr.io/nationalsecurityagency/seabee:build
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Check formatting
21+
run: cargo fmt -- --check
22+
23+
- name: Run Clippy
24+
run: cargo clippy --all-targets --all-features --no-deps

ci/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ARG DOCKER_MIRROR
22

3-
FROM ${DOCKER_MIRROR}rust:1.79.0-slim
3+
FROM ${DOCKER_MIRROR}rust:slim
44

5-
COPY scripts/update_root_dependencies.sh /scripts/update_root_dependencies.sh
6-
COPY scripts/update_test_dependencies.sh /scripts/update_test_dependencies.sh
7-
COPY scripts/update_dependencies.sh /scripts/update_dependencies.sh
5+
LABEL org.opencontainers.image.source=https://github.com/NationalSecurityAgency/seabee
6+
7+
COPY scripts /scripts
88

99
RUN DOCKER=1 /scripts/update_dependencies.sh \
1010
&& rm -rf /var/lib/apt/lists/*

scripts/update_dependencies.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@ TOP_DIR=$(dirname "$(dirname "$(realpath "$0" || true)")")
55
ASCIINEMA_VERSION=2.4.0
66
POETRY_VERSION=1.8.3
77
PYTHON_VERSION=3.9
8-
RUST_VERSION=1.79.0
98

109
ASCIINEMA=asciinema
1110
export DOCKER="${DOCKER:-0}"
1211
POETRY=poetry
1312
PYTHON=python3
1413
RUSTUP="$HOME/.cargo/bin/rustup"
1514

15+
# Docker container doesn't have sudo
16+
SUDO="sudo"
17+
if [ "$DOCKER" -eq 1 ]; then
18+
SUDO=""
19+
fi
20+
1621
if [ "$EUID" -eq 0 ] && [ "$DOCKER" -eq 0 ]; then
1722
printf "Please don't run this script as root or sudo\n"
18-
exit
23+
exit 1
1924
fi
2025

2126
# https://unix.stackexchange.com/a/567537
@@ -45,11 +50,14 @@ python_check() {
4550
source "$HOME/.bashrc" && poetry install
4651
}
4752

53+
# install the latest stable verison of rust
4854
rust_check() {
4955
if ! command -V "$RUSTUP" &>/dev/null; then
5056
printf "Rustup not detected. Installing...\n"
51-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile default --default-toolchain $RUST_VERSION -y
57+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --profile default stable -y
5258
fi
59+
# Install rust lints
60+
rustup component add rustfmt clippy
5361
}
5462

5563
autocast_check() {
@@ -58,7 +66,7 @@ autocast_check() {
5866
fi
5967
}
6068

61-
sudo "$TOP_DIR"/scripts/update_root_dependencies.sh
69+
$SUDO "$TOP_DIR"/scripts/update_root_dependencies.sh
6270
python_check
6371
rust_check
6472
autocast_check

scripts/update_root_dependencies.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ version_greater_equal() {
2121
os_check() {
2222
ID=$(grep "^ID=" /etc/os-release | cut -d= -f2 | tr -d "\"")
2323
case $ID in
24-
ubuntu)
24+
ubuntu | debian)
2525
USE_APT=1
2626
;;
2727
fedora | rocky)
@@ -34,7 +34,7 @@ os_check() {
3434
install_system_packages() {
3535
printf "Installing tools and libraries needed for development\n"
3636
local common_deps
37-
common_deps=(clang pipx python3 python3-pip strace)
37+
common_deps=(clang make pipx python3 python3-pip strace)
3838
# depedencies necessary to build static libraries for libelf and zlib
3939
# which are dependencies of libbpf which is also built statically
4040
local library_deps library_deps_deb library_deps_dnf

0 commit comments

Comments
 (0)