From 41c29df84521052d92ebdde7a4ec103af7204281 Mon Sep 17 00:00:00 2001 From: azzamsa Date: Wed, 31 Jul 2024 08:16:54 +0700 Subject: [PATCH] build: adopt `just` new features It simplifies my recipes. --- justfile | 79 +++++++++++++++++++------------------------------------- 1 file changed, 27 insertions(+), 52 deletions(-) diff --git a/justfile b/justfile index a1b8dfb..f50e868 100755 --- a/justfile +++ b/justfile @@ -10,103 +10,106 @@ alias t := test alias c := comply alias k := check -# List available commands. +[doc('List available commands')] _default: just --list --unsorted -# Setup the repository. -setup: _areyousure +[confirm('⚠️ This command will alter your system. Run recipe `setup`?')] +[doc('Setup the repository')] +setup: just _cargo-install 'cargo-edit cargo-nextest cargo-outdated dprint git-cliff bacon typos-cli' just _cargo-install 'sqlx-cli' -# Tasks to make the code-base comply with the rules. Mostly used in git hooks. +[doc('Tasks to make the code-base comply with the rules. Mostly used in git hooks')] comply: _doc-check _update-sqlx-schema fmt lint test -# Check if the repository comply with the rules and ready to be pushed. +[doc('Check if the repository comply with the rules and ready to be pushed')] check: _doc-check _check-sqlx-schema fmt-check lint test -# Develop the app. +[doc('Develop the app')] dev: bacon -# Run the app. +[doc('Run the app')] run: cargo run -# Build the container image. +[doc('Build the container image')] image-build: docker build . --tag tin:latest --build-arg VCS_REVISION=$(git rev-parse --short HEAD) -# Run the container. +[doc('Run the container')] image-start service="": docker compose --file compose.local.yml up {{ service }} -d -# Stop the container. +[doc('Stop the container')] image-stop: docker compose --file compose.local.yml down -# Restart the containers. +[doc('Restart the containers')] image-restart: just image-stop just image-run -# Format the codebase. +[doc('Format the codebase.')] fmt: cargo fmt --all dprint fmt -# Check is the codebase properly formatted. +[doc('Check is the codebase properly formatted')] fmt-check: cargo fmt --all -- --check dprint check -# Lint the codebase. +[doc('Lint the codebase')] lint: cargo clippy --all-targets --all-features typos --config configs/typos.toml -# Test the codebase. +[doc('Test the codebase')] test: cargo nextest run --config-file configs/nextest.toml -# Run the unit tests. +[doc('Run the unit tests')] test-unit: cargo nextest run --lib -# Create a new release. Example `cargo-release release minor --tag-name v0.2.0` +[doc('Create a new release. Example `cargo-release release minor --tag-name v0.2.0`')] release level: cargo-release release {{ level }} --execute -# Make sure the repo is ready for release +[doc('Make sure the repo is ready for release')] release-check level: check just up cargo-release release {{ level }} -# Setup the database schema. +[doc('Setup the database schema.')] db-migrate: sqlx database create # sqlx migrate run # auto migration enabled -# reset the database schema. +[doc('Reset the database schema')] db-reset: sqlx database drop && sqlx database create -# Check the documentation. +[doc('Check the documentation')] _doc-check: cargo doc --all-features --no-deps +[doc('Update the SQLx schema')] _update-sqlx-schema: cargo sqlx prepare -- --lib +[doc('Check the SQLx schema')] _check-sqlx-schema: cargo sqlx prepare --check -- --lib -# Release hooks +[doc('Prepare release hooks')] _release-prepare version: git-cliff --config configs/cliff.toml --output CHANGELOG.md --tag {{ version }} just fmt -# Check dependencies health. Pass `--write` to uppgrade dependencies. +[doc('Check dependencies health. Pass `--write` to upgrade dependencies')] [unix] up arg="": #!/usr/bin/env bash @@ -117,21 +120,11 @@ up arg="": cargo outdated --root-deps-only fi; -[windows] -up arg="": - #!powershell.exe - if ( "tool" -eq "--write") { - cargo upgrade - cargo update - } - else { - cargo outdated --root-deps-only - } - # # Helper # +[doc('Install using plain cargo or cargo-binstall')] [unix] _cargo-install tool: #!/usr/bin/env bash @@ -142,21 +135,3 @@ _cargo-install tool: echo "Building from source" cargo install --locked {{ tool }} fi - -[unix] -_areyousure: - #!/usr/bin/env bash - echo -e "This command will alter your system. ⚠️ - You are advised to run in inside containerized environment. - Such as [toolbx](https://containertoolbx.org/). - - If you are unsure. Run the installation commands manually. - Take a look at the 'setup' recipe in the Justfile.\n" - - read -p "Are you sure you want to proceed? (Y/n) " response; - if [[ $response =~ ^[Yy] ]]; then - echo "Continue!"; - else - echo "Cancelled!"; - exit 1; - fi