Skip to content

Commit

Permalink
Setup CI build on travis-ci.org
Browse files Browse the repository at this point in the history
Setup Travis CI for continuous testing and integration of the project
  • Loading branch information
jgebal authored and javornikolov committed May 11, 2016
1 parent 17b02d2 commit 777a60f
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 2 deletions.
38 changes: 38 additions & 0 deletions .travis.yml
@@ -0,0 +1,38 @@
sudo: required

env:
global:
- ORACLE_COOKIE=sqldev
- ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
- NLS_LANG=AMERICAN_AMERICA.AL32UTF8
- ORACLE_BASE=/u01/app/oracle
- LD_LIBRARY_PATH=$ORACLE_HOME/lib
- PATH=$PATH:$ORACLE_HOME/jdbc/lib
- DATABASE_VERSION=11.2.0.2
- ORACLE_SID=XE
- DATABASE_NAME=XE
# - JRUBY_OPTS='--ng'
- ORA_SDTZ='Europe/London' #Needed as a client parameter
- TZ='Europe/London' #Needed as a DB Server parameter

before_install:
- chmod +x .travis/oracle/download.sh
- chmod +x .travis/oracle/install.sh
- chmod +x .travis/setup_accounts.sh

install:
- .travis/oracle/download.sh
- .travis/oracle/install.sh
- .travis/setup_accounts.sh
- bundle install

