Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ci: add github ci to run tests #8

Merged
merged 2 commits into from
Jan 12, 2025
Merged
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
82 changes: 82 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test 🧪

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
test:
name: Test and check ️✅
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- lua-type: "lua"
lua-version: "5.1"
- lua-type: "lua"
lua-version: "5.2"
- lua-type: "lua"
lua-version: "5.3"
- lua-type: "lua"
lua-version: "5.4"
- lua-type: "luajit"
luajit-version: "2.0"
- lua-type: "luajit"
luajit-version: "2.1"

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Create and activate virtual environment
run: |
python -m venv venv
source venv/bin/activate
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH

- name: Install hererocks
run: pip install hererocks

- name: Setup Lua
run: |
mkdir -p lua_install
if [[ "${{ matrix.lua-type }}" == "lua" ]]; then
hererocks lua_install -r^ --lua=${{ matrix.lua-version }}
else
hererocks lua_install -r^ --luajit=${{ matrix.luajit-version }}
fi
echo "$PWD/lua_install/bin" >> $GITHUB_PATH

- name: Install dependencies
run: |
luarocks install luacheck
luarocks install busted
luarocks install luacov

- name: Run tests and checks
run: |
luacheck --no-unused-args --std max+busted smiti18n spec
busted --verbose --coverage

- name: Generate and show coverage report
run: |
luacov
{
if [[ "${{ matrix.lua-type }}" == "lua" ]]; then
echo "# Test Coverage Summary - Lua ${{ matrix.lua-version }}"
else
echo "# Test Coverage Summary - LuaJIT ${{ matrix.luajit-version }}"
fi
echo ""
echo "| File | Hits | Missed | Coverage |"
echo "|------|------|---------|----------|"
grep "^smiti18n/.*[0-9]" luacov.report.out | sort -u | sed -E 's/^([^|]+[^ ])[[:space:]]+([0-9]+)[[:space:]]+([0-9]+)[[:space:]]+([0-9.]+)%[[:space:]]*$/| \1 | \2 | \3 | \4% |/'
} >> $GITHUB_STEP_SUMMARY
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release 🏷️

on:
push:
tags:
- "v?[0-9]+.[0-9]+.[0-9]+*"
workflow_dispatch:
inputs:
tag:
description: "The existing tag to publish"
type: "string"
required: true

jobs:
publish-release:
name: "Publish Release 📤️"
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Publish release ${{ github.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ github.ref }}" --draft --generate-notes
if [ "$(gh release view "${{ github.ref }}" --json assets --template '{{len .assets}}')" -eq 0 ]; then
exit 1
fi
gh release edit "${{ github.ref }}" --draft=false
10 changes: 10 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
return {
include = {
'smiti18n/',
'spec/'
},
exclude = {
'lua_install',
'.luarocks'
}
}
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

19 changes: 10 additions & 9 deletions smiti18n/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local unpack = unpack or table.unpack -- lua 5.2 compat
local i18n = {}

local store
Expand Down Expand Up @@ -67,17 +68,17 @@ local function assertFunctionOrNil(functionName, paramName, value)
error(msg:format(functionName, paramName, tostring(value), type(value)))
end

local function defaultPluralizeFunction(locale, count)
if not locale then
locale = i18n.getLocale()
if type(locale) == "table" then
locale = locale[1]
local function defaultPluralizeFunction(loc, count)
if not loc then
loc = i18n.getLocale()
if type(loc) == "table" then
loc = loc[1]
end
end
return plural.get(variants.root(locale), count)
return plural.get(variants.root(loc), count)
end

local function pluralize(t, locale, data)
local function pluralize(t, loc, data)
assertPresentOrPlural('interpolatePluralTable', 't', t)
data = data or {}
local key
Expand All @@ -92,7 +93,7 @@ local function pluralize(t, locale, data)
if customPluralizeFunction then
plural_form = customPluralizeFunction(count)
else
plural_form = defaultPluralizeFunction(locale, count)
plural_form = defaultPluralizeFunction(loc, count)
end
return t[plural_form]
end
Expand All @@ -102,7 +103,7 @@ local function treatNode(node, loc, data)
local iter = {ipairs(node)}
node = {}
for k,v in unpack(iter) do
node[k] = treatNode(v, data)
node[k] = treatNode(v, loc, data)
end
elseif type(node) == 'string' then
return interpolate(node, data)
Expand Down
7 changes: 0 additions & 7 deletions smiti18n/variants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ local function reverse(arr, length)
return result, length
end

local function concat(arr1, len1, arr2, len2)
for i = 1, len2 do
arr1[len1 + i] = arr2[i]
end
return arr1, len1 + len2
end

function variants.ancestry(locale)
local result, length, accum = {},0,nil
locale:gsub("[^%-]+", function(c)
Expand Down