mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-03 01:50:12 +00:00
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] ```
This commit is contained in:
parent
425be1e01b
commit
6771ecdde5
@ -28,6 +28,7 @@ this project:
|
|||||||
|
|
||||||
- the [Rust](https://www.rust-lang.org/tools/install) toolchain installed on your machine
|
- the [Rust](https://www.rust-lang.org/tools/install) toolchain installed on your machine
|
||||||
- any working version of [Git](https://git-scm.com/downloads)
|
- 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
|
### Forking the repository and setting up the project
|
||||||
|
|
||||||
@ -44,13 +45,18 @@ this project:
|
|||||||
```
|
```
|
||||||
4. Install the project dependencies by running the following command:
|
4. Install the project dependencies by running the following command:
|
||||||
```shell
|
```shell
|
||||||
make setup
|
just setup
|
||||||
```
|
```
|
||||||
5. Create a new branch for your feature or bug fix:
|
5. Create a new branch for your feature or bug fix:
|
||||||
```shell
|
```shell
|
||||||
git checkout -b <branch-name>
|
git checkout -b <branch-name>
|
||||||
```
|
```
|
||||||
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
|
```shell
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Your commit message"
|
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
|
8. If not done automatically, create a pull request by navigating to the original repository and clicking on the
|
||||||
`New pull request` button.
|
`New pull request` button.
|
||||||
|
|
||||||
### Building the project
|
### Developing locally
|
||||||
|
|
||||||
Before anything else:
|
Before anything else (if not done already):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
make setup
|
just setup
|
||||||
```
|
```
|
||||||
|
|
||||||
To run the application in debug mode while developing, with the ability to see logs and debug information:
|
To run the application in debug mode while developing, with the ability to see logs and debug information:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
make run
|
just run
|
||||||
```
|
```
|
||||||
|
|
||||||
**Accessing the Logs:**
|
**Accessing the Logs:**
|
||||||
@ -86,40 +92,24 @@ configuration:
|
|||||||
| macOS | `$XDG_DATA_HOME/television/television.log` or `$HOME/Library/Application\ Support/television/television.log` |
|
| macOS | `$XDG_DATA_HOME/television/television.log` or `$HOME/Library/Application\ Support/television/television.log` |
|
||||||
| Windows | `{FOLDERID_LocalAppData}\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
|
```shell
|
||||||
make
|
just fix
|
||||||
```
|
```
|
||||||
|
|
||||||
or
|
To get a sense of the real thing and test how your patch would behave in production, run:
|
||||||
|
|
||||||
```shell
|
```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
|
```shell
|
||||||
make release
|
just test
|
||||||
```
|
|
||||||
|
|
||||||
Formatting the code
|
|
||||||
|
|
||||||
```shell
|
|
||||||
make format
|
|
||||||
```
|
|
||||||
|
|
||||||
Linting the code
|
|
||||||
|
|
||||||
```shell
|
|
||||||
make lint
|
|
||||||
```
|
|
||||||
|
|
||||||
Running the tests
|
|
||||||
|
|
||||||
```shell
|
|
||||||
make test
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Project structure
|
### Project structure
|
||||||
|
60
Makefile
60
Makefile
@ -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
|
|
117
justfile
Normal file
117
justfile
Normal file
@ -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"
|
||||||
|
|
@ -625,7 +625,7 @@ mod tests {
|
|||||||
fn test_replace_non_printable(input: &str, expected: &str) {
|
fn test_replace_non_printable(input: &str, expected: &str) {
|
||||||
let (actual, _offset) = replace_non_printable(
|
let (actual, _offset) = replace_non_printable(
|
||||||
input.as_bytes(),
|
input.as_bytes(),
|
||||||
&ReplaceNonPrintableConfig::default().tab_width(2),
|
ReplaceNonPrintableConfig::default().tab_width(2),
|
||||||
);
|
);
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
@ -641,7 +641,7 @@ mod tests {
|
|||||||
test_replace_non_printable(
|
test_replace_non_printable(
|
||||||
" -- AND
|
" -- AND
|
||||||
", " -- AND",
|
", " -- AND",
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -686,7 +686,7 @@ mod tests {
|
|||||||
let input = b"Hello,\nWorld!";
|
let input = b"Hello,\nWorld!";
|
||||||
let (output, offsets) = replace_non_printable(
|
let (output, offsets) = replace_non_printable(
|
||||||
input,
|
input,
|
||||||
&ReplaceNonPrintableConfig::default().tab_width(2),
|
ReplaceNonPrintableConfig::default().tab_width(2),
|
||||||
);
|
);
|
||||||
assert_eq!(output, "Hello,World!");
|
assert_eq!(output, "Hello,World!");
|
||||||
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1]);
|
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 input = b"Hello,\x00World!";
|
||||||
let (output, offsets) = replace_non_printable(
|
let (output, offsets) = replace_non_printable(
|
||||||
input,
|
input,
|
||||||
&ReplaceNonPrintableConfig::default().tab_width(2),
|
ReplaceNonPrintableConfig::default().tab_width(2),
|
||||||
);
|
);
|
||||||
assert_eq!(output, "Hello,␀World!");
|
assert_eq!(output, "Hello,␀World!");
|
||||||
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
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 input = b"Hello,\x7FWorld!";
|
||||||
let (output, offsets) = replace_non_printable(
|
let (output, offsets) = replace_non_printable(
|
||||||
input,
|
input,
|
||||||
&ReplaceNonPrintableConfig::default().tab_width(2),
|
ReplaceNonPrintableConfig::default().tab_width(2),
|
||||||
);
|
);
|
||||||
assert_eq!(output, "Hello,␀World!");
|
assert_eq!(output, "Hello,␀World!");
|
||||||
assert_eq!(offsets, vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
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!", 1.0);
|
||||||
test_proportion_of_printable_ascii_characters(
|
test_proportion_of_printable_ascii_characters(
|
||||||
"Hello, World!\x00",
|
"Hello, World!\x00",
|
||||||
0.9285714,
|
0.928_571_4,
|
||||||
);
|
);
|
||||||
test_proportion_of_printable_ascii_characters(
|
test_proportion_of_printable_ascii_characters(
|
||||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
|
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user