language: ruby
rvm:
- 2.3.1
- 2.3.0
- 2.2.4
- 1.9.3
- jruby-1.7.9
- jruby-9.0.5.0
- jruby-9.1.0.0
5 changes: 5 additions & 0 deletions .travis/oracle/LICENSE
@@ -0,0 +1,5 @@
Copyright (c) 2013, Christopher Bandy

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
64 changes: 64 additions & 0 deletions .travis/oracle/README.md
@@ -0,0 +1,64 @@
[![Build](https://travis-ci.org/cbandy/travis-oracle.svg?branch=master)](https://travis-ci.org/cbandy/travis-oracle)

Use [Oracle Database Express Edition][] in your builds on [Travis CI][].

[Oracle Database Express Edition]: http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html
[Travis CI]: https://travis-ci.org/


Usage
-----

To use this tool, you must have an Oracle account with which you have accepted
the current license agreement for [Oracle Database Express Edition][].

1. Add your Oracle username and password to your build [environment variables][],
either as hidden repository settings or encrypted variables:

| Variable Name | Value |
| -------------------------- | ------------- |
| `ORACLE_LOGIN_ssousername` | your username |
| `ORACLE_LOGIN_password` | your password |

2. Add the version information to your build environment variables:

```yaml
- ORACLE_COOKIE=sqldev
- ORACLE_FILE=oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
- ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
- ORACLE_SID=XE
```

3. Download and extract the [latest release][] into your project. For example,

```shell
wget 'https://github.com/cbandy/travis-oracle/archive/v2.0.0.tar.gz'
mkdir -p .travis/oracle
tar xz --strip-components 1 -C .travis/oracle -f v2.0.0.tar.gz
```

4. Enable [`sudo`](https://docs.travis-ci.com/user/workers/standard-infrastructure/):

```yaml
sudo: required
```

5. Finally, execute the extracted scripts as part of your build, usually
during [`before_install`](https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle):

```yaml
- .travis/oracle/download.sh
- .travis/oracle/install.sh
```

[SQL\*Plus][] is installed to `$ORACLE_HOME/bin/sqlplus`, and the current user
has both normal and DBA access without a password, i.e. `/` and `/ AS SYSDBA`.

[OCI][] and [OCCI][] libraries and header files are in `$ORACLE_HOME/lib` and
`$ORACLE_HOME/rdbms/public`, respectively.

[environment variables]: https://docs.travis-ci.com/user/environment-variables/
[latest release]: https://github.com/cbandy/travis-oracle/releases/latest
[OCCI]: http://www.oracle.com/pls/topic/lookup?ctx=xe112&id=LNCPP
[OCI]: http://www.oracle.com/pls/topic/lookup?ctx=xe112&id=LNOCI
[SQL\*Plus]: http://www.oracle.com/pls/topic/lookup?ctx=xe112&id=SQPUG
100 changes: 100 additions & 0 deletions .travis/oracle/download.js
@@ -0,0 +1,100 @@
// vim: set et sw=2 ts=2:
"use strict";
var env = process.env;
var Promise = require('bluebird');
var Phantom = Promise.promisifyAll(require('node-phantom-simple'));
var PhantomError = require('node-phantom-simple/headless_error');

Phantom.createAsync({ parameters: { 'ssl-protocol': 'tlsv1' } }).then(function (browser) {
browser = Promise.promisifyAll(browser, { suffix: 'Promise' });

// Configure the browser, open a tab
return browser
.addCookiePromise({'name': 'oraclelicense', 'value': "accept-" + env['ORACLE_COOKIE'] + "-cookie", 'domain': '.oracle.com' })
.then(function () {
return browser.createPagePromise();
})
.then(function (page) {
page = Promise.promisifyAll(page, { suffix: 'Promise' });

// Configure the tab
page.onResourceError = console.error.bind(console);
return page
.setPromise('settings.userAgent', env['USER_AGENT']) // PhantomJS configures the UA per tab

// Request the file, wait for the login page
.then(function () {
return page.openPromise("https://edelivery.oracle.com/akam/otn/linux/" + env['ORACLE_FILE']).then(function (status) {
if (status != 'success') throw "Unable to connect to oracle.com";
return page.waitForSelectorPromise('input[type=password]', 5000);
})
.catch(PhantomError, function (err) {
return page.getPromise('plainText').then(function (text) {
console.error("Unable to load login page. Last response was:\n" + text);
throw err;
});
});
})

// Export cookies for cURL
.then(function () {
return page.getPromise('cookies').then(function (cookies) {
var data = "";
for (var i = 0; i < cookies.length; ++i) {
var cookie = cookies[i];
data += cookie.domain + "\tTRUE\t" + cookie.path + "\t"
+ (cookie.secure ? "TRUE" : "FALSE") + "\t0\t"
+ cookie.name + "\t" + cookie.value + "\n";
}
return Promise.promisifyAll(require('fs')).writeFileAsync(env['COOKIES'], data);
});
})

// Submit the login form using cURL
.then(function () {
return page.evaluatePromise(function () {
var $form = jQuery(document.forms[0]);
return {
action: $form.prop('action'),
data: $form.serialize()
};
})
.then(function (form) {
return browser.exitPromise().then(function () {
for (var key in env) {
if (key.indexOf('ORACLE_LOGIN_') == 0 && env.hasOwnProperty(key)) {
var name = key.substr(13) + '=';
form.data = form.data.replace(name, name + env[key]);
}
}

var cmd = ['curl', [
'--cookie', env['COOKIES'],
'--cookie-jar', env['COOKIES'],
'--data', '@-',
'--location',
'--output', require('path').basename(env['ORACLE_FILE']),
'--user-agent', env['USER_AGENT'],
form.action
]];

console.info("Executing %j", cmd);

var child_process = require('child_process');
var child = child_process.spawn.apply(child_process, cmd.concat({ stdio: ['pipe', 1, 2] }));
child.on('exit', process.exit);
child.stdin.end(form.data);
});
});
})
.catch(function (err) {
console.error(err);
browser.on('exit', function () { process.exit(1); });
browser.exit();
});
});
})
.catch(function (err) {
console.error(err);
process.exit(1);
});
16 changes: 16 additions & 0 deletions .travis/oracle/download.sh
@@ -0,0 +1,16 @@
#!/bin/sh -e

[ -n "$ORACLE_COOKIE" ] || { echo "Missing ORACLE_COOKIE environment variable!"; exit 1; }
[ -n "$ORACLE_FILE" ] || { echo "Missing ORACLE_FILE environment variable!"; exit 1; }

cd "$(dirname "$(readlink -f "$0")")"

npm install bluebird node-phantom-simple

export COOKIES='cookies.txt'
export USER_AGENT='Mozilla/5.0'

echo > "$COOKIES"
chmod 600 "$COOKIES"

exec node download.js
32 changes: 32 additions & 0 deletions .travis/oracle/install.sh
@@ -0,0 +1,32 @@
#!/bin/sh -e

[ -n "$ORACLE_FILE" ] || { echo "Missing ORACLE_FILE environment variable!"; exit 1; }
[ -n "$ORACLE_HOME" ] || { echo "Missing ORACLE_HOME environment variable!"; exit 1; }

ORACLE_RPM="$(basename $ORACLE_FILE .zip)"

cd "$(dirname "$(readlink -f "$0")")"

sudo apt-get -qq update
sudo apt-get --no-install-recommends -qq install bc libaio1 rpm unzip

df -B1 /dev/shm | awk 'END { if ($1 != "shmfs" && $1 != "tmpfs" || $2 < 2147483648) exit 1 }' ||
( sudo rm -r /dev/shm && sudo mkdir /dev/shm && sudo mount -t tmpfs shmfs -o size=2G /dev/shm )

test -f /sbin/chkconfig ||
( echo '#!/bin/sh' | sudo tee /sbin/chkconfig > /dev/null && sudo chmod u+x /sbin/chkconfig )

test -d /var/lock/subsys || sudo mkdir /var/lock/subsys

unzip -j "$(basename $ORACLE_FILE)" "*/$ORACLE_RPM"
sudo rpm --install --nodeps --nopre "$ORACLE_RPM"

echo 'OS_AUTHENT_PREFIX=""' | sudo tee -a "$ORACLE_HOME/config/scripts/init.ora" > /dev/null
sudo usermod -aG dba $USER

( echo ; echo ; echo travis ; echo travis ; echo n ) | sudo AWK='/usr/bin/awk' /etc/init.d/oracle-xe configure

"$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA <<SQL
CREATE USER $USER IDENTIFIED EXTERNALLY;
GRANT CONNECT, RESOURCE TO $USER;
SQL
7 changes: 7 additions & 0 deletions .travis/setup_accounts.sh
@@ -0,0 +1,7 @@
#!/bin/bash

set -ev

"$ORACLE_HOME/bin/sqlplus" -L -S / AS SYSDBA <<SQL
@@spec/support/unlock_and_setup_hr_user.sql
SQL
10 changes: 8 additions & 2 deletions Gemfile
Expand Up @@ -9,7 +9,13 @@ gem 'nokogiri', '~> 1.6.0'
group :development do
gem 'jeweler', '~> 2.0.1'

# gem 'ruby-oci8', '~> 2.1.0'
gem 'ruby-oci8', :git => 'git://github.com/kubo/ruby-oci8.git', :platforms => :mri
platforms :ruby, :mswin, :mingw do
gem 'ruby-oci8', '~> 2.1'
end
# gem 'ruby-oci8', :git => 'git://github.com/kubo/ruby-oci8.git', :platforms => :mri
gem 'rspec_junit_formatter'
end

group :test do
gem 'rake', '>= 10.0'
end
2 changes: 2 additions & 0 deletions README.md
@@ -1,3 +1,5 @@
[![Build Status](https://travis-ci.org/rsim/ruby-plsql-spec.svg?branch=master)](https://travis-ci.org/rsim/ruby-plsql-spec)

ruby-plsql-spec
===============
PL/SQL unit testing with Ruby
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -35,6 +35,7 @@ RSpec::Core::RakeTask.new(:rcov) do |t|
end

task :default => :spec
task :test => :spec

require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
Expand Down
2 changes: 2 additions & 0 deletions spec/support/unlock_and_setup_hr_user.sql
@@ -0,0 +1,2 @@
alter user hr identified by hr account unlock;
grant execute on dbms_lock to hr;

0 comments on commit 777a60f

Please sign in to comment.