-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |