Skip to content

Add module version constant #289

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ luacov.report.out
luacov.stats.out
build/*.cmake
build/Makefile
.history
crud/VERSION.lua
Makefile
CTestTestfile.cmake
cmake_install.cmake
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

* crud.VERSION constant to make it possible to determine crud module
version application runs on in runtime

### Changed

### Fixed
Expand Down
21 changes: 21 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ file(GLOB_RECURSE LUA_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/cartridge/roles/*.lua"
)

## VERSION ####################################################################
###############################################################################

execute_process(
COMMAND git describe --tags --always
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE GIT_DESCRIBE
ERROR_QUIET
)

if (NOT GIT_DESCRIBE)
set(GIT_DESCRIBE "unknown")
endif()

configure_file (
"${PROJECT_SOURCE_DIR}/crud/VERSION.lua.in"
"${CMAKE_CURRENT_BINARY_DIR}/crud/VERSION.lua"
)

## Testing ####################################################################
###############################################################################

Expand Down Expand Up @@ -78,6 +98,7 @@ endif()
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}
DESTINATION ${TARANTOOL_INSTALL_LUADIR}
PATTERN "*.in" EXCLUDE
)

install(
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,12 @@ support preserving stats between role reload
(see [tarantool/metrics#334](https://github.com/tarantool/metrics/issues/334)),
thus this feature will be unsupported for `metrics` driver.

### VERSION

`VERSION` - is a crud module version constant.

Use `crud.VERSION` on "routers" to get module version, or `_crud.VERSION` - on storages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we use globals and different API for routers and storages? There are no supported cases for using _crud now, all interaction are processed with require('crud').something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no supported cases for using _crud: And what is this:

crud/crud.lua

Line 123 in e709a87

rawset(_G, '_crud', {})
?
and this;
_G._crud.select_on_storage = select_on_storage

and so on...?

Copy link
Member

@DifferentialOrange DifferentialOrange May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's internal and should be used only by crud itself, not by user


## Cartridge roles

`cartridge.roles.crud-storage` is a Tarantool Cartridge role that depends on the
Expand Down
8 changes: 8 additions & 0 deletions crud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ local stats = require('crud.stats')

local crud = {}

local ok, VERSION = pcall(require, 'crud.VERSION')
if not ok then
VERSION = 'unknown'
end

crud.VERSION = VERSION

--- CRUD operations.
-- @section crud

Expand Down Expand Up @@ -123,6 +130,7 @@ function crud.init_storage()
rawset(_G, '_crud', {})
end

_G._crud.VERSION = VERSION
insert.init()
get.init()
replace.init()
Expand Down
3 changes: 3 additions & 0 deletions crud/VERSION.lua.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env tarantool

return "@GIT_DESCRIBE@"
57 changes: 57 additions & 0 deletions test/unit/version_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
local fio = require('fio')

local t = require('luatest')
local g = t.group('version')

local helpers = require('test.helper')

g.before_all = function()
g.cluster = helpers.Cluster:new({
datadir = fio.tempdir(),
server_command = helpers.entrypoint('srv_say_hi'),
use_vshard = true,
replicasets = {
{
uuid = helpers.uuid('a'),
alias = 'router',
roles = { 'crud-router' },
servers = {
{ instance_uuid = helpers.uuid('a', 1), alias = 'router' },
},
},
{
uuid = helpers.uuid('b'),
alias = 's-1',
roles = { 'crud-storage' },
servers = {
{ instance_uuid = helpers.uuid('b', 1), alias = 's1-master' },
{ instance_uuid = helpers.uuid('b', 2), alias = 's1-replica' },
},
},
{
uuid = helpers.uuid('c'),
alias = 's-2',
roles = { 'crud-storage' },
servers = {
{ instance_uuid = helpers.uuid('c', 1), alias = 's2-master' },
{ instance_uuid = helpers.uuid('c', 2), alias = 's2-replica' },
},
}
},
})
g.cluster:start()
end

g.after_all = function()
g.cluster:stop()
fio.rmtree(g.cluster.datadir)
end

g.test_version = function()
local handle = io.popen('git describe --tags --always')
local version = handle:read("*a"):gsub('\n*', '')
handle:close()
t.assert_equals(g.cluster.main_server.net_box:eval('return crud.VERSION'), version)
t.assert_equals(g.cluster.servers[2].net_box:eval('return _crud.VERSION'), version)
t.assert_equals(g.cluster.servers[3].net_box:eval('return _crud.VERSION'), version)
end