[env]
LAST_FM_USER = 'change-me'
LAST_FM_API_KEY = 'change-me'
OPENAI_KEY = 'change-me'
FLUXON_KEY_FINGERPRINT = 'change-me'
FLUXON_LICENSE_KEY = 'change-me'
DBUI_URL = 'sqlite:data/music_library_dev.db'

[tools]
hurl = 'latest'
sqlite = 'latest'
gh = 'latest'

# BUILDING BLOCKS

# NPM DEPS

[tasks.npm-install]
run = 'npm install --prefix assets'
hide = true

[tasks.npm-update]
run = 'npm update --prefix assets'
hide = true

[tasks.npm-outdated]
run = 'npm outdated --prefix assets'
hide = true

# TAILWIND DEP

[tasks.tailwind-update]
description = 'Update the Tailwind version configured in the project'
run = 'mix tailwind.update_version'
hide = true

[tasks.tailwind-outdated]
description = 'Checks that the Tailwind version is up to date'
run = 'mix tailwind.check_version'
hide = true

# ESBUILD DEP

[tasks.esbuild-update]
description = 'Update the esbuild version configured in the project'
run = 'mix esbuild.update_version'
hide = true

[tasks.esbuild-outdated]
description = 'Checks that the esbuild version is up to date'
run = 'mix esbuild.check_version'
hide = true

# MIX DEPS

[tasks.mix-update]
description = 'Update mix dependencies'
run = ['mix deps.update --all']
hide = true

[tasks.mix-outdated]
description = 'Show outdated mix dependencies'
run = ['mix hex.outdated --all']
hide = true

# SQLEAN EXTENSIONS

[tasks.sqlean-update]
description = 'Update the sqlite3 extensions configured in the project'
run = ['mix sqlean.update_version']
hide = true

[tasks.sqlean-outdated]
description = 'Checks the sqlite extensions version is up to date'
run = ['mix sqlean.check_version']
hide = true

# TOOLING

[tasks.gh-markdown-preview-extension-install]
description = 'Install a gh extension to preview GH-flavoured markdown files locally'
run = ['gh extension install thiagokokada/gh-gfm-preview']
hide = true

[tasks.gh-markdown-preview-extension-update]
description = 'Update the gh extension to preview GH-flavoured markdown files locally'
run = ['gh extension upgrade gfm-preview']
hide = true

# PUBLIC TASKS

# DEPENDENCIES

[tasks."deps:outdated"]
depends = [
  'npm-outdated',
  'tailwind-outdated',
  'esbuild-outdated',
  'sqlean-outdated',
  'mix-outdated',
]
description = 'Show outdated dependencies'

[tasks."deps:update"]
depends = [
  'npm-update',
  'tailwind-update',
  'esbuild-update',
  'sqlean-update',
  'mix-update',
  'gh-markdown-preview-extension-update',
]
description = 'Update dependencies'

# SETUP

[tasks.fluxon-add-repo]
description = "Add the fluxon repo"
run = """
mix hex.repo add fluxon https://repo.fluxonui.com \
  --fetch-public-key $FLUXON_KEY_FINGERPRINT \
  --auth-key $FLUXON_LICENSE_KEY
"""
hide = true

[tasks."dev:setup"]
depends = [
  'npm-install',
  'fluxon-add-repo',
  'gh-markdown-preview-extension-install',
]
description = 'Install dependencies and setup the database'
run = ['mix setup']

# CI

[tasks."ci:watch"]
description = "Monitor CI status"
run = "gh run watch"

# PRODUCTION

[tasks."prod:console"]
description = 'Open an ssh console to the production env'
run = 'ssh music-library-prod'

[tasks."prod:backup"]
description = 'Backup the production database to the local development env'
run = 'scripts/prod-backup.sh'

[tasks."prod:prune-backups"]
confirm = 'Are you sure you want to delete all downloaded database backups?'
description = 'Deletes all downloaded database backups'
run = 'rm data/music_library_prod*'

[tasks."prod:test"]
description = 'Run HTTP tests against production'
run = 'hurl --test test/prod.hurl'

[tasks."prod:deploy"]
description = 'Deploy on production and monitor'
run = """
hurl --test --progress-bar scripts/deploy.hurl
"""

# GIT TOOLING

[tasks.static-checks-hook]
description = '''
Pre-commit task to ensure code conforms to static checks policies.

Install with `mise generate git-pre-commit --write --task=static-checks-hook`
'''
run = 'mix do format --check-formatted, credo --strict, gettext.extract --check-up-to-date'
hide = true

# DEVELOPMENT/TEST

[tasks."dev:static-checks"]
description = 'Run static checks for code formatting, translations, quality'
run = 'mix do format, credo, gettext.extract --merge'

[tasks.test]
description = 'Run project tests'
run = 'mix test'

[tasks."dev:console"]
description = 'Run the application attached to an IEx console'
run = 'iex -S mix phx.server'

[tasks."dev:readme-preview"]
description = 'Preview the README file via a GH flavoured markdown rendered'
run = 'gh gfm-preview README.md'

[tasks."dev:fix-translations-conflict"]
run = [
  'git co --theirs  priv/gettext/default.pot',
  'git co --theirs  priv/gettext/en/LC_MESSAGES/default.po',
  'mix gettext.extract --merge',
]

# DOCKER

[tasks."docker:build"]
description = 'Builds and tags the application Docker image'
run = 'docker compose build'

[tasks."docker:push"]
description = 'Push the image to the registry'
run = 'docker compose push'
