Skip to content

Commit

Permalink
Merge pull request #2 from castlele/infra-support-ci-on-every-os
Browse files Browse the repository at this point in the history
[infra]: with linux also support windows and macos in pipelines
  • Loading branch information
castlele authored Dec 27, 2024
2 parents 9993bbe + 87c8ee0 commit e15e438
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 17 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,55 @@ on:
branches: [ "master" ]

jobs:
test:
runs-on: ubuntu-latest
unit-tests:
strategy:
fail-fast: false
matrix:
os:
# TODO: Add windows support later
# Will be added later: waiting added support in: https://github.com/leafo/gh-actions-luarocks/pull/14
# - windows-latest
- ubuntu-latest
- macos-latest
- macos-13
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@master

- uses: leafo/gh-actions-lua@v10
- uses: ilammy/msvc-dev-cmd@v1

- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: "5.1.5"
buildCache: false

- uses: leafo/gh-actions-luarocks@v4
- uses: luarocks/gh-actions-luarocks@v5
with:
luarocksVersion: "3.0.0"

- name: build
- name: test
run: |
luarocks make
./run_tests.sh "*"
deploy:
runs-on: ubuntu-latest
needs: test
needs: unit-tests
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@master

- uses: leafo/gh-actions-lua@v10
- uses: ilammy/msvc-dev-cmd@v1

- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: "5.1.5"
buildCache: false

- uses: leafo/gh-actions-luarocks@v4
- uses: luarocks/gh-actions-luarocks@v5
with:
luarocksVersion: "3.0.0"

- name: publish-luarocks
env:
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ check_report.txt
.cache/
**/*.o
**/*.so
cluautils/*
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
OSNAME=$(shell uname)

CC=clang
CFLAGS=-arch arm64
ARCHIVE_CFLAGS=-shared -fPIC $(CFLAGS)
Expand All @@ -20,14 +22,24 @@ THREAD_BINARY=thread.so
MEMORY_CFILES=$(MEMORY_SRC)/memory.c
MEMORY_BINARY=memory.so


THREAD_LIBS=-L./$(THREAD_BIN)/ -lcthread
THREAD_LIBS=
TEST_SRC=tests/cthread_internal_tests.c
TEST_BINARY=tests

# TODO: Update paths somehow
LIBS=-llua -ldl -lm -I/Users/castlelecs/.luaver/lua/5.1/include/ -L/Users/castlelecs/.luaver/lua/5.1/lib/

ifeq ($(OSNAME), Darwin)
THREAD_LIBS=-L./$(THREAD_BIN)/ -lcthread
endif

ifeq ($(OSNAME), Linux)
THREAD_LIBS=-L./$(THREAD_BIN)/ -lcthread -pthread
endif


build: build_thread build_memory
test: test_thread

test_thread: compile_thread
clear
Expand Down
4 changes: 4 additions & 0 deletions build.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---@diagnostic disable-next-line
conf = {
install = "luarocks make",
allTest = [[
./run_tests.sh "*"
]],
threadTest = [[
bear -- make build
make test_thread
Expand Down
11 changes: 8 additions & 3 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

tests_dir=./tests
FILTER=$1
IS_ANY_ERROR=0

for test_file in $tests_dir/${FILTER}.lua; do
echo -e "\033[35mRunning tests for $test_file\033[0m"

lua $test_file

echo -e "\033[35mTests finished for $test_file\033[0m"
if [[ $? -ne 0 ]]; then
IS_ANY_ERROR=1
fi
done

if [[ $IS_ANY_ERROR -ne 0 ]]; then
exit -1
fi
11 changes: 9 additions & 2 deletions src/tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ tests.describe = function(label, func)
print(colorString(colorTable.YELLOW, "Test cases: " .. wrapWith(label, "'")))
func()

local isAnyFailed = false

for _, value in pairs(currentResults) do
if not value then
isAnyFailed = true
print(colorString(colorTable.RED, "Test cases failed: " .. wrapWith(label, "'")))
return
end
end
print(colorString(colorTable.YELLOW, "Test cases succeeded: " .. wrapWith(label, "'")))

if isAnyFailed then
os.exit(-1)
end

print(colorString(colorTable.YELLOW, "Test cases succeeded: " .. wrapWith(label, "'")))
end

tests.it = function(name, func)
Expand Down
9 changes: 8 additions & 1 deletion tests/cmemory_tests.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
local t = require("src.tests")
local memory = assert(package.loadlib("./src/memory/bin/memory.so", "_luaopen_cluautils_memory"))()
local localMemoryPackage = package.loadlib("./src/memory/bin/memory.so", "_luaopen_cluautils_memory")
local memory

if not localMemoryPackage then
memory = require("cluautils.memory")
else
memory = localMemoryPackage()
end

t.describe("Memory module tests", function ()
t.it("Memory module gets address of the table", function ()
Expand Down
9 changes: 8 additions & 1 deletion tests/cthread_tests.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require("src.file_manager.file_manager")
local t = require("src.tests")
local thread = assert(package.loadlib("./src/threads/bin/thread.so", "_luaopen_cluautils_thread"))()
local localThreadPackage = package.loadlib("./src/threads/bin/thread.so", "_luaopen_cluautils_thread")
local thread

if not localThreadPackage then
thread = require("cluautils.thread")
else
thread = localThreadPackage()
end

t.describe("Thread Module Tests", function ()
---@param maxValue integer?
Expand Down

0 comments on commit e15e438

Please sign in to comment.