Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
aon committed Aug 22, 2023
1 parent eb49f17 commit 7c5971b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/general-rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: General Rust

on:
push:
branches:
- "main"
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Update Rust
run: rustup update

- name: Install Rust
run: rustup install 1.69 --profile minimal

- name: Install Rustfmt
run: rustup component add rustfmt

- name: Run cargo fmt
run: make fmt-rust-check
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fmt: fmt-rust
fmt-check: fmt-rust-check

fmt-rust:
@echo "Formatting Rust code..."
@./scripts/list-cargo-directories.sh | ./scripts/run-cargo-fmt.sh

fmt-rust-check:
@echo "Checking Rust code formatting..."
@./scripts/list-cargo-directories.sh | ./scripts/run-cargo-fmt.sh --check
9 changes: 9 additions & 0 deletions scripts/list-cargo-directories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Find all directories with a Cargo.toml file
directories=$(find . -name Cargo.toml -exec dirname {} \; | sort -u)

# Print out the list of directories
for directory in $directories; do
echo "$directory"
done
37 changes: 37 additions & 0 deletions scripts/run-cargo-fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Parse command line arguments
check=0
while [[ "$#" -gt 0 ]]; do
case $1 in
--check) check=1 ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

# Read the list of directories from stdin
directories=$(cat)

# Create a list of directories to push into if any fail
failed_directories=""

# Run cargo fmt on each directory
for directory in $directories; do
echo "Running cargo fmt on $directory"
if [[ $check -eq 1 ]]; then
(cd "$directory" && cargo +nightly fmt --check)
else
(cd "$directory" && cargo +nightly fmt)
fi

if [ $? -ne 0 ]; then
failed_directories="$failed_directories\n$directory"
fi
done

# If any directories failed, print them out and exit with an error
if [ -n "$failed_directories" ]; then
printf "\nThe following directories failed cargo fmt:$failed_directories\n"
exit 1
fi

0 comments on commit 7c5971b

Please sign in to comment.