diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73040d0..4b28fba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,4 +16,6 @@ jobs: steps: - uses: actions/checkout@v4 - uses: jdx/mise-action@v2 - - run: mise run ci \ No newline at end of file + - run: mise run ci + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.luacheckrc b/.luacheckrc index 0129608..83398e3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,8 +1,8 @@ -- .luacheckrc configuration for mise-semver plugin --- Globals defined by the vfox plugin system +-- Globals defined by the vfox plugin system globals = { - "PLUGIN" + "PLUGIN", } -- Read-only globals from vfox environment @@ -32,8 +32,9 @@ read_globals = { -- Ignore line length warnings max_line_length = false --- Ignore unused arguments in hook functions +-- Ignore unused arguments in hook functions and unused globals unused_args = false +unused = false --- Allow trailing whitespace (can be auto-fixed) +-- Allow defined top-level variables and trailing whitespace allow_defined_top = true \ No newline at end of file diff --git a/README.md b/README.md index d97525b..13f70db 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,21 @@ mise use -g semver@3.4.0 mise use semver@3.4.0 ``` +## Development + +This project uses [hk](https://hk.jdx.dev) for pre-commit hooks and linting. + +```bash +# Install pre-commit hooks +hk install + +# Run linting manually +mise run lint + +# Run all CI checks +mise run ci +``` + ## About semver semver is a bash utility to manipulate and validate semantic versions. It provides commands to: diff --git a/hk.pkl b/hk.pkl new file mode 100644 index 0000000..493fd2e --- /dev/null +++ b/hk.pkl @@ -0,0 +1,33 @@ +amends "package://github.com/jdx/hk/releases/download/v1.2.0/hk@1.2.0#/Config.pkl" +import "package://github.com/jdx/hk/releases/download/v1.2.0/hk@1.2.0#/Builtins.pkl" + +local linters = new Mapping { + ["luacheck"] { + glob = "**/*.lua" + check = "luarocks install luacheck --local || true && ~/.luarocks/bin/luacheck {{files}}" + } + ["stylua"] { + glob = "**/*.lua" + check = "stylua --check {{files}}" + fix = "stylua {{files}}" + } + ["actionlint"] { + glob = ".github/workflows/*.{yml,yaml}" + check = "actionlint {{files}}" + } +} + +hooks { + ["pre-commit"] { + fix = true + stash = "git" + steps = linters + } + ["fix"] { + fix = true + steps = linters + } + ["check"] { + steps = linters + } +} diff --git a/metadata.lua b/metadata.lua index b9e4014..6ca55f2 100644 --- a/metadata.lua +++ b/metadata.lua @@ -1,5 +1,5 @@ -- metadata.lua -PLUGIN = { +PLUGIN = { -- luacheck: ignore name = "semver", version = "1.0.0", description = "A semantic versioning (semver) command-line tool", diff --git a/mise-tasks/lint b/mise-tasks/lint deleted file mode 100755 index f0a88bb..0000000 --- a/mise-tasks/lint +++ /dev/null @@ -1,7 +0,0 @@ -#!/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.toml b/mise.toml index e512ad3..7476bea 100644 --- a/mise.toml +++ b/mise.toml @@ -2,13 +2,20 @@ MISE_USE_VERSIONS_HOST = "0" [tools] +actionlint = "1" +hk = "1" lua = "5.4" -stylua = "latest" +pkl = "0.29" +stylua = "2" [tasks.format] description = "Format Lua scripts" run = "stylua metadata.lua hooks/" +[tasks.lint] +description = "Lint Lua scripts and GitHub Actions using hk" +run = "hk check" + [tasks.ci] description = "Run all CI checks" -depends = ["lint", "test"] \ No newline at end of file +depends = ["lint", "test"]