Skip to content

Commit

Permalink
repository: prepare for development
Browse files Browse the repository at this point in the history
Added CI with test + linter.
Added CI to publish a rock.
Added dummy tests.
Added dummy role file.
Added Makefile.
Added rockspec.

Closes #4
  • Loading branch information
better0fdead committed Jul 5, 2024
1 parent 459ab9a commit c940f9a
Show file tree
Hide file tree
Showing 13 changed files with 863 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: publish

on:
push:
branches: [master]
tags: ['*']

jobs:
version-check:
# We need this job to run only on push with tag.
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-22.04
steps:
- name: Check module version
uses: tarantool/actions/check-module-version@master
with:
module-name: 'metrics-export-role'

publish-rockspec-scm-1:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: tarantool/rocks.tarantool.org/github-action@master
with:
auth: ${{ secrets.ROCKS_AUTH }}
files: metrics-export-role-scm-1.rockspec

publish-rockspec-tag:
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
needs: version-check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

# Create a rockspec for the release.
- run: printf '%s=%s\n' TAG "${GITHUB_REF##*/}" >> "${GITHUB_ENV}"
- run: sed -E
-e 's/branch = ".+"/tag = "${{ env.TAG }}"/g'
-e 's/version = ".+"/version = "${{ env.TAG }}-1"/g'
metrics-export-role-scm-1.rockspec > metrics-export-role-${{ env.TAG }}-1.rockspec

- name: Setup tt
run: |
curl -L https://tarantool.io/XodVosJ/release/3/installer.sh | bash
sudo apt install -y tt
tt version
# Create a rock for the release (.all.rock).
#
# `tt rocks pack <module_name> <version>` creates
# .all.rock tarball. It speeds up
# `tt rocks install <module_name> <version>` and
# frees it from dependency on git.
#
# Don't confuse this command with
# `tt rocks pack <rockspec>`, which creates a
# source tarball (.src.rock).
#
# Important: Don't upload binary rocks to
# rocks.tarantool.org. Lua/C modules should be packed into
# .src.rock instead. See [1] for description of rock types.
#
# [1]: https://github.com/luarocks/luarocks/wiki/Types-of-rocks
- uses: tarantool/setup-tarantool@v3
with:
tarantool-version: '3.1'
- run: tt rocks install metrics-export-role-${{ env.TAG }}-1.rockspec
- run: tt rocks pack metrics-export-role ${{ env.TAG }}

# Upload .rockspec and .all.rock.
- uses: tarantool/rocks.tarantool.org/github-action@master
with:
auth: ${{ secrets.ROCKS_AUTH }}
files: |
metrics-export-role-${{ env.TAG }}-1.rockspec
metrics-export-role-${{ env.TAG }}-1.all.rock
106 changes: 106 additions & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: testing

on:
push:
pull_request:
workflow_dispatch:

jobs:
linux:
# We want to run on external PRs, but not on our own internal
# PRs as they'll be run by the push to the branch.
#
# The main trick is described here:
# https://github.com/Dart-Code/Dart-Code/pull/2375
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

strategy:
fail-fast: false
matrix:
tarantool:
- 'debug-master'
- '3.1'

env:
TNT_DEBUG_PATH: /home/runner/tnt-debug

runs-on: ubuntu-22.04
steps:
- name: Install tarantool ${{ matrix.tarantool }}
if: startsWith(matrix.tarantool, 'debug') != true
uses: tarantool/setup-tarantool@v3
with:
tarantool-version: ${{ matrix.tarantool }}

