Skip to content

Commit

Permalink
chore(ci) switch to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Feb 2, 2023
1 parent 1b1fe8b commit bf58830
Show file tree
Hide file tree
Showing 15 changed files with 158 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
return {
default = {
--helper = "spec/configure-log.lua",
verbose = true,
coverage = false,
output = "gtest",
},
}
38 changes: 38 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint

concurrency:
# for PR's cancel the running task, if another commit is pushed
group: ${{ github.workflow }} ${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

on:
# build on PR and push-to-main. This works for short-lived branches, and saves
# CPU cycles on duplicated tests.
# For long-lived branches that diverge, you'll want to run on all pushes, not
# just on push-to-main.
pull_request: {}
push:
branches:
- main


jobs:
lint:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- uses: leafo/gh-actions-lua@v8
with:
luaVersion: "5.4"

- uses: leafo/gh-actions-luarocks@v4

- name: dependencies
run: |
luarocks install luacheck
- name: lint
run: |
make check
55 changes: 55 additions & 0 deletions .github/workflows/unix_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Unix build"

concurrency:
# for PR's cancel the running task, if another commit is pushed
group: ${{ github.workflow }} ${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

on:
# build on PR and push-to-main. This works for short-lived branches, and saves
# CPU cycles on duplicated tests.
# For long-lived branches that diverge, you'll want to run on all pushes, not
# just on push-to-main.
pull_request: {}
push:
branches:
- main


jobs:
test:
runs-on: ubuntu-20.04

strategy:
fail-fast: false
matrix:
luaVersion: ["5.1", "5.2", "5.3", "5.4", "luajit-2.1.0-beta3", "luajit-openresty"]

steps:
- name: Checkout
uses: actions/checkout@v3

- uses: leafo/gh-actions-lua@v8
with:
luaVersion: ${{ matrix.luaVersion }}

- uses: leafo/gh-actions-luarocks@v4

- name: dependencies
run: |
make install
luarocks install luacov-coveralls
luarocks install busted
make start_app
- name: test
run: |
busted --coverage
make kill_server
- name: Report test coverage
if: success()
continue-on-error: true
run: luacov-coveralls
env:
COVERALLS_REPO_TOKEN: ${{ github.token }}
32 changes: 32 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
unused_args = false
redefined = false
max_line_length = false

globals = {
-- "ngx",
}

not_globals = {
-- deprecated Lua 5.0 functions
"string.len",
"table.getn",
}

include_files = {
"**/*.lua",
"**/*.rockspec",
".busted",
".luacheckrc",
}

files["spec/**/*.lua"] = {
std = "+busted",
}

exclude_files = {
-- The Github Actions Lua Environment
".lua",
".luarocks",
".install",
}

5 changes: 5 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
modules = {
["homie45.*"] = "src"
}

runreport = true
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.SILENT:

START_APP=test/start_app.lua
START_APP=spec/start_app.lua

.PHONY: run_example
run_example:
Expand All @@ -11,19 +11,19 @@ test: unit_test integration_test

.PHONY: unit_test
unit_test:
busted test/unit/
busted spec/unit/

.PHONY: check
check:
luacheck src/pegasus
luacheck .

.PHONY: start_app
start_app:
lua $(START_APP) &

.PHONY: _integration_test
_integration_test:
busted test/integration/
busted spec/integration/

.PHONY: kill_server
kill_server:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ describe('integration', function()
local url = 'http://localhost:' .. port

local executeCommand = function(command)
local handle = io.popen(command .. ' -s ' .. url)
local result = handle:read('*a')
local handle = assert(io.popen(command .. ' -s ' .. url))
local result = assert(handle:read('*a'))
handle:close()

return result
Expand All @@ -13,12 +13,12 @@ describe('integration', function()
it('should return correct headers', function()
local result = executeCommand('curl --head')

assert.truthy(string.find(result, 'HTTP/1.1 200 OK'))
assert.truthy(string.find(result, 'Content%-Type: text/html'))
assert.truthy(string.find(result, 'Content%-Length: 16'))
assert.match('HTTP/1%.1 200 OK', result)
assert.match('Content%-Type: text/html', result)
assert.match('Content%-Length: 16', result)
end)

it('should return correct body', function()
assert.truthy(string.find(executeCommand('curl'), 'Hello, Pegasus'))
assert.match('Hello, Pegasus', executeCommand('curl'))
end)
end)
2 changes: 1 addition & 1 deletion test/start_app.lua → spec/start_app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local Pegasus = require 'pegasus'

local server = Pegasus:new({
port='7070',
location='/test/fixtures/'
location='/spec/fixtures/'
})

server:start()
6 changes: 3 additions & 3 deletions test/unit/compress_spec.lua → spec/unit/compress_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ describe('compress #compress', function()
local value = nil

local response = {
addHeader = function(obj, _key, _value)
key = _key
value = _value
addHeader = function(obj, k, v)
key = k
value = v
end
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/pegasus_spec.lua → spec/unit/pegasus_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('pegasus', function()
end)

it('should receive a location as plugins', function()
plugins = {}
local plugins = {}
local server = Pegasus:new { port = '8080', location = 'mimi/', plugins = plugins }
assert.equal(plugins, server.plugins)
end)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/request_spec.lua → spec/unit/request_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local Request = require 'pegasus.request'

function getInstance(headers)
local function getInstance(headers)
local position = 1
local client = {
receive = function()
Expand Down Expand Up @@ -32,7 +32,7 @@ function getInstance(headers)
return Request:new(8080, client, server)
end

function verifyHttpMethod(method)
local function verifyHttpMethod(method)
local headers = { method .. ' /index.html HTTP/1.1', '' }
local request = getInstance(headers)
local result = request:method()
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('require', function()
test('find value with = signal', function()
local headers = { 'GET /Makefile?a=b= HTTP/1.1', 'a: A=', '' }
local request = getInstance(headers)
local result = request:headers()
local _ = request:headers()

assert.are.same(
request:headers(),
Expand All @@ -105,11 +105,11 @@ describe('require', function()
end)

it('should not crash on invalid first line', function()
local request, result
local request, _
assert.not_error(function()
local headers = { 'garbage', nil }
request = getInstance(headers)
result = request:headers()
_ = request:headers()
end)

assert.is_nil(request:method())
Expand Down
File renamed without changes.

0 comments on commit bf58830

Please sign in to comment.