VERSION := "1.0.0"
PATCH := "1"

set dotenv-load := true

#
# Installing, updating and upgrading dependencies
#

_venv:
  if [ ! -d venv ]; then python3 -m venv venv; . ./venv/bin/activate && pip install pip wheel; fi

_clean-venv:
  rm -rf venv

# Install all dependencies
install:
  @just _venv
  . ./venv/bin/activate && pip install -r requirements_dev.txt

#
# Development
#

# Format Python with black
format:
  . ./venv/bin/activate &&  black ./bin/kbconfig

# Lint with flake8 and shellcheck
lint:
  . ./venv/bin/activate && flake8 './bin/kbconfig'
  shellcheck ./bin/*

# Open a shell with bins in the PATH
shell:
  . ./venv/bin/activate && PATH="$(pwd)/bin:${PATH}" bash --login

#
# Publishing
#

check_tap:
  if [ ! -d "${HOMEBREW_TAP}" ]; then echo "A HOMEBREW_TAP is required to publish."; exit 1; fi

tag:
  tito tag --use-version '{{VERSION}}'

bundle:
  tar -czf korbenware-{{VERSION}}.tar.gz bin COPYING NOTICE README.md

push:
  git push origin --follow-tags

gh-release:
  bash ./scripts/release.sh '{{VERSION}}' '{{PATCH}}'

apply-copr:
  coprctl apply -f ./package.yml

build-copr:
  copr build-package jfhbrook/joshiverse --name 'korbenware'

apply-homebrew:
  bash ./scripts/apply-homebrew.sh '{{VERSION}}' '{{PATCH}}'

# Publish the release on GitHub, Homebrew, and Copr
publish: check_tap tag push bundle gh-release apply-homebrew apply-copr build-copr
