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 36463df
Show file tree
Hide file tree
Showing 13 changed files with 972 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/fast_testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: fast_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'

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

runs-on: ubuntu-20.04
steps:
- name: Install tarantool ${{ matrix.tarantool }}
if: startsWith(matrix.tarantool, 'debug') != true
uses: tarantool/setup-tarantool@v1
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/release/2/installer.sh | sudo 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
103 changes: 103 additions & 0 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: packaging

on:
pull_request:
workflow_dispatch:
push:
branches:
- 'master'
tags:
- '*'

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

package:
runs-on: ubuntu-20.04
needs: version-check

strategy:
fail-fast: false
matrix:
platform:
- { os: 'debian', dist: 'stretch' }
- { os: 'debian', dist: 'buster' }
- { os: 'debian', dist: 'bullseye' }
- { os: 'el', dist: '7' }
- { os: 'el', dist: '8' }
- { os: 'fedora', dist: '30' }
- { os: 'fedora', dist: '31' }
- { os: 'fedora', dist: '32' }
- { os: 'fedora', dist: '33' }
- { os: 'fedora', dist: '34' }
- { os: 'fedora', dist: '35' }
- { os: 'fedora', dist: '36' }
- { os: 'ubuntu', dist: 'xenial' }
- { os: 'ubuntu', dist: 'bionic' }
- { os: 'ubuntu', dist: 'focal' }
- { os: 'ubuntu', dist: 'groovy' }
- { os: 'ubuntu', dist: 'jammy' }

env:
OS: ${{ matrix.platform.os }}
DIST: ${{ matrix.platform.dist }}

steps:
- name: Clone the module
uses: actions/checkout@v3
# `actions/checkout` performs shallow clone of repo. To provide
# proper version of the package to `packpack` we need to have
# complete repository, otherwise it will be `0.0.1`.
with:
fetch-depth: 0

- name: Clone the packpack tool
uses: actions/checkout@v3
with:
repository: packpack/packpack
path: packpack

- name: Fetch tags
# Found that Github checkout Actions pulls all the tags, but
# right it deannotates the testing tag, check:
# https://github.com/actions/checkout/issues/290
# But we use 'git describe ..' calls w/o '--tags' flag and it
# prevents us from getting the needed tag for packages version
# setup. To avoid of it, let's fetch it manually, to be sure
# that all tags will exist always.
run: git fetch --tags -f

- name: Create packages
run: ./packpack/packpack

- name: Deploy packages
# We need this step to run only on push with tag.
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
env:
RWS_URL_PART: https://rws.tarantool.org/tarantool-modules
RWS_AUTH: ${{ secrets.RWS_AUTH }}
PRODUCT_NAME: tarantool-metrics-export-role
working-directory: build
run: |
CURL_CMD="curl -LfsS \
-X PUT ${RWS_URL_PART}/${OS}/${DIST} \
-u ${RWS_AUTH} \
-F product=${PRODUCT_NAME}"
shopt -s nullglob
for f in *.deb *.rpm *.dsc *.tar.xz *.tar.gz; do
CURL_CMD+=" -F $(basename ${f})=@${f}"
done
echo ${CURL_CMD}
${CURL_CMD}
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-20.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-20.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-20.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/release/2/installer.sh | sudo 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@v1
with:
tarantool-version: '1.10'
- 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
39 changes: 39 additions & 0 deletions .github/workflows/reusable_testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: reusable_testing

on:
workflow_call:
inputs:
artifact_name:
description: The name of the Tarantool build artifact
default: ubuntu-focal
required: false
type: string

jobs:
run_tests:
runs-on: ubuntu-20.04
steps:
- name: Clone the metrics-export-role module
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/metrics-export-role

- name: Download the Tarantool build artifact
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact_name }}

- name: Install Tarantool
# Now we're lucky: all dependencies are already installed. Check package
# dependencies when migrating to other OS version.
run: sudo dpkg -i tarantool_*.deb tarantool-common_*.deb tarantool-dev_*.deb

- name: Setup tt
run: |
curl -L https://tarantool.io/release/2/installer.sh | sudo bash
sudo apt install -y tt
tt version
- run: make deps
- run: echo $PWD/.rocks/bin >> $GITHUB_PATH
- run: make test
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 --coverage --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 36463df

Please sign in to comment.