Skip to content

Commit 332b1ab

Browse files
committed
WIP: Generate graphql.VERSION at build stage
XXX: luarocks removes `.git` directory after cloning a repository. So actually this approach only works when we're within our cloned repository. So, questions: 1. We need to reprase comments acoordingly at least. 2. Whether it works with tarantoolctl rocks install in CI? Now it is possible to obtain a version of the module using the following code: ```lua local graphql = require('graphql') print(graphql.VERSION) ``` It does not work for cloned repository (without calling `tarantoolctl rocks make`) -- the `graphql.VERSION` field will return `'unknown'`, but it works for a user scenario: when the module is installed either from .all.rock file or from the rockspec. The short list of changes is the following. - Upload all.rock instead of .src.rock for releases. I don't find a way to add a generated file into the .src.rock tarball using luarocks. It is not necessary, though: it is completely okay (and even preferable) to ship .all.rock for a pure Lua module. - Upload scm-1 rockspec from CI. - Moved from the `'builtin'` build type to `'make'` in the rockspec to generate the `graphql/VERSION.lua` file at the build stage. - Added Make targets for luarocks with `graphql/VERSION.lua` file generation. - Added `graphql/init.lua` file with `VERSION` field, which is filled from the generated `graphql/VERSION.lua` file if it is present. Otherwise it is filled with the `'unknown'` string. And a couple of minor tweaks: - Replaced `tarantoolctl rocks new_version --tag $TAG` with `sed` in the rockspec publication workflow, because the former strips comments and reformats the file. It is a thing of taste: personally I prefer to be able to diff rockspecs on the rock server in case of an incident. - Use `ubuntu-latest` in rockspec publication workflow, because we have nothing Ubuntu version specific here. This way it requires less maintenance. The publication workflow now almost the same as in expirationd, see [1]. As for me, it is good to have such code standartized. This is reimplementation of the original #29 fix from PR #41. The key points are the following. - Usage the `'make'` build type allows to lower the logic down to luarocks level, so it works not only from CI. - Complete the implementation by packing into .all.rock instead of .src.rock. Otherwise it does not work at all, see [2] for details. - Generate the gitignored `graphql/VERSION.lua` file (don't touch `graphql/init.lua`) to don't leave the repository clone in a dirty state. Also it is the alternative to PR #50, where the `'cmake'` build type was proposed for the same purposes. The differences are the following. - Use Make instead of CMake for the same of simplicity. - Don't require tarantool-dev/devel package for building the rock or installing the package from the rockspec. [1]: tarantool/expirationd#55 [2]: #46 (comment) Follows up #29 Supersedes PR #50
1 parent 082d6d1 commit 332b1ab

File tree

5 files changed

+122
-27
lines changed

5 files changed

+122
-27
lines changed

.github/workflows/publish.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,59 @@ name: Publish
22

33
on:
44
push:
5-
tags:
6-
- '*'
5+
branches: [master]
6+
tags: ['*']
77

88
jobs:
9-
publish:
9+
publish-rockspec-scm-1:
10+
if: github.ref == 'refs/heads/master'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: tarantool/rocks.tarantool.org/github-action@master
15+
with:
16+
auth: ${{ secrets.ROCKS_AUTH }}
17+
files: graphql-scm-1.rockspec
18+
19+
publish-rockspec-tag:
1020
if: startsWith(github.ref, 'refs/tags/')
11-
runs-on: ubuntu-20.04
21+
runs-on: ubuntu-latest
1222
steps:
1323
- uses: actions/checkout@v2
24+
25+
# Create a rockspec for the release.
26+
- run: printf '%s=%s\n' TAG "${GITHUB_REF##*/}" >> "${GITHUB_ENV}"
27+
- run: sed -E
28+
-e "s/branch = '.+'/tag = '${{ env.TAG }}'/g"
29+
-e "s/version = '.+'/version = '${{ env.TAG }}-1'/g"
30+
graphql-scm-1.rockspec > graphql-${{ env.TAG }}-1.rockspec
31+
32+
# Create a rock for the release (.all.rock).
33+
#
34+
# `tarantoolctl rocks pack <module_name> <version>` creates
35+
# .all.rock tarball. It speeds up
36+
# `tarantoolctl rocks install <module_name> <version>` and
37+
# frees it from dependency on git.
38+
#
39+
# Don't confuse this command with
40+
# `tarantoolctl rocks pack <rockspec>`, which creates a
41+
# source tarball (.src.rock).
42+
#
43+
# Important: Don't upload binary rocks to
44+
# rocks.tarantool.org. Lua/C modules should be packed into
45+
# .src.rock instead. See [1] for description of rock types.
46+
#
47+
# [1]: https://github.com/luarocks/luarocks/wiki/Types-of-rocks
1448
- uses: tarantool/setup-tarantool@v1
1549
with:
16-
tarantool-version: '2.8'
17-
18-
- run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV
19-
- run: tarantoolctl rocks new_version --tag $TAG
20-
- run: tarantoolctl rocks pack graphql-$TAG-1.rockspec
50+
tarantool-version: '1.10'
51+
- run: tarantoolctl rocks install graphql-${{ env.TAG }}-1.rockspec
52+
- run: tarantoolctl rocks pack graphql ${{ env.TAG }}
2153

