Skip to content

Commit

Permalink
feat: do not fail on already existing rocks, add fail_on_duplicate
Browse files Browse the repository at this point in the history
…flag (#411)
  • Loading branch information
vhyrro authored May 25, 2024
1 parent d6ec863 commit 07c35cf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ Example:
specrev: "${{ env.SPECREV }}"
```

### `fail_on_duplicate` (optional)

When set to `true` will cause the workflow to fail with an error if the rock already exists on the server.
By default, if the rock already exists with a given version, the workflow will do nothing and fall back to other tasks
instead (e.g. running tests).

### `extra_luarocks_args`

Extra args to pass to the luarocks command.
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ inputs:
Extra args to pass to the luarocks command.
For example: "CURL_DIR=/usr/include/x86_64-linux-gnu/"
required: false
fail_on_duplicate:
description: |
Whether to fail if the rock's version has already been published to `luarocks.org`.
required: false
runs:
using: "composite"
steps:
Expand All @@ -92,5 +96,6 @@ runs:
INPUT_LICENSE: ${{ inputs.license }}
INPUT_TEST_INTERPRETERS: ${{ inputs.test_interpreters }}
INPUT_EXTRA_LUAROCKS_ARGS: ${{ inputs.extra_luarocks_args }}
INPUT_FAIL_ON_DUPLICATE: ${{ inputs.fail_on_duplicate }}
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 @@ -59,6 +59,7 @@ local args = {
ref_type = os.getenv('GITHUB_REF_TYPE_OVERRIDE') or getenv_or_err('GITHUB_REF_TYPE'),
git_ref = os.getenv('GITHUB_REF_NAME_OVERRIDE') or getenv_or_err('GITHUB_REF_NAME'),
is_debug = os.getenv('RUNNER_DEBUG') == '1',
fail_on_duplicate = getenv_or_empty('INPUT_FAIL_ON_DUPLICATE') == 'true',
}

local function get_github_sha()
Expand Down
15 changes: 14 additions & 1 deletion lua/luarocks-tag-release.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
---@field extra_luarocks_args string[]
---@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
---@field fail_on_duplicate boolean Whether to fail if the rock version has already been uploaded.

---@param package_name string The name of the LuaRocks package.
---@param package_version string | nil The version of the LuaRocks package.
Expand Down Expand Up @@ -92,7 +93,19 @@ local function luarocks_tag_release(package_name, package_version, specrev, args
.. ' --api-key $LUAROCKS_API_KEY'
.. luarocks_extra_flags_and_args
print('UPLOAD: ' .. cmd)
local stdout, _ = OS.execute(cmd, error, args.is_debug)
local stdout, _ = OS.execute(cmd, function(message)
if message:find('already exists on the server') and not args.fail_on_duplicate then
print(
string.format(
'%s already exists with version %s on the remote. Doing nothing (`fail_on_duplicate` is false).',
package_name,
package_version
)
)
else
error(message)
end
end, args.is_debug)
print(stdout)
cmd = luarocks_install_cmd .. ' ' .. package_name .. ' ' .. modrev .. luarocks_extra_flags_and_args
print('TEST: ' .. cmd)
Expand Down

0 comments on commit 07c35cf

Please sign in to comment.