[private]
default:
    just --list --unsorted

clean:
    rm -f library.lua
    rm -rf .lomu/ playlists/ songs/
    cargo clean

[private]
tag:
    #!/usr/bin/env julia
    using TOML

    cargo = TOML.parsefile("Cargo.toml")
    version = cargo["package"]["version"]

    if version == readchomp(`git describe --tags --abbrev=0`)
        error("tag $version already exists")
    end

    cmd = `git tag -s $version -m $version`
    @info(cmd)
    run(cmd)

    cmd = `git push origin $version`
    @info(cmd)
    run(cmd)

fmt:
    cargo fmt

test: fmt
    cargo test

run *args: fmt
    cargo run -- {{args}}

build: fmt
    cargo build --release

[private]
upload: upload-on-codeberg upload-on-crates-io

[private]
upload-on-codeberg:
    #!/usr/bin/env julia
    using TOML

    cargo = TOML.parsefile("Cargo.toml")
    version = cargo["package"]["version"]
    title = "v$version"

    if !isfile("CHANGELOG-$title.md")
        error("Missing file CHANGELOG-$title.md")
    end

    note = ""
    open("CHANGELOG-$title.md", "r") do f
        note = read(f, String)
    end

    cmd = `tea releases create --title $title --note $note $version`
    @info(cmd)
    run(cmd)

[private]
upload-on-crates-io:
    #!/usr/bin/env julia

    cmd = `cargo publish --allow-dirty`
    @info(cmd)
    run(cmd)

publish: clean fmt test tag build upload
