From 61eed1c3f0666265728ad164c93b0722ea4c0dbd Mon Sep 17 00:00:00 2001 From: Marc Jakobi Date: Wed, 8 Mar 2023 14:34:01 +0100 Subject: [PATCH] feat!: better defaults for copy_directories + only add existing ones (#31) BREAKING CHANGE: This could result in new directories being added to packages that did not set the copy_directories input. --- .github/workflows/pr.yml | 3 ++ .github/workflows/release.yml | 3 ++ CHANGELOG.md | 9 ++++ README.md | 49 ++++++++++++++----- action.yml | 9 +++- bin/luarocks-tag-release.lua | 74 +++++++++++++++++++++++++---- flake.nix | 5 +- luarocks-tag-release-scm-1.rockspec | 1 + 8 files changed, 126 insertions(+), 27 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0b9bd08..0ae7ab5 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -18,3 +18,6 @@ jobs: plenary.nvim version: "0.0.0" upload: false + copy_directories: | + {{ neovim.plugin.dirs }} + bin diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e4d1080..5f0f741 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,9 @@ jobs: detailed_description: | This is not a real lua package. It exists for the purpose of testing the workflow. + copy_directories: | + {{ neovim.plugin.dirs }} + bin - name: Fail if changelog entry does not exist run: grep -q "${{ github.ref_name }}" CHANGELOG.md - name: Release to marketplace diff --git a/CHANGELOG.md b/CHANGELOG.md index e669028..a5eff7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [v3.0.0] - 2023-03-08 +### Added +- Add directories from Neovim's `runtimepath` and some common plugin directories + as the default for the `copy_directories` input. + BREAKING CHANGE: This could potentially add new directories to LuaRocks packages, + if the `copy_directories` input is not explicity specified, and one of the new default directories exists. +### Changed +- Only add directories that exist to the rockspec's `copy_directories`. + ## [v2.3.0] - 2023-03-01 ### Added - Maintain `vX` and `vX.X` tags for the latest non-breaking releases. diff --git a/README.md b/README.md index ccded10..4ff9bb1 100644 --- a/README.md +++ b/README.md @@ -45,14 +45,14 @@ jobs: - name: Checkout uses: actions/checkout@v3 - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 env: LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} ``` > **Note** > -> Use the `v2` tag to keep up with the latest releases, without breaking changes. +> Use the `v3` tag to keep up with the latest releases, without breaking changes. ## Inputs @@ -73,7 +73,7 @@ Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: dependencies: | plenary.nvim @@ -89,7 +89,7 @@ Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: labels: | neovim @@ -99,17 +99,40 @@ Example: Directories in the source directory to be copied to the rock installation prefix as-is. Useful for installing documentation and other files such as samples and tests. -Example to specify additional directories: +Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: copy_directories: | - doc - plugin + {{ neovim.plugin.dirs }} + src + examples ``` +>**Note** +> +> The value `{{ neovim.plugin.dirs }}` (set by default) expands to common Neovim plugin directories +> (see also `:help runtimepath`): +> +> * autoload +> * colors +> * compiler +> * doc +> * filetype.lua +> * indent +> * keymap +> * lang +> * menu.vim +> * parser +> * plugin +> * queries +> * query +> * rplugin +> * spell +> * syntax +> >**Warning** > > Do not use the following directory names: `lua`, `lib`, `rock_manifest` or the name of your rockspec; those names are used by the .rock format internally, and attempting to copy directories with those names using the build.copy_directories directive will cause a clash. @@ -127,7 +150,7 @@ Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: detailed_description: | Publishes packages to LuaRocks when a git tag is pushed. @@ -146,7 +169,7 @@ Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: build_type: "make" ``` @@ -162,7 +185,7 @@ Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: template: "/path/to/my/template.rockspec" ``` @@ -177,7 +200,7 @@ Example: ```yaml - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 with: license: "MIT" ``` @@ -217,7 +240,7 @@ jobs: - name: Get new commits run: echo "NEW_COMMIT_COUNT=$(git log --oneline --since '24 hours ago' | wc -l)" >> $GITHUB_ENV - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v2 + uses: nvim-neorocks/luarocks-tag-release@v3 if: ${{ env.NEW_COMMIT_COUNT > 0 }} env: LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} diff --git a/action.yml b/action.yml index e74877d..b7df2c0 100644 --- a/action.yml +++ b/action.yml @@ -23,9 +23,14 @@ inputs: required: true default: "" copy_directories: - description: "List of additional directories to copy." + description: | + List of additional directories to copy. + Only directories that exist will be copied. + The defaults are taken from Neovim's `:help runtimepath` + WARNING: Do not add the directories `lua`, `lib` or `rock_manifest`. required: true - default: "" + default: | + {{ neovim.plugin.dirs }} summary: description: "Short description of the package." required: true diff --git a/bin/luarocks-tag-release.lua b/bin/luarocks-tag-release.lua index 77ce2d2..dec8f37 100755 --- a/bin/luarocks-tag-release.lua +++ b/bin/luarocks-tag-release.lua @@ -18,6 +18,18 @@ local arg_list = { ... } assert(os.getenv('LUAROCKS_API_KEY'), 'LUAROCKS_API_KEY secret not set') +local github_repo = assert(os.getenv('GITHUB_REPOSITORY'), 'GITHUB_REPOSITORY not set') + +local repo_name = assert( + string.match(github_repo, '/(.+)'), + [[ + Could not determine repository name from GITHUB_REPOSITORY. + If you see this, please report this as a bug. + ]] +) + +local github_server_url = assert(os.getenv('GITHUB_SERVER_URL'), 'GITHUB_SERVER_URL not set') + ---@param str string ---@return string[] list_arg local function parse_list_args(str) @@ -28,17 +40,59 @@ local function parse_list_args(str) return tbl end -local github_repo = assert(os.getenv('GITHUB_REPOSITORY'), 'GITHUB_REPOSITORY not set') +---Filter out directories that don't exist. +---@param directories string[] List of directories. +---@return string[] existing_directories +local function filter_existing_directories(directories) + local existing_directories = {} + for _, dir in pairs(directories) do + if require('lfs').attributes(dir, 'mode') == 'directory' then + existing_directories[#existing_directories + 1] = dir + end + end + return existing_directories +end -local repo_name = assert( - string.match(github_repo, '/(.+)'), - [[ - Could not determine repository name from GITHUB_REPOSITORY. - If you see this, please report this as a bug. - ]] -) +---Insert Neovim plugin directories into the `copy_directories` list +---@param copy_directories string[] List of directories +local function insert_neovim_plugin_dirs(copy_directories) + local neovim_plugin_dirs = { + 'autoload', + 'colors', + 'compiler', + 'doc', + 'filetype.lua', + 'indent', + 'keymap', + 'lang', + 'menu.vim', + 'parser', + 'plugin', + 'queries', + 'query', + 'rplugin', + 'spell', + 'syntax', + } + for _, dir in neovim_plugin_dirs do + table.insert(copy_directories, dir) + end +end -local github_server_url = assert(os.getenv('GITHUB_SERVER_URL'), 'GITHUB_SERVER_URL not set') +---@param str_args string The arguments to parse +---@return string[] copy_directories The directories to copy +local function parse_copy_directory_args(str_args) + local args = parse_list_args(str_args) + local copy_directories = {} + for _, arg in pairs(args) do + if string.match(arg, '{{ neovim.plugin.dirs }}') then + insert_neovim_plugin_dirs(copy_directories) + else + copy_directories[#copy_directories + 1] = arg + end + end + return filter_existing_directories(copy_directories) +end ---@type Args local args = { @@ -46,7 +100,7 @@ local args = { package_version = arg_list[2], dependencies = parse_list_args(arg_list[3]), labels = parse_list_args(arg_list[4]), - copy_directories = parse_list_args(arg_list[5]), + copy_directories = parse_copy_directory_args(arg_list[5]), summary = arg_list[6], detailed_description_lines = parse_list_args(arg_list[7]), build_type = arg_list[8], diff --git a/flake.nix b/flake.nix index b2e796b..3b846a4 100644 --- a/flake.nix +++ b/flake.nix @@ -30,8 +30,9 @@ src = self; - propagatedBuildInputs = with pkgs; [ - lua51Packages.dkjson + propagatedBuildInputs = with pkgs.lua51Packages; [ + dkjson + luafilesystem ]; }; in diff --git a/luarocks-tag-release-scm-1.rockspec b/luarocks-tag-release-scm-1.rockspec index 0eac319..20497be 100755 --- a/luarocks-tag-release-scm-1.rockspec +++ b/luarocks-tag-release-scm-1.rockspec @@ -12,6 +12,7 @@ description = { dependencies = { 'lua >= 5.1', 'dkjson', + 'luafilesystem', } source = {