Skip to content

Commit

Permalink
feat: enable verbose logging if run with debug mode (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Sep 20, 2023
1 parent 23360e4 commit 1d6da4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ runs:
INPUT_TEMPLATE: ${{ inputs.template }}
INPUT_LICENSE: ${{ inputs.license }}
INPUT_TEST_INTERPRETERS: ${{ inputs.test_interpreters }}
RUNNER_DEBUG: ${{ runner.debug }}
shell: bash
1 change: 1 addition & 0 deletions bin/luarocks-tag-release-action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ local args = {
github_event_path = getenv_or_err('GITHUB_EVENT_PATH'),
ref_type = getenv_or_err('GITHUB_REF_TYPE'),
git_ref = getenv_or_err('GITHUB_REF_NAME'),
is_debug = os.getenv('RUNNER_DEBUG') == '1',
}

print('Workflow has been triggered by: ' .. args.ref_type)
Expand Down
29 changes: 16 additions & 13 deletions lua/luarocks-tag-release.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
---@field license string|nil License SPDX ID (optional).
---@field luarocks_test_interpreters lua_interpreter[]
---@field github_event_path string|nil The path to the file on the runner that contains the full event webhook payload. For example, /github/workflow/event.json.
---@field is_debug boolean Whether to enable debug logging

---@param package_name string The name of the LuaRocks package.
---@param package_version string The version of the LuaRocks package.
Expand All @@ -30,27 +31,29 @@ local function luarocks_tag_release(package_name, package_version, specrev, args

local rockspec_file_path = package_name .. '-' .. modrev .. '-' .. specrev .. '.rockspec'

local luarocks_extra_flags = args.is_debug and ' --verbose ' or ''

local OS = require('ltr.os')

---@param interpreter lua_interpreter
---@return nil
local function luarocks_test(interpreter)
print('Initialising luarocks project...')
OS.execute('luarocks init', print)
OS.execute('luarocks init' .. luarocks_extra_flags, print)
print('Done.')
print('Configuring luarocks to use interpreter ' .. interpreter .. '...')
OS.execute('luarocks config --scope project lua_interpreter ' .. interpreter)
OS.execute('luarocks config --scope project lua_interpreter ' .. interpreter .. luarocks_extra_flags)
print('Done.')
print('Running tests...')
OS.execute('luarocks test', error, true)
OS.execute('rm -r .luarocks luarocks', print)
OS.execute('luarocks test' .. luarocks_extra_flags, error, true)
OS.execute('rm -r .luarocks luarocks', print, args.is_debug)
end

---@return string tmp_dir The temp directory in which to install the package
---@return string luarocks_install_cmd The luarocks install command for installing in tmp_dir
local function mk_luarocks_install_cmd()
local tmp_dir = OS.execute('mktemp -d', error):gsub('\n', '')
local luarocks_install_cmd = 'luarocks install --tree ' .. tmp_dir
local tmp_dir = OS.execute('mktemp -d', error, args.is_debug):gsub('\n', '')
local luarocks_install_cmd = 'luarocks install --tree ' .. tmp_dir .. luarocks_extra_flags
return tmp_dir, luarocks_install_cmd
end

Expand All @@ -64,11 +67,11 @@ local function luarocks_tag_release(package_name, package_version, specrev, args
local tmp_dir, luarocks_install_cmd = mk_luarocks_install_cmd()
local cmd = luarocks_install_cmd .. ' ' .. rockspec_file_path
print('TEST: ' .. cmd)
local stdout, _ = OS.execute(cmd)
local stdout, _ = OS.execute(cmd, error, args.is_debug)
print(stdout)
cmd = 'luarocks remove --tree ' .. tmp_dir .. ' ' .. package_name
cmd = 'luarocks remove --tree ' .. tmp_dir .. ' ' .. package_name .. luarocks_extra_flags
print('TEST: ' .. cmd)
stdout, _ = OS.execute(cmd, error)
stdout, _ = OS.execute(cmd, error, args.is_debug)
print(stdout)
return rockspec_file_path
end
Expand All @@ -77,13 +80,13 @@ local function luarocks_tag_release(package_name, package_version, specrev, args
---@return nil
local function luarocks_upload(target_rockspec_path)
local _, luarocks_install_cmd = mk_luarocks_install_cmd()
local cmd = 'luarocks upload ' .. target_rockspec_path .. ' --api-key $LUAROCKS_API_KEY'
local cmd = 'luarocks upload ' .. target_rockspec_path .. ' --api-key $LUAROCKS_API_KEY' .. luarocks_extra_flags
print('UPLOAD: ' .. cmd)
local stdout, _ = OS.execute(cmd)
local stdout, _ = OS.execute(cmd, error, args.is_debug)
print(stdout)
cmd = luarocks_install_cmd .. ' ' .. package_name .. ' ' .. modrev
cmd = luarocks_install_cmd .. ' ' .. package_name .. ' ' .. modrev .. luarocks_extra_flags
print('TEST: ' .. cmd)
stdout, _ = OS.execute(cmd, print)
stdout, _ = OS.execute(cmd, print, args.is_debug)
print(stdout)
end

Expand Down

0 comments on commit 1d6da4a

Please sign in to comment.