Skip to content

Commit

Permalink
chore: split script up into github-action and luarocks-tag-release
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Mar 19, 2023
1 parent ed865a3 commit 0198fc5
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 314 deletions.
40 changes: 19 additions & 21 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,12 +31,10 @@ 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: ""
required: false
build_type:
description: "The build type."
required: true
Expand Down Expand Up @@ -70,17 +66,19 @@ runs:
- uses: cachix/install-nix-action@v20
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- run: |
entrypoint.sh
\ ${{ 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 }}
- run: nix profile install ".#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_BUILD_TYPE: ${{ inputs.build_type }}
INPUT_TEMPLATE: ${{ inputs.template }}
INPUT_UPLOAD: ${{ inputs.upload }}
INPUT_LICENSE: ${{ inputs.license }}
shell: bash
110 changes: 110 additions & 0 deletions bin/luarocks-tag-release-action.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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 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')

---@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')),
build_type = getenv_or_err('INPUT_BUILD_TYPE'),
rockspec_template_file_path = getenv_or_err('INPUT_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 0198fc5

Please sign in to comment.