Skip to content

Commit

Permalink
chore!: convert to composite action (#38)
Browse files Browse the repository at this point in the history
* chore: convert workflow to a composite action

* chore: split script up into github-action and luarocks-tag-release

* fix: use github.action_path

* chore!: remove gnumake from wrapper and remove build_type input
  • Loading branch information
mrcjkb authored Mar 19, 2023
1 parent 61eed1c commit af973b1
Show file tree
Hide file tree
Showing 10 changed files with 340 additions and 354 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v4.0.0] - 2023-03-08
- POTENIALLY BREAKING: Convert to composite action.
- POTENTIALLY BREAKING: Remove redundant `build_type` input.
Use `template` input for non-builtin build types instead.
- Remove `gnumake` from shell wrapper (no longer needed in a composite action).

## [v3.0.0] - 2023-03-08
### Added
- Add directories from Neovim's `runtimepath` and some common plugin directories
Expand Down
11 changes: 0 additions & 11 deletions Dockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,6 @@ Example:
and tests the installation before releasing.
```

### `build_type`

The LuaRocks build backend.

* Defaults to `builtin`.
* If the installation fails, it may be necessary to [use a Makefile](https://github.com/luarocks/luarocks/wiki/Creating-a-Makefile-that-plays-nice-with-LuaRocks).

Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v3
with:
build_type: "make"
```

### `template`

By default, this workflow will generate a rockspec based on a [predefined template](./rockspec.template).
Expand Down
55 changes: 23 additions & 32 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ inputs:
default: ${{ github.ref_name }}
dependencies:
description: "List of LuaRocks dependencies."
required: true
default: ""
required: false
labels:
description: "List of package labels."
required: true
default: ""
required: false
copy_directories:
description: |
List of additional directories to copy.
Expand All @@ -33,24 +31,13 @@ inputs:
{{ neovim.plugin.dirs }}
summary:
description: "Short description of the package."
required: true
default: ""
required: false
detailed_description:
description: "Detailed description of the package."
required: true
default: ""
build_type:
description: "The build type."
required: true
default: builtin
type: choice
options:
- builtin
- make
required: false
template:
description: "Path to a rockspec template."
required: true
default: "/rockspec.template"
required: false
upload:
description: |
Whether to upload to LuaRocks.
Expand All @@ -65,17 +52,21 @@ inputs:
in which case LuaRocks will fall back to this one.
required: false
runs:
using: "docker"
image: "Dockerfile"
args:
- ${{ inputs.name }}
- ${{ inputs.version }}
- ${{ inputs.dependencies }}
- ${{ inputs.labels }}
- ${{ inputs.copy-directories }}
- ${{ inputs.summary }}
- ${{ inputs.detailed_description }}
- ${{ inputs.build_type }}
- ${{ inputs.template }}
- ${{ inputs.upload }}
- ${{ inputs.license }}
using: "composite"
steps:
- uses: cachix/install-nix-action@v20
- run: nix profile install "${{ github.action_path }}#luarocks-tag-release-action"
shell: bash
- run: luarocks-tag-release-action
env:
INPUT_NAME: ${{ inputs.name }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_DEPENDENCIES: ${{ inputs.dependencies }}
INPUT_LABELS: ${{ inputs.labels }}
INPUT_COPY_DIRECTORIES: ${{ inputs.copy-directories }}
INPUT_SUMMARY: ${{ inputs.summary }}
INPUT_DETAILED_DESCRIPTION: ${{ inputs.detailed_description }}
INPUT_TEMPLATE: ${{ inputs.template }}
INPUT_UPLOAD: ${{ inputs.upload }}
INPUT_LICENSE: ${{ inputs.license }}
shell: bash
113 changes: 113 additions & 0 deletions bin/luarocks-tag-release-action.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
assert(os.getenv('LUAROCKS_API_KEY'), 'LUAROCKS_API_KEY secret not set')

local function getenv_or_err(env_var)
return assert(os.getenv(env_var), env_var .. ' not set.')
end

local function getenv_or_empty(env_var)
return os.getenv(env_var) or ''
end

local action_path = getenv_or_err('GITHUB_ACTION_PATH')

local github_repo = getenv_or_err('GITHUB_REPOSITORY')

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 = getenv_or_err('GITHUB_SERVER_URL')

---@param str string
---@return string[] list_arg
local function parse_list_args(str)
local tbl = {}
for arg in string.gmatch(str, '[^\r\n]+') do
table.insert(tbl, arg)
end
return tbl
end

---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

---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

---@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

local license_input = os.getenv('INPUT_LICENSE')
local template_input = os.getenv('INPUT_TEMPLATE')

---@type Args
local args = {
github_repo = github_repo,
repo_name = repo_name,
github_server_url = github_server_url,
package_name = getenv_or_err('INPUT_NAME'),
package_version = getenv_or_err('INPUT_VERSION'),
dependencies = parse_list_args(getenv_or_empty('INPUT_DEPENDENCIES')),
labels = parse_list_args(getenv_or_empty('INPUT_LABELS')),
copy_directories = parse_copy_directory_args(getenv_or_err('INPUT_COPY_DIRECTORIES')),
summary = getenv_or_empty('INPUT_SUMMARY'),
detailed_description_lines = parse_list_args(getenv_or_empty('INPUT_DETAILED_DESCRIPTION')),
rockspec_template_file_path = template_input ~= '' and template_input
or action_path .. '/resources/rockspec.template',
upload = getenv_or_err('INPUT_UPLOAD') == 'true',
license = license_input ~= '' and license_input or nil,
}
table.insert(args.dependencies, 1, 'lua >= 5.1')

local luarocks_tag_release = require('luarocks-tag-release')

luarocks_tag_release(args)
Loading

0 comments on commit af973b1

Please sign in to comment.