Skip to content

Commit

Permalink
feat!: better defaults for copy_directories + only add existing ones (#…
Browse files Browse the repository at this point in the history
…31)

BREAKING CHANGE: This could result in new directories being added
to packages that did not set the copy_directories input.
  • Loading branch information
mrcjkb authored Mar 8, 2023
1 parent d01919d commit 61eed1c
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ jobs:
plenary.nvim
version: "0.0.0"
upload: false
copy_directories: |
{{ neovim.plugin.dirs }}
bin
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
49 changes: 36 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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"
```
Expand All @@ -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"
```
Expand All @@ -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"
```
Expand Down Expand Up @@ -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 }}
Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 64 additions & 10 deletions bin/luarocks-tag-release.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,25 +40,67 @@ 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 = {
package_name = arg_list[1],
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],
Expand Down
5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@

src = self;

propagatedBuildInputs = with pkgs; [
lua51Packages.dkjson
propagatedBuildInputs = with pkgs.lua51Packages; [
dkjson
luafilesystem
];
};
in
Expand Down
1 change: 1 addition & 0 deletions luarocks-tag-release-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = {
dependencies = {
'lua >= 5.1',
'dkjson',
'luafilesystem',
}

source = {
Expand Down

0 comments on commit 61eed1c

Please sign in to comment.