From 6771ecdde57040f1eb996d9ee4c9c931a18a2c25 Mon Sep 17 00:00:00 2001 From: Alexandre Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Sat, 12 Apr 2025 20:36:29 +0000 Subject: [PATCH] chore(project): migrate from Makefile to Just (#463) ``` Available recipes: br # Build the project in release mode build profile='dev' # Build the project with the specified profile (dev by default) [alias: b] check # Check the project for errors and warnings [alias: c] clean # Clean up cargo build artifacts default # List all available commands fix # Fix linting and formatting errors [alias: f] format # Format the code using cargo fmt lint # Lint the code using cargo clippy release kind='patch' # Publish a new release (major, minor, or patch) [alias: rl] run # Run the program in debug mode with logs enabled [alias: r] setup # Setup the project environment for local development test # Run the tests for the project [alias: t] update-changelog # Update the project's changelog update-man # Update the project's manpages [alias: m] ``` --- CONTRIBUTING.md | 52 +++++++--------- Makefile | 60 ------------------ justfile | 117 ++++++++++++++++++++++++++++++++++++ television/utils/strings.rs | 12 ++-- 4 files changed, 144 insertions(+), 97 deletions(-) delete mode 100644 Makefile create mode 100644 justfile diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b75bbb..a57ed45 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,6 +28,7 @@ this project: - the [Rust](https://www.rust-lang.org/tools/install) toolchain installed on your machine - any working version of [Git](https://git-scm.com/downloads) +- the [just](https://github.com/casey/just) command runner ### Forking the repository and setting up the project @@ -44,13 +45,18 @@ this project: ``` 4. Install the project dependencies by running the following command: ```shell - make setup + just setup ``` 5. Create a new branch for your feature or bug fix: ```shell git checkout -b ``` -6. Make your changes and commit them to your branch: +6. Make your changes and test them locally. Predefined commands are available to make your life simpler, using them + spares some time and effort: + ```shell + just --list + ``` +7. Once you're all set, commit them to your branch: ```shell git add . git commit -m "Your commit message" @@ -62,18 +68,18 @@ this project: 8. If not done automatically, create a pull request by navigating to the original repository and clicking on the `New pull request` button. -### Building the project +### Developing locally -Before anything else: +Before anything else (if not done already): ```shell -make setup +just setup ``` To run the application in debug mode while developing, with the ability to see logs and debug information: ```shell -make run +just run ``` **Accessing the Logs:** @@ -86,40 +92,24 @@ configuration: | macOS | `$XDG_DATA_HOME/television/television.log` or `$HOME/Library/Application\ Support/television/television.log` | | Windows | `{FOLDERID_LocalAppData}\television\television.log` | -To build the project in debug mode, run the following command in the project directory: +To check for linting and formatting issues (and fix them automatically), run: ```shell -make +just fix ``` -or +To get a sense of the real thing and test how your patch would behave in production, run: ```shell -make build +just b release + +# or `just br` +# or `just build release` ``` -To build the project in release mode, run the following command in the project directory: - +Running the tests can be done with: ```shell -make release -``` - -Formatting the code - -```shell -make format -``` - -Linting the code - -```shell -make lint -``` - -Running the tests - -```shell -make test +just test ``` ### Project structure diff --git a/Makefile b/Makefile deleted file mode 100644 index cd064f8..0000000 --- a/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -default: build - -setup: - @echo "Setting up $(NAME)" - @echo "Installing git hooks" - @mkdir -p .git/hooks - @echo "make fix" > .git/hooks/pre-commit - @chmod +x .git/hooks/pre-commit - @echo "Done" - -clean: - @echo "Cleaning build dir" - @rm -rf target/* - @echo "Cleaning using cargo" - @cargo clean - -check: - @echo "Checking $(NAME)" - @cargo check - -release: - @echo "Building release: $(VERSION)" - @cargo build --release - -build: - @echo "Building debug" - @cargo build - -format: - @echo "Formatting $(NAME)" - @cargo fmt --all - -lint: - @echo "Linting $(NAME)" - @cargo clippy - -fix: format - @echo "Fixing $(NAME)" - @cargo fix --allow-staged --allow-dirty - @make lint - -run: - @echo "Running debug" - @RUST_LOG=debug cargo run - -test: - @echo "Testing $(NAME)" - @cargo test --all - -bump-workspace: - @echo "Bumping workspace" - @./scripts/bump.sh - -publish: - @echo "Publishing $(NAME)" - @./scripts/publish.sh - -update-changelog: - @echo "Updating changelog" - @git cliff -o CHANGELOG.md diff --git a/justfile b/justfile new file mode 100644 index 0000000..b4b86cf --- /dev/null +++ b/justfile @@ -0,0 +1,117 @@ +NAME := 'television' + +# List all available commands +default: + just --list + +alias r := run + +# Run the program in debug mode with logs enabled +@run: + echo "Running {{ NAME }}..." + RUST_LOG=debug cargo run + echo "Done" + +# Setup the project environment for local development +@setup: + echo "Setting up {{ NAME }}..." + echo "Installing git hooks..." + mkdir -p .git/hooks + echo "just fix" > .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + echo "Installing dependencies..." + cargo build + echo "Done" + +# Clean up cargo build artifacts +@clean: + echo "Cleaning up {{ NAME }}..." + echo "Removing git hooks..." + rm -f .git/hooks/pre-commit + echo "Done" + +alias c := check + +# Check the project for errors and warnings +@check: + echo "Checking {{ NAME }}..." + cargo check + echo "Done" + +# Format the code using cargo fmt +@format: + echo "Formatting {{ NAME }}..." + cargo fmt --all + echo "Done" + +# Lint the code using cargo clippy +@lint: + echo "Linting {{ NAME }}..." + cargo clippy --all-targets --all-features -- -D warnings + echo "Done" + +alias f := fix +# Fix linting and formatting errors +@fix: + echo "Fixing {{ NAME }}..." + cargo fix --allow-dirty --allow-staged + just format + just lint + +alias t := test +# Run the tests for the project +@test: + echo "Running {{ NAME }}'s test suite..." + cargo test --all + echo "Done" + +alias b := build +# Build the project with the specified profile (dev by default) +@build profile='dev': + echo "Building {{ NAME }} for profile: {{ profile }}..." + cargo build --profile {{ profile }} + echo "Done" + +# Build the project in release mode +br: (build 'release') + +# Update the project's changelog +@update-changelog: + echo "Updating changelog..." + git cliff -o CHANGELOG.md + echo "Done" + +alias m := update-man +# Update the project's manpages +update-man: build + #!/usr/bin/env sh + echo "Checking for manpages updates..." + if ! diff ./man/tv.1 ./target/assets/tv.1 > /dev/null; + then cp ./target/assets/tv.1 ./man/tv.1 && echo "Updated manpages" + else echo "No changes to manpages" + fi + +alias rl := release +# Publish a new release (major, minor, or patch) +release kind='patch': + #!/usr/bin/env sh + echo "Releasing {{ NAME }} (kind: {{ kind }})..." + # bump version (major, minor, patch) + version=$(grep -E '^\s*version\s*=' Cargo.toml | cut -d '"' -f 2) + kind="{{ kind }}" + echo "Current version is: $version" + if [ "$kind" = "major" ]; then + new_version=$(echo $version | awk -F. -v OFS=. '{$1++; $2=0; $3=0} 1') + elif [ "$kind" = "minor" ]; then + new_version=$(echo $version | awk -F. -v OFS=. '{$2++; $3=0} 1') + elif [ "$kind" = "patch" ]; then + new_version=$(echo $version | awk -F. -v OFS=. '{$3++} 1') + else + echo "Invalid kind: $kind" + exit 1 + fi + echo "New version is: $new_version" + sed -i "s/version = \"$version\"/version = \"$new_version\"/" Cargo.toml + git add Cargo.toml + echo "Done" + diff --git a/television/utils/strings.rs b/television/utils/strings.rs index d0ad531..59b1fee 100644 --- a/television/utils/strings.rs +++ b/television/utils/strings.rs @@ -625,7 +625,7 @@ mod tests { fn test_replace_non_printable(input: &str, expected: &str) { let (actual, _offset) = replace_non_printable( input.as_bytes(), - &ReplaceNonPrintableConfig::default().tab_width(2), + ReplaceNonPrintableConfig::default().tab_width(2), ); assert_eq!(actual, expected); } @@ -641,7 +641,7 @@ mod tests { test_replace_non_printable( " -- AND ", " -- AND", - ) + ); } #[test] @@ -686,7 +686,7 @@ mod tests { let input = b"Hello,\nWorld!"; let (output, offsets) = replace_non_printable( input, - &ReplaceNonPrintableConfig::default().tab_width(2), + ReplaceNonPrintableConfig::default().tab_width(2), ); assert_eq!(output, "Hello,World!"); assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1]); @@ -756,7 +756,7 @@ mod tests { let input = b"Hello,\x00World!"; let (output, offsets) = replace_non_printable( input, - &ReplaceNonPrintableConfig::default().tab_width(2), + ReplaceNonPrintableConfig::default().tab_width(2), ); assert_eq!(output, "Hello,␀World!"); assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); @@ -764,7 +764,7 @@ mod tests { let input = b"Hello,\x7FWorld!"; let (output, offsets) = replace_non_printable( input, - &ReplaceNonPrintableConfig::default().tab_width(2), + ReplaceNonPrintableConfig::default().tab_width(2), ); assert_eq!(output, "Hello,␀World!"); assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); @@ -784,7 +784,7 @@ mod tests { test_proportion_of_printable_ascii_characters("Hello, World!", 1.0); test_proportion_of_printable_ascii_characters( "Hello, World!\x00", - 0.9285714, + 0.928_571_4, ); test_proportion_of_printable_ascii_characters( "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",