diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a1999f..73040d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,89 +8,12 @@ on: workflow_dispatch: jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install mise - uses: jdx/mise-action@v2 - with: - version: latest - install: true - - - name: Install dependencies - run: | - mise install - sudo apt-get update - sudo apt-get install -y lua5.4 - - - name: Run linter - run: mise run lint - - test: - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - - name: Install mise - uses: jdx/mise-action@v2 - with: - version: latest - install: true - - - name: Install Lua (Ubuntu) - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y lua5.4 - - - name: Install Lua (macOS) - if: runner.os == 'macOS' - run: | - brew install lua - - - name: Run tests - run: | - mise install - mise run test - - integration-test: + ci: strategy: matrix: os: [ubuntu-latest, macos-latest] - semver-version: ['3.4.0', '3.3.0', '3.2.0'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - - name: Install mise - uses: jdx/mise-action@v2 - with: - version: latest - install: true - - - name: Test plugin installation - run: | - # Install the plugin from current directory - mise plugin install semver . - - # List available versions - mise ls-remote semver | head -20 - - # Install specific version - mise install semver@${{ matrix.semver-version }} - - # Test execution - mise exec semver@${{ matrix.semver-version }} -- semver --version - - # Test basic functionality - mise exec semver@${{ matrix.semver-version }} -- semver bump major 1.2.3 | grep -q "2.0.0" - mise exec semver@${{ matrix.semver-version }} -- semver bump minor 1.2.3 | grep -q "1.3.0" - mise exec semver@${{ matrix.semver-version }} -- semver bump patch 1.2.3 | grep -q "1.2.4" - - # Clean up - mise plugin uninstall semver \ No newline at end of file + - uses: jdx/mise-action@v2 + - run: mise run ci \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 005255e..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Release - -on: - push: - tags: - - 'v*' - workflow_dispatch: - -jobs: - release: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v4 - - - name: Create Release - uses: softprops/action-gh-release@v1 - with: - draft: false - prerelease: false - generate_release_notes: true - body: | - ## Installation - - ```bash - mise plugin install semver https://github.com/mise-plugins/mise-semver - ``` - - ## What's Changed - - See the auto-generated release notes below for details. \ No newline at end of file diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..0129608 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,39 @@ +-- .luacheckrc configuration for mise-semver plugin + +-- Globals defined by the vfox plugin system +globals = { + "PLUGIN" +} + +-- Read-only globals from vfox environment +read_globals = { + -- Standard Lua globals + "require", + "os", + "io", + "table", + "string", + "math", + "loadfile", + "error", + "ipairs", + "pairs", + "print", + "tostring", + "tonumber", + "type", + "getmetatable", + "setmetatable", + + -- vfox context object + "ctx" +} + +-- Ignore line length warnings +max_line_length = false + +-- Ignore unused arguments in hook functions +unused_args = false + +-- Allow trailing whitespace (can be auto-fixed) +allow_defined_top = true \ No newline at end of file diff --git a/hooks/available.lua b/hooks/available.lua index fc8689e..d6dbc36 100644 --- a/hooks/available.lua +++ b/hooks/available.lua @@ -17,7 +17,7 @@ function PLUGIN:Available(ctx) -- Make API request local resp, err = http.get({ url = repo_url, - headers = headers + headers = headers, }) if err ~= nil then @@ -39,9 +39,9 @@ function PLUGIN:Available(ctx) -- Add version to result table.insert(result, { version = version, - note = nil + note = nil, }) end return result -end \ No newline at end of file +end diff --git a/hooks/env_keys.lua b/hooks/env_keys.lua index 6e58f6e..b1b0fcc 100644 --- a/hooks/env_keys.lua +++ b/hooks/env_keys.lua @@ -6,7 +6,7 @@ function PLUGIN:EnvKeys(ctx) return { { key = "PATH", - value = mainPath .. "/bin" - } + value = mainPath .. "/bin", + }, } -end \ No newline at end of file +end diff --git a/hooks/post_install.lua b/hooks/post_install.lua index c2217a8..d0694e4 100644 --- a/hooks/post_install.lua +++ b/hooks/post_install.lua @@ -1,9 +1,7 @@ -- hooks/post_install.lua function PLUGIN:PostInstall(ctx) - local rootPath = ctx.rootPath - local sdkInfo = ctx.sdkInfo['semver'] + local sdkInfo = ctx.sdkInfo["semver"] local path = sdkInfo.path - local version = sdkInfo.version -- Create bin directory if it doesn't exist os.execute("mkdir -p " .. path .. "/bin") @@ -24,4 +22,4 @@ function PLUGIN:PostInstall(ctx) if testResult ~= 0 then error("semver installation appears to be broken") end -end \ No newline at end of file +end diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index 3721125..af72aa2 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -8,6 +8,6 @@ function PLUGIN:PreInstall(ctx) return { version = version, url = url, - note = "Downloading semver " .. version + note = "Downloading semver " .. version, } -end \ No newline at end of file +end diff --git a/metadata.lua b/metadata.lua index 499db3e..b9e4014 100644 --- a/metadata.lua +++ b/metadata.lua @@ -5,5 +5,5 @@ PLUGIN = { description = "A semantic versioning (semver) command-line tool", author = "mise-plugins", updateUrl = "https://github.com/mise-plugins/mise-semver", - minRuntimeVersion = "0.2.0" -} \ No newline at end of file + minRuntimeVersion = "0.2.0", +} diff --git a/mise-tasks/lint b/mise-tasks/lint new file mode 100755 index 0000000..f0a88bb --- /dev/null +++ b/mise-tasks/lint @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +#MISE description="Lint and format check Lua scripts with luacheck and StyLua" +set -euo pipefail + +luarocks install luacheck --local || true +~/.luarocks/bin/luacheck metadata.lua hooks/ +stylua --check metadata.lua hooks/ \ No newline at end of file diff --git a/mise-tasks/test b/mise-tasks/test new file mode 100755 index 0000000..c327a13 --- /dev/null +++ b/mise-tasks/test @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +#MISE description="Run plugin tests - install and verify semver functionality" +set -euo pipefail + +mise plugin link --force semver . +mise cache clear +mise install semver@3.4.0 + +# Capture and display the output while also verifying it +output=$(mise exec semver@3.4.0 -- semver --version) +echo "semver output: $output" + +if echo "$output" | grep -q '3.4.0'; then + echo "✓ Tests passed" +else + echo "✗ Test failed: expected version 3.4.0" + exit 1 +fi \ No newline at end of file diff --git a/mise.toml b/mise.toml index c9950c5..e512ad3 100644 --- a/mise.toml +++ b/mise.toml @@ -1,20 +1,14 @@ -[tools] -semver = "3.4.0" -shellcheck = "latest" -shfmt = "latest" - -[tasks.test] -description = "Run plugin tests" -run = "./scripts/test.sh" +[env] +MISE_USE_VERSIONS_HOST = "0" -[tasks.lint] -description = "Lint shell and Lua scripts" -run = "./scripts/lint.sh" +[tools] +lua = "5.4" +stylua = "latest" -[tasks."lint:fix"] -description = "Lint and fix shell scripts" -run = "shfmt -w scripts/*.sh" +[tasks.format] +description = "Format Lua scripts" +run = "stylua metadata.lua hooks/" [tasks.ci] description = "Run all CI checks" -depends = ["lint", "test"] +depends = ["lint", "test"] \ No newline at end of file diff --git a/scripts/lint.sh b/scripts/lint.sh deleted file mode 100755 index 9280cf6..0000000 --- a/scripts/lint.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Lint status -LINT_PASSED=true - -# Helper functions -info() { - echo -e "${GREEN}[INFO]${NC} $1" -} - -error() { - echo -e "${RED}[ERROR]${NC} $1" - LINT_PASSED=false -} - -warning() { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -info "Starting linting checks" - -# Check shell scripts with shellcheck -if command -v shellcheck >/dev/null 2>&1; then - info "Checking shell scripts with shellcheck..." - - for script in scripts/*.sh; do - if [ -f "$script" ]; then - echo -n " Checking $(basename "$script")... " - if shellcheck "$script"; then - echo -e "${GREEN}✓${NC}" - else - echo -e "${RED}✗${NC}" - LINT_PASSED=false - fi - fi - done -else - warning "shellcheck not found, install with: mise install shellcheck" -fi - -# Check shell script formatting with shfmt -if command -v shfmt >/dev/null 2>&1; then - info "Checking shell script formatting with shfmt..." - - for script in scripts/*.sh; do - if [ -f "$script" ]; then - echo -n " Checking $(basename "$script")... " - if shfmt -d "$script" >/dev/null 2>&1; then - echo -e "${GREEN}✓${NC}" - else - echo -e "${RED}✗${NC} (run 'mise run lint:fix' to fix)" - LINT_PASSED=false - fi - fi - done -else - warning "shfmt not found, install with: mise install shfmt" -fi - -# Check Lua syntax -if command -v luac >/dev/null 2>&1; then - info "Checking Lua syntax..." - - # Check all Lua files - for lua_file in metadata.lua hooks/*.lua; do - if [ -f "$lua_file" ]; then - echo -n " Checking $(basename "$lua_file")... " - if luac -p "$lua_file" 2>/dev/null; then - echo -e "${GREEN}✓${NC}" - else - echo -e "${RED}✗${NC}" - luac -p "$lua_file" - LINT_PASSED=false - fi - fi - done -else - warning "luac not found, skipping Lua syntax checks" -fi - -# Check for common issues in Lua files -info "Checking for common Lua issues..." - -# Check for consistent indentation (4 spaces) -for lua_file in metadata.lua hooks/*.lua; do - if [ -f "$lua_file" ]; then - echo -n " Checking indentation in $(basename "$lua_file")... " - if ! grep -q $'^\t' "$lua_file"; then - echo -e "${GREEN}✓${NC}" - else - echo -e "${RED}✗${NC} (found tabs, use 4 spaces)" - LINT_PASSED=false - fi - fi -done - -# Check for trailing whitespace -for file in metadata.lua hooks/*.lua scripts/*.sh README.md; do - if [ -f "$file" ]; then - echo -n " Checking trailing whitespace in $(basename "$file")... " - if ! grep -q '[[:space:]]$' "$file"; then - echo -e "${GREEN}✓${NC}" - else - echo -e "${RED}✗${NC}" - LINT_PASSED=false - fi - fi -done - -# Summary -echo -if [ "$LINT_PASSED" = true ]; then - info "All linting checks passed!" - exit 0 -else - error "Some linting checks failed" - exit 1 -fi diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index d0c7bf5..0000000 --- a/scripts/test.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Test counter -TESTS_PASSED=0 -TESTS_FAILED=0 - -# Helper functions -info() { - echo -e "${GREEN}[INFO]${NC} $1" -} - -error() { - echo -e "${RED}[ERROR]${NC} $1" -} - -warning() { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -run_test() { - local test_name="$1" - local test_cmd="$2" - - echo -n "Testing $test_name... " - if eval "$test_cmd" >/dev/null 2>&1; then - echo -e "${GREEN}✓${NC}" - TESTS_PASSED=$((TESTS_PASSED + 1)) - else - echo -e "${RED}✗${NC}" - TESTS_FAILED=$((TESTS_FAILED + 1)) - fi -} - -# Setup test environment -TEST_DIR=$(mktemp -d) -trap 'rm -rf $TEST_DIR' EXIT - -info "Starting mise-semver plugin tests" - -# Test 1: Check plugin structure -run_test "Plugin structure" "test -f metadata.lua && test -d hooks" - -# Test 2: Check required hooks exist -run_test "Available hook exists" "test -f hooks/available.lua" -run_test "Pre-install hook exists" "test -f hooks/pre_install.lua" -run_test "Post-install hook exists" "test -f hooks/post_install.lua" -run_test "Env keys hook exists" "test -f hooks/env_keys.lua" - -# Test 3: Validate Lua syntax -if command -v luac >/dev/null 2>&1; then - run_test "metadata.lua syntax" "luac -p metadata.lua" - run_test "available.lua syntax" "luac -p hooks/available.lua" - run_test "pre_install.lua syntax" "luac -p hooks/pre_install.lua" - run_test "post_install.lua syntax" "luac -p hooks/post_install.lua" - run_test "env_keys.lua syntax" "luac -p hooks/env_keys.lua" -else - warning "luac not found, skipping Lua syntax checks" -fi - -# Test 4: Test with mise if available -if command -v mise >/dev/null 2>&1; then - info "Testing with mise" - - # Save current directory - PLUGIN_DIR=$(pwd) - - # Create test project - cd "$TEST_DIR" - - # Uninstall plugin if already installed - mise plugin uninstall semver 2>/dev/null || true - - # Install plugin from local directory - run_test "Plugin installation" "mise plugin link semver '$PLUGIN_DIR'" - - # List available versions - run_test "List versions" "mise ls-remote semver | grep -q '3.4.0'" - - # Install a specific version - run_test "Install semver 3.4.0" "mise install semver@3.4.0" - - # Test execution - run_test "Execute semver" "mise exec semver@3.4.0 -- semver --version | grep -q '3.4.0'" - - # Clean up - mise plugin uninstall semver 2>/dev/null || true - - cd "$PLUGIN_DIR" -else - warning "mise not found, skipping integration tests" -fi - -# Print summary -echo -echo "Test Results:" -echo "=============" -echo -e "Passed: ${GREEN}$TESTS_PASSED${NC}" -echo -e "Failed: ${RED}$TESTS_FAILED${NC}" - -if [ $TESTS_FAILED -eq 0 ]; then - info "All tests passed!" - exit 0 -else - error "Some tests failed" - exit 1 -fi diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..5b1add7 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,10 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 4 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "Never" + +[sort_requires] +enabled = false \ No newline at end of file