diff --git a/.github/workflows/ci-checks.yml b/.github/workflows/ci-checks.yml index a066e0c..9cc76b0 100644 --- a/.github/workflows/ci-checks.yml +++ b/.github/workflows/ci-checks.yml @@ -16,9 +16,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Install mise + uses: jdx/mise-action@v2 - name: Build CLI - run: | - make build + run: mise run build - name: Run tests - run: | - make test + run: mise run test diff --git a/.mise/run-in-caller-dir b/.mise/run-in-caller-dir new file mode 100755 index 0000000..0b42463 --- /dev/null +++ b/.mise/run-in-caller-dir @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +program="$1" +shift +if [[ "$program" != /* ]]; then + program="$(cd -- "$(dirname -- "$program")" && pwd)/$(basename -- "$program")" +fi +caller="${NV_DEV_CWD:-${MISE_ORIGINAL_CWD:-$PWD}}" +cd "$caller" +unset NV_DEV_CWD +exec "$program" "$@" diff --git a/.mise/tasks/run b/.mise/tasks/run new file mode 100755 index 0000000..3b9ab0b --- /dev/null +++ b/.mise/tasks/run @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +#MISE description="Run nv from source in the caller's directory" +#MISE raw=true +set -euo pipefail + +export NV_DEV_CWD="${NV_DEV_CWD:-${MISE_ORIGINAL_CWD:-$PWD}}" +root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd)" +cd "$root" +exec go run -exec "$root/.mise/run-in-caller-dir" . "$@" diff --git a/README.md b/README.md index 239ea0e..6538719 100644 --- a/README.md +++ b/README.md @@ -112,3 +112,7 @@ There are a couple ways to change your resolver behavior by environment. 2. If more control is needed than above, create a separate resolver entry for the different resolver versions and target the environment-appropriate resolver in the relevant `.env` files. When/if configuration for resolvers becomes more complex, additional ways to manage environment overrides will likely be introduced. + +## Development (mise) + +Run `mise run setup` to install Go and watchexec, download modules, and build `dist/nv`. `mise run build` rebuilds the artifact; `mise dev` builds and watches Go sources for changes. `mise run test` builds and runs the test suite. Activate the mise environment with `eval "$(mise env -s bash)"` to put `dist/` on `PATH`, so `nv` invokes the built artifact. `mise run run -- ` runs the CLI from source in your current directory, and `mise run install` installs the artifact under `${NV_INSTALL_DIR:-$HOME/.local/bin}`. `mise run release` builds binaries for all platforms. diff --git a/bin/release.sh b/bin/release.sh index ff94fd4..8e541af 100755 --- a/bin/release.sh +++ b/bin/release.sh @@ -1,4 +1,4 @@ -#! bash +#!/usr/bin/env bash OS_TARGETS=( darwin linux ) ARCH_TARGETS=( amd64 arm64 ) diff --git a/makefile b/makefile deleted file mode 100644 index d731102..0000000 --- a/makefile +++ /dev/null @@ -1,17 +0,0 @@ -.PHONY: test - -build: - go build -o dist/nv main.go - -run: - go run main.go - -test: build - go test -v ./... - -uninstall: - rm /usr/local/bin/nv - -release: - rm -rf ./dist - sh ./bin/release.sh diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..6d499a3 --- /dev/null +++ b/mise.toml @@ -0,0 +1,44 @@ +[tools] +go = "1.27" +watchexec = "latest" + +[env] +_.path = ["{{config_root}}/dist"] + +[tasks.setup] +description = "Install project tools and download Go modules" +run = ["mise install", "go mod download", "mise run build"] + +[tasks.build] +description = "Build the nv CLI" +sources = ["*.go", "cmd/**/*.go", "internal/**/*.go", "go.mod", "go.sum"] +outputs = ["dist/nv"] +run = "mkdir -p dist && go build -o dist/nv main.go" + +[tasks.dev] +description = "Build the CLI and watch source files for changes" +run = "mise watch build" + +[tasks.test] +description = "Build the CLI and run all tests" +depends = ["build"] +run = "go test ./..." + +[tasks.install] +description = "Build and install nv globally" +depends = ["build"] +run = ''' +set -eu +install_dir="${NV_INSTALL_DIR:-$HOME/.local/bin}" +mkdir -p "$install_dir" +cp dist/nv "$install_dir/nv" +printf 'Installed nv to %s\n' "$install_dir/nv" +case ":$PATH:" in + *":$install_dir:"*) ;; + *) printf 'Warning: %s is not on PATH\n' "$install_dir" >&2 ;; +esac +''' + +[tasks.release] +description = "Build release binaries for all platforms into dist/" +run = "rm -rf dist && bash bin/release.sh"