***
https://kikito.github.io/ci-with-lua
***
## I. What, why?
## II. How?
## III. Conclusion
***
# I. What? Why?
***
## Continuous Integration:
> Automated & frequent checks on the code
***
# Automated
***
# Frequent
***
# Checks
***
``` lua
-- spec/numbers_spec.lua
describe('A number', function()
it('Can be added to other number', function()
assert.equal(4, 2+2)
end)
end)
```
***
# Why?
***
***
***
***
***
# II. How?
***
***
| | | |
|---|---|---|
| [![github](./img/github.png) github.com](http://github.com) | [![travis ci](./img/travis-ci.png) travis-ci.org](http://travis-ci.org) | [![coveralls.io](./img/coveralls.png) coveralls.io](http://coveralls.io) |
***
| | | |
|---|---|---|
| [![bitbucket](./img/bitbucket.jpg) bitbucket.org](http://bitbucket.org) | [![Appveyor](./img/appveyor.png) appveyor.com](http://appveyor.com) | [![codecov.io](./img/codecov.png) codecov.io](http://codecov.io) |
***
***
***
## a) Environment
***
![lua](./img/lua.png)
![luajit](./img/luajit.png)
5.1, 5.2, 5.3 / 2.0, 2.1
***
[travis-ci.org](http://travis-ci.org)
[![travis-ci](./img/travis-ci.png)](http://travis-ci.org)
***
`.travis.yml`
***
***
``` yaml
# .travis.yml
language: ruby
rvm:
- '1.9.3'
- 'jruby-18mode' # JRuby in 1.8 mode
- 'jruby-19mode' # JRuby in 1.9 mode
- 'rbx-2.1.1'
- '1.8.7'
- 'ree'
```
***
``` yaml
# .travis.yml
language: C # does not really matter
env:
- LUA=lua5.1
- LUA=lua5.2
- LUA=lua5.3
- LUA=luajit2.0
- LUA=luajit2.1
before_install:
- source install_lua.sh
```
***
``` yaml
# .travis.yml
language: C # does not really matter
env:
- LUA=lua5.1
- LUA=lua5.2
- LUA=lua5.3
- LUA=luajit2.0
- LUA=luajit2.1
before_install:
☞ - source install_lua.sh ☜
```
***
``` sh
# install_lua.sh
if [ "$PLATFORM" == "macosx" ]; then
if [ "$LUA" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.0" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.1" ]; then
LUAJIT="yes";
fi;
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
LUAJIT="yes";
fi
mkdir -p "$LUA_HOME_DIR"
...
```
***
``` yaml
# .travis.yml
language: ruby
rvm:
- '1.9.3'
- 'jruby-18mode' # JRuby in 1.8 mode
- 'jruby-19mode' # JRuby in 1.9 mode
- 'rbx-2.1.1'
- '1.8.7'
- 'ree'
```
***
***
***
https://github.com/mpeterv/hererocks
***
``` yaml
# .travis.yml
language: python
sudo: false
env:
- LUA="lua=5.1"
- LUA="lua=5.2"
- LUA="lua=5.3"
- LUA="luajit=2.0"
- LUA="luajit=2.1"
before_install:
- pip install hererocks
- hererocks lua_install -r^ --$LUA
- export PATH=$PATH:$PWD/lua_install/bin
```
***
## b) Specs
***
[olivinelabs.com/busted](http://olivinelabs.com/busted)
***
``` lua
-- mylib.lua
return {
add = function(a,b) return a+b end
}
```
***
``` lua
-- spec/mylib_spec.lua
local mylib = require 'mylib'
describe('mylib', function()
it('adds numbers', function()
assert.equal(5, mylib.add(2,3))
end)
end)
```
***
***
***
``` yml
# .travis.yml
install:
- luarocks install busted
script:
- busted --verbose
```
***
travis status screen
***
github pr screen
***
github pr screen
***
github pr screen
***
github all prs
***
***
## b) Coverage
***
[coveralls.io](http://coveralls.io)
[![coveralls.io](./img/coveralls.png)](http://coveralls.io)
***
coveralls file view
***
coveralls github integration
***
[keplerproject.github.io/luacov/](https://keplerproject.github.io/luacov/)
***
[github.com/moteus/luacov-coveralls](https://github.com/moteus/luacov-coveralls)
***
``` yaml
# .travis.yml
install:
- luarocks install luacov
- luarocks install luacov-coveralls
...
after_success:
- luacov-coveralls
```
***
``` yaml
# .travis.yml
install:
- luarocks install busted
- luarocks install luacov
- luarocks install luacov-coveralls
script:
- busted --verbose
after_success:
- luacov-coveralls
```
***
``` yaml
# .travis.yml
install:
- luarocks install busted
- luarocks install luacov
- luarocks install luacov-coveralls
script:
- busted --verbose --coverage
after_success:
- luacov-coveralls -e $TRAVIS_BUILD_DIR/lua_install
```
***
## c) Static analysis
***
[github.com/mpeterv/luacheck](https://github.com/mpeterv/luacheck)
***
***
* Global variables
* Read-only globals
* Implicitly defined globals
* Modules
* Unused variables and values
* Unused values and uninitialized variables
* Secondary values and variables
* Shadowing declarations
* Control flow and data flow issues
***
``` yaml
# .travis.yml
install:
- luarocks install luacheck
script:
- luacheck --std max+busted *.lua spec
```
***
## d) All together
***
``` yaml
# .travis.yml
language: python
sudo: false
env:
- LUA="lua=5.1"
- LUA="lua=5.2"
- LUA="lua=5.3"
- LUA="luajit=2.0"
- LUA="luajit=2.1"
before_install:
- pip install hererocks
- hererocks lua_install -r^ --$LUA
- export PATH=$PATH:$PWD/lua_install/bin
```
***
``` yaml
# .travis.yml (cont.)
install:
- luarocks install luacheck
- luarocks install busted
- luarocks install luacov
- luarocks install luacov-coveralls
script:
- luacheck --std max+busted *.lua spec
- busted --verbose --coverage
after_success:
- luacov-coveralls -e $TRAVIS_BUILD_DIR/lua_install
```
***
## e) Alternatives
***
***
### C Extensions
***
```
luarocks make
```
***
``` lua
-- mylib-scm-1.rockspec
package = "mylib"
version = "scm-1"
source = {...}
description = {...}
dependencies = {...}
build = {
type = "command"
build_command = [[
cmake -E make_directory build;
cd build;
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="$(LUA_BINDIR)/.." \
-DCMAKE_INSTALL_PREFIX="$(PREFIX)";
$(MAKE)
]],
install_command = "cd build && $(MAKE) install"
}
```
***
``` yaml
# travis.yml
language: c
compiler:
- gcc
- clang
addons:
apt:
packages:
- cmake
- gcc-multilib
- build-essential
- gcc
- g++
...
script:
- luarocks make
```
***
https://github.com/torch/nngraph/blob/master/.travis.yml
***
***
[appveyor.com](http://appveyor.com)
[![Appveyor](./img/appveyor.png)](http://appveyor.com)
***
## Always be testing
### Ignacio Burgueño
https://www.youtube.com/watch?v=sLFwKeyH2Ug
https://github.com/ignacio/lua-appveyor-example/
***
# III. Conclusion
***
### What, why, how?
***
### What, why, how, should?
***
***
# Questions?
https://kikito.github.io/ci-with-lua
Enrique García Cota ([@otikik](https://twitter.com/otikik))
***
# Thank you!