Skip to content

Commit 07c35cf

Browse files
authored
feat: do not fail on already existing rocks, add fail_on_duplicate flag (#411)
1 parent d6ec863 commit 07c35cf

4 files changed

+26
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ Example:
354354
specrev: "${{ env.SPECREV }}"
355355
```
356356

357+
### `fail_on_duplicate` (optional)
358+
359+
When set to `true` will cause the workflow to fail with an error if the rock already exists on the server.
360+
By default, if the rock already exists with a given version, the workflow will do nothing and fall back to other tasks
361+
instead (e.g. running tests).
362+
357363
### `extra_luarocks_args`
358364

359365
Extra args to pass to the luarocks command.

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ inputs:
6969
Extra args to pass to the luarocks command.
7070
For example: "CURL_DIR=/usr/include/x86_64-linux-gnu/"
7171
required: false
72+
fail_on_duplicate:
73+
description: |
74+
Whether to fail if the rock's version has already been published to `luarocks.org`.
75+
required: false
7276
runs:
7377
using: "composite"
7478
steps:
@@ -92,5 +96,6 @@ runs:
9296
INPUT_LICENSE: ${{ inputs.license }}
9397
INPUT_TEST_INTERPRETERS: ${{ inputs.test_interpreters }}
9498
INPUT_EXTRA_LUAROCKS_ARGS: ${{ inputs.extra_luarocks_args }}
99+
INPUT_FAIL_ON_DUPLICATE: ${{ inputs.fail_on_duplicate }}
95100
RUNNER_DEBUG: ${{ runner.debug }}
96101
shell: bash

bin/luarocks-tag-release-action.lua

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ local args = {
5959
ref_type = os.getenv('GITHUB_REF_TYPE_OVERRIDE') or getenv_or_err('GITHUB_REF_TYPE'),
6060
git_ref = os.getenv('GITHUB_REF_NAME_OVERRIDE') or getenv_or_err('GITHUB_REF_NAME'),
6161
is_debug = os.getenv('RUNNER_DEBUG') == '1',
62+
fail_on_duplicate = getenv_or_empty('INPUT_FAIL_ON_DUPLICATE') == 'true',
6263
}
6364

6465
local function get_github_sha()

lua/luarocks-tag-release.lua

+14-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
---@field extra_luarocks_args string[]
2323
---@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.
2424
---@field is_debug boolean Whether to enable debug logging
25+
---@field fail_on_duplicate boolean Whether to fail if the rock version has already been uploaded.
2526

2627
---@param package_name string The name of the LuaRocks package.
2728
---@param package_version string | nil The version of the LuaRocks package.
@@ -92,7 +93,19 @@ local function luarocks_tag_release(package_name, package_version, specrev, args
9293
.. ' --api-key $LUAROCKS_API_KEY'
9394
.. luarocks_extra_flags_and_args
9495
print('UPLOAD: ' .. cmd)
95-
local stdout, _ = OS.execute(cmd, error, args.is_debug)
96+
local stdout, _ = OS.execute(cmd, function(message)
97+
if message:find('already exists on the server') and not args.fail_on_duplicate then
98+
print(
99+
string.format(
100+
'%s already exists with version %s on the remote. Doing nothing (`fail_on_duplicate` is false).',
101+
package_name,
102+
package_version
103+
)
104+
)
105+
else
106+
error(message)
107+
end
108+
end, args.is_debug)
96109
print(stdout)
97110
cmd = luarocks_install_cmd .. ' ' .. package_name .. ' ' .. modrev .. luarocks_extra_flags_and_args
98111
print('TEST: ' .. cmd)

0 commit comments

Comments
 (0)