From 3296ddd65886117d721f223f1be7c29d0c7d7382 Mon Sep 17 00:00:00 2001 From: Lam Chau Date: Fri, 18 Oct 2024 13:53:49 -0700 Subject: [PATCH] chore: add justfile to format recipe (#163) --- justfile | 119 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 48 deletions(-) diff --git a/justfile b/justfile index 96f51d6b..65b8e424 100644 --- a/justfile +++ b/justfile @@ -1,79 +1,102 @@ +# list all tasks default: - @just --list --unsorted + @just --list --unsorted +# run tests test *FLAGS: - uv run pytest tests -m "not integration" {{FLAGS}} + uv run pytest tests -m "not integration" {{ FLAGS }} +# run integration tests integration *FLAGS: - uv run pytest tests -m integration {{FLAGS}} + uv run pytest tests -m integration {{ FLAGS }} +# format code format: - #!/usr/bin/env bash - UVX_PATH="$(which uvx)" + #!/usr/bin/env bash + UVX_PATH="$(which uvx)" - if [ -z "$UVX_PATH" ]; then - echo "[error]: unable to find uvx" - exit 1 - fi - eval "$UVX_PATH ruff format ." - eval "$UVX_PATH ruff check . --fix" + if [ -z "$UVX_PATH" ]; then + echo "[error]: unable to find uvx" + exit 1 + fi + eval "$UVX_PATH ruff format ." + eval "$UVX_PATH ruff check . --fix" + just --unstable --fmt +# run tests with coverage coverage *FLAGS: - uv run coverage run -m pytest tests -m "not integration" {{FLAGS}} - uv run coverage report - uv run coverage lcov -o lcov.info + uv run coverage run -m pytest tests -m "not integration" {{ FLAGS }} + uv run coverage report + uv run coverage lcov -o lcov.info +# build docs docs: - uv sync && uv run mkdocs serve + uv sync && uv run mkdocs serve +# install pre-commit hooks install-hooks: - #!/usr/bin/env bash - HOOKS_DIR="$(git rev-parse --git-path hooks)" + #!/usr/bin/env bash + HOOKS_DIR="$(git rev-parse --git-path hooks)" - if [ ! -d "$HOOKS_DIR" ]; then - mkdir -p "$HOOKS_DIR" - fi + if [ ! -d "$HOOKS_DIR" ]; then + mkdir -p "$HOOKS_DIR" + fi - cat > "$HOOKS_DIR/pre-commit" < "$HOOKS_DIR/pre-commit" <=.*/ai-exchange>='"${ai_exchange_version}"'\",/' pyproject.toml - git checkout -b release-version-{{version}} - git add pyproject.toml - git commit -m "chore(release): release version {{version}}" + #!/usr/bin/env bash + if [[ ! "{{ version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then + echo "[error]: invalid version '{{ version }}'." + echo " expected: semver format major.minor.patch or major.minor.patch-" + exit 1 + fi + uvx --from=toml-cli toml set --toml-path=pyproject.toml "project.version" {{ version }} + git checkout -b "release-{{ version }}" + git add pyproject.toml + git commit --message "chore(release): release version {{ version }}" -tag_version: - grep 'version' pyproject.toml | cut -d '"' -f 2 +# extract tag from pyproject.toml +get-tag-version: + #!/usr/bin/env bash + uvx --from=toml-cli toml get --toml-path=pyproject.toml "project.version" +# create tag from pyproject.toml tag: - git tag v$(just tag_version) + #!/usr/bin/env bash + git tag v$(just get-tag-version) -# this will kick of ci for release -# use this when release branch is merged to main -tag-push: - just tag - git push origin tag v$(just tag_version) +# create tag and push to origin (use this when release branch is merged to main) +tag-push: tag + #!/usr/bin/env bash + # this will kick of ci for release + git push origin tag v$(just get-tag-version) -# get commit messages for a release +# create release notes latest tag..HEAD release-notes: - git log --pretty=format:"- %s" v$(just tag_version)..HEAD + #!/usr/bin/env bash + git log --pretty=format:"- %s" v$(just get-tag-version)..HEAD +# setup langfuse server langfuse-server: - ./scripts/setup_langfuse.sh + #!/usr/bin/env bash + ./scripts/setup_langfuse.sh