54+
# Upload .rockspec and .all.rock.
2255
- uses: tarantool/rocks.tarantool.org/github-action@master
2356
with:
2457
auth: ${{ secrets.ROCKS_AUTH }}
2558
files: |
2659
graphql-${{ env.TAG }}-1.rockspec
27-
graphql-${{ env.TAG }}-1.src.rock
60+
graphql-${{ env.TAG }}-1.all.rock

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ luacov.*.out*
3030
.history
3131
.vscode
3232
*.rock
33+
# Generated file.
34+
graphql/VERSION.lua

Makefile

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,49 @@
11
SHELL := /bin/bash
22

3+
# {{{ Build & install using luarocks
4+
5+
PREFIX?=/usr/local
6+
TARANTOOL_INSTALL_LUADIR?=$(DESTDIR)$(PREFIX)/share/tarantool
7+
8+
# https://stackoverflow.com/a/18137056/1598057
9+
#
10+
# This way everything works as expected ever for
11+
# `make -C /path/to/project` or
12+
# `make -f /path/to/project/Makefile`.
13+
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
14+
PROJECT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
15+
16+
VERSION := $(shell git -C $(PROJECT_DIR) describe --long --always)
17+
18+
.PHONY: default
19+
default: build
20+
21+
.PHONY: build
22+
build:
23+
# Generate VERSION.lua file within the build directory.
24+
mkdir -p graphql
25+
printf "return '$(VERSION)'\n" > graphql/VERSION.lua
26+
27+
.PHONY: install
28+
install:
29+
# Install source files as is.
30+
install -d -m 755 $(TARANTOOL_INSTALL_LUADIR)/graphql
31+
install -m 644 $(PROJECT_DIR)/graphql/*.lua \
32+
$(TARANTOOL_INSTALL_LUADIR)/graphql
33+
34+
# AFAIS, foo/init.lua usually normalized to foo.lua at
35+
# the installation step. Let's follow this rule.
36+
mv $(TARANTOOL_INSTALL_LUADIR)/graphql/init.lua \
37+
$(TARANTOOL_INSTALL_LUADIR)/graphql.lua
38+
39+
# Copy the generated VERSION.lua file.
40+
install -m 644 graphql/VERSION.lua \
41+
$(TARANTOOL_INSTALL_LUADIR)/graphql/VERSION.lua
42+
43+
# }}} Build & install using luarocks
44+
45+
# {{{ Developer tools
46+
347
.PHONY: .rocks
448
.rocks: graphql-scm-1.rockspec Makefile
549
tarantoolctl rocks make
@@ -23,7 +67,9 @@ test:
2367
clean:
2468
rm -rf .rocks
2569

26-
.PHONY: build
27-
build:
70+
.PHONY: dev-build
71+
dev-build:
2872
if [ ! -d ".rocks" ]; then make .rocks; fi
29-
tarantoolctl rocks pack graphql scm-1
73+
tarantoolctl rocks pack graphql scm-1
74+
75+
# }}} Developer tools

graphql-scm-1.rockspec

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package = 'graphql'
22
version = 'scm-1'
33

44
source = {
5-
url = 'git+https://github.com/tarantool/graphql.git'
5+
url = 'git+https://github.com/tarantool/graphql.git',
6+
branch = 'master',
67
}
78

89
description = {
@@ -18,17 +19,11 @@ dependencies = {
1819
}
1920

2021
build = {
21-
type = 'builtin',
22-
modules = {
23-
['graphql.execute'] = 'graphql/execute.lua',
24-
['graphql.introspection'] = 'graphql/introspection.lua',
25-
['graphql.parse'] = 'graphql/parse.lua',
26-
['graphql.query_util'] = 'graphql/query_util.lua',
27-
['graphql.rules'] = 'graphql/rules.lua',
28-
['graphql.schema'] = 'graphql/schema.lua',
29-
['graphql.types'] = 'graphql/types.lua',
30-
['graphql.util'] = 'graphql/util.lua',
31-
['graphql.validate'] = 'graphql/validate.lua',
32-
['graphql.validate_variables'] = 'graphql/validate_variables.lua',
33-
}
22+
type = 'make',
23+
variables = {
24+
-- Support unusual tarantool location.
25+
--
26+
-- https://github.com/tarantool/modulekit/issues/2
27+
TARANTOOL_INSTALL_LUADIR='$(LUADIR)',
28+
},
3429
}

graphql/init.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- The VERSION.lua file is generated at two points:
2+
--
3+
-- 1. At generating the .all.rock file.
4+
-- 2. At installation from the rockspec.
5+
--
6+
-- As result it should exist in a user installation.
7+
--
8+
-- However we require it conditionally to allow to use directly
9+
-- from the repository clone. It is convenient for developers of
10+
-- the module.
11+
local ok, VERSION = pcall(require, 'graphql.VERSION')
12+
13+
if not ok then
14+
VERSION = 'unknown'
15+
end
16+
17+
return {
18+
VERSION = VERSION,
19+
}

0 commit comments

Comments
 (0)