- name: Create variables for Tarantool ${{ matrix.tarantool }}
if: startsWith(matrix.tarantool, 'debug')
run: |
branch=$(echo ${{ matrix.tarantool }} | cut -d- -f2)
commit_hash=$(git ls-remote https://github.com/tarantool/tarantool.git --branch ${branch} | head -c 8)
echo "TNT_BRANCH=${branch}" >> $GITHUB_ENV
echo "VERSION_POSTFIX=-${commit_hash}" >> $GITHUB_ENV
shell: bash

- name: Cache tarantool build
if: startsWith(matrix.tarantool, 'debug')
id: cache-tnt-debug
uses: actions/cache@v3
with:
path: ${{ env.TNT_DEBUG_PATH }}
key: cache-tnt-${{ matrix.tarantool }}${{ env.VERSION_POSTFIX }}

- name: Clone tarantool ${{ matrix.tarantool }}
if: startsWith(matrix.tarantool, 'debug') && steps.cache-tnt-debug.outputs.cache-hit != 'true'
uses: actions/checkout@v3
with:
repository: tarantool/tarantool
ref: ${{ env.TNT_BRANCH }}
path: tarantool
fetch-depth: 0
submodules: true

- name: Build tarantool ${{ matrix.tarantool }}
if: startsWith(matrix.tarantool, 'debug') && steps.cache-tnt-debug.outputs.cache-hit != 'true'
run: |
sudo apt-get -y install git build-essential cmake make zlib1g-dev \
libreadline-dev libncurses5-dev libssl-dev \
libunwind-dev libicu-dev python3 python3-yaml \
python3-six python3-gevent
cd ${GITHUB_WORKSPACE}/tarantool
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_DIST=ON
make
make DESTDIR=${TNT_DEBUG_PATH} install
- name: Install tarantool ${{ matrix.tarantool }}
if: startsWith(matrix.tarantool, 'debug')
run: |
sudo cp -rvP ${TNT_DEBUG_PATH}/usr/local/* /usr/local/
- name: Clone the module
uses: actions/checkout@v3

- name: Cache rocks
uses: actions/cache@v3
id: cache-rocks
with:
path: .rocks/
key: "cache-rocks-${{ matrix.tarantool }}${{ env.VERSION_POSTFIX }}-\
${{ matrix.cartridge-version }}-\
${{ matrix.metrics-version }}"

- name: Setup tt
run: |
curl -L https://tarantool.io/XodVosJ/release/3/installer.sh | bash
sudo apt install -y tt
tt version
- name: Install requirements
run: make deps
if: steps.cache-rocks.outputs.cache-hit != 'true'

- run: echo $PWD/.rocks/bin >> $GITHUB_PATH

- run: make check

- run: make test
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*~
*.snap
*.xlog
*.log
VERSION
luacov.stats.out
luacov.report.out
tags
.rocks
doc/apidoc/
.idea
*.swp
19 changes: 19 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
globals = {
"box",
"_TARANTOOL",
}

ignore = {
-- Shadowing an upvalue argument.
"432",
}

include_files = {
'.luacheckrc',
'*.rockspec',
'**/*.lua',
}

exclude_files = {
'.rocks',
}
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This way everything works as expected ever for
# `make -C /path/to/project` or
# `make -f /path/to/project/Makefile`.
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJECT_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))

SHELL := $(shell which bash)
SEED ?= $(shell /bin/bash -c "echo $$RANDOM")

all: test

check: luacheck

luacheck:
luacheck --config .luacheckrc --codes .

.PHONY: test
test:
luatest -v --shuffle all:${SEED}

deps:
tt rocks install luatest 1.0.1
tt rocks install luacheck 0.26.0
tt rocks make
22 changes: 22 additions & 0 deletions metrics-export-role-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package = "metrics-export-role"
version = "scm-1"
source = {
url = "git+https://github.com/tarantool/metrics-export-role",
branch = "master",
}
description = {
summary = "The Tarantool 3 role for metrics export via HTTP",
homepage = "https://github.com/tarantool/metrics-export-role",
license = "BSD2",
maintainer = "Fedor Terekhin <[email protected]>"
}
dependencies = {
"lua >= 5.1",
}
build = {
type = "builtin",
modules = {
["roles.metrics-export"] = "roles/metrics-export.lua"
}
}
-- vim: syntax=lua
17 changes: 17 additions & 0 deletions roles/metrics-export.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local function validate()

end

local function apply()

end

local function stop()

end

return {
validate = validate,
apply = apply,
stop = stop,
}
Loading

0 comments on commit c940f9a

Please sign in to comment.