Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: convert to composite action #38

Merged
merged 4 commits into from
Mar 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Dockerfile

This file was deleted.

48 changes: 24 additions & 24 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 All @@ -49,8 +45,7 @@ inputs:
- make
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 +60,22 @@ 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:
mrcjkb marked this conversation as resolved.
Show resolved Hide resolved
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
114 changes: 114 additions & 0 deletions bin/luarocks-tag-release-action.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
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')),
build_type = getenv_or_err('INPUT_BUILD_TYPE'),
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