Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Added integration with Travis-CI deployments and test execution. #230

Open
wants to merge 2 commits into
base: 3.2.0
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ temp/*
.imdone/*
# VSC Task connection string
.vscode/vsc-task-env

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml

## Directory-based project format:
.idea/

118 changes: 118 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
sudo: required

language: java
jdk:
- oraclejdk8

addons:
sonarcloud:
#update this to your org
organization: jgebal-github

env:
global:
# Docker variables:
- DOCKHER_HUB_REPO="${DOCKER_USER}/oracledb"
- ORACLE_VERSION=11g-r2-xe
- CONNECTION_STR='127.0.0.1:1521/XE'
- DOCKER_OPTIONS='--shm-size=1g'

# SYS account password for DB - could be stored in Travis secrets
- ORACLE_SYS_PASS="oracle"
# Adding utPLSQL-cli to path - to be able to invoke "utplsql" from command line
- PATH=$PATH:${TRAVIS_BUILD_DIR}/utPLSQL-cli/bin
# Adding Oracle SQLCL to path - to be able to invoke "sql" from command line
- PATH=$PATH:${TRAVIS_BUILD_DIR}/sqlcl/bin

# Project-specific database variables
# used for creating the user in database, deploying source code and tests as well as executing the tests
- DB_USER=logger_user
- DB_PASS=logger_user_pass
#utPLSQL variables
- UTPLSQL_DIR="utPLSQL"
- CACHE_DIR=$HOME/.cache
# Additionally, you need to set following variables as Travis secrets:
# DOCKER_USER - Your Dockerhub user
# DOCKER_PASSWORD - Your Dockerhub PASS
# ORACLE_OTN_USER - Your Oracle Tech Net user
# ORACLE_OTN_PASSWORD - Your Oracle Tech Net PASS
# DB_SYS_PASSWORD - SYS account password for DB
# SONAR_TOKEN - if you want to use sonarcloud.io for static code analysis and publishing of test results - see https://docs.travis-ci.com/user/sonarcloud/
matrix:
- UTPLSQL_VERSION='develop'
- UTPLSQL_VERSION='v3.1.6'

cache:
pip: true
directories:
- $CACHE_DIR
- node_modules

before_install:
# Download Oracle sqlcl
- .travis/install_sqlcl.sh -u ${ORACLE_OTN_USER} -p ${ORACLE_OTN_PASSWORD} -d ${CACHE_DIR} -o ${TRAVIS_BUILD_DIR}
# Check if Oracle sqlcl it is installed correctly
- sql -v

# download and unzip utPLSQL-cli release
- curl -Lk -o utPLSQL-cli.zip "https://github.com/utPLSQL/utPLSQL-cli/releases/download/v3.1.6/utPLSQL-cli.zip"
- unzip utPLSQL-cli.zip && chmod -R u+x utPLSQL-cli
# copy ojdbc.jar from sqlcl to utPSLQL-cli so it can be visible to utPSLQL-cli
- cp sqlcl/lib/ojdbc8.jar utPLSQL-cli/lib && cp sqlcl/lib/orai18n.jar utPLSQL-cli/lib

# Download specified version of utPLSQL from utPLSQL github repo
# Allows any utPLSQL branch/tag name to be used
- git clone --depth=1 --branch=${UTPLSQL_VERSION} https://github.com/utPLSQL/utPLSQL.git ${UTPLSQL_DIR}

# update version placeholder before install
# This is only needed when downloading utPLSQL versions older than 3.1
- if [[ -n ${VERSION_PLACEHOLDER} ]] ; then sed -i "s/${VERSION_PLACEHOLDER}/${UTPLSQL_VERSION}/g" ${UTPLSQL_DIR}/source/core/ut_utils.pks; fi

- docker login -u "${DOCKER_USER}" -p "${DOCKER_PASSWORD}"
# download Oracle Database docker image from private repo and start the DB
- docker pull ${DOCKHER_HUB_REPO}:${ORACLE_VERSION}
# start the docker container (DB)
- docker run -d --name ${ORACLE_VERSION} ${DOCKER_OPTIONS} -p 1521:1521 ${DOCKHER_HUB_REPO}:${ORACLE_VERSION}
# Wait for DB startup
- docker logs -f ${ORACLE_VERSION} | grep -m 1 "DATABASE IS READY TO USE!" --line-buffered

# Install utPLSQL into the Database
- .travis/install_utplsql.sh

install:
# Create the demo project DB user account
- sql sys/${DB_SYS_PASSWORD}@//${CONNECTION_STR} as sysdba @scripts/create_user_headless.sql ${DB_USER} ${DB_PASS}
# Install project sources
- |
sql ${DB_USER}/${DB_PASS}@//${CONNECTION_STR} <<-SQL
alter session set plsql_ccflags = 'logger_context:true, no_op:false, logger_debug:true, APEX:false, logger_plugin_error: true';
@install/logger_install.sql
exit
SQL
# Grant needed for tests - to use DMBS_LOCK.SLEEP in tests as the docker image used doesn't include APEX at all
- |
sql sys/${DB_SYS_PASSWORD}@//${CONNECTION_STR} as sysdba <<-SQL
grant execute on dbms_lock to ${DB_USER};
exit
SQL
# Install project tests
- |
sql ${DB_USER}/${DB_PASS}@//${CONNECTION_STR} <<-SQL
set echo on
@tests/test_logger.pks
@tests/test_logger.pkb
exit
SQL

script:
# Run tests
- |
utplsql run ${DB_USER}/${DB_PASS}@//${CONNECTION_STR} \
-source_path=packages -test_path=tests \
-f=ut_documentation_reporter -c \
-f=ut_coverage_sonar_reporter -o=coverage.xml \
-f=ut_sonar_test_reporter -o=test_results.xml \
--failure-exit-code=0
# --failure-exit-code=0 skips test errors and failures
# Run sonar scanner and publish to sonar
- sonar-scanner
56 changes: 56 additions & 0 deletions .travis/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

var casper = require("casper").create({
// verbose: true,
// logLevel: "debug",
pageSettings: {
loadImages: false,
loadPlugins: false
}
});

if (casper.cli.args.length < 4) {
casper.echo("Missing parameters: username password agreementUrl downloadUrl").exit(1);
}

// Script parameters.
var paramUsername = casper.cli.get(0);
var paramPassword = casper.cli.get(1);
var agreementUrl = casper.cli.get(2);
var downloadUrl = casper.cli.get(3);
var downloaded = false;

casper.start();
// TODO: Error handling.

// Accept the license agreement.
casper.thenOpen(agreementUrl, function () {
// this.echo("Accepting License");
this.evaluate(function () {
acceptAgreement(window.self);
});
});

// Try to access the download page, wait for redirection and submit the login form.
casper.thenOpen(downloadUrl).waitForUrl(/signon\.jsp$/, function (re) {
// this.echo("Injecting Login Info");
this.evaluate(function (username, password) {
document.getElementById("sso_username").value = username;
document.getElementById("ssopassword").value = password;
doLogin(document.LoginForm);
}, paramUsername, paramPassword);
// this.capture("Screenshot.png");
});

casper.on("resource.received", function (resource) {
if (resource.url.indexOf("AuthParam") !== -1 && !downloaded) {
// this.echo("DownloadUrl:");
// Print the download url.
this.echo(resource.url);
downloaded = true;
// TODO: Try to download file from here. this.download is not working because of cross site request.
}
});

casper.run(function () {
this.exit();
});
66 changes: 66 additions & 0 deletions .travis/install_sqlcl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
set -e

###############################3
# Declarations
###############################3
SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}" )"
SQLCL_FILE=sqlcl-18.3.0.259.2029.zip
AGREEMENT_URL="http://www.oracle.com/technetwork/developer-tools/sqlcl/downloads/index.html"
DOWNLOAD_URL="https://download.oracle.com/otn/java/sqldeveloper/${SQLCL_FILE}"
ZIP_TARGET_DIR=""
OTN_USER=""
OTN_PASS=""
OUTPUT_DIR=""

# Call the casperjs script to return the download url. Then download the file using curl.
downloadFile() {
user=$1
pass=$2
agreementUrl=$3
downloadUrl=$4
outputFile=$5
echo "Signing-in"
downloadUrl=$(exec casperjs ${SCRIPT_DIR}/download.js ${user} ${pass} ${agreementUrl} ${downloadUrl})
downloadUrl=${downloadUrl%$'\r'}
echo "DownloadURL: $downloadUrl"
curl -o ${outputFile} -L "$downloadUrl"
}

###############################3
# Main script
###############################3

#Evaluate script input parameters
while getopts "p:u:d:o:" OPTNAME; do
case "${OPTNAME}" in
"d") ZIP_TARGET_DIR="${OPTARG}" ;;
"u") OTN_USER="${OPTARG}" ;;
"p") OTN_PASS="${OPTARG}" ;;
"o") OUTPUT_DIR="${OPTARG}" ;;
esac
done

#Check parameters
if [[ "${ZIP_TARGET_DIR}" == "" ]]; then
ZIP_TARGET_DIR="."
fi
if [[ "$OTN_USER" == "" ]] || [[ "$OTN_PASS" == "" ]]; then
echo "Error: Oracle OTN username/password not specified."
exit 1
fi
if [[ "$OUTPUT_DIR" == "" ]]; then
echo "Error: Output directory not specified"
exit 1
fi

if [[ ! -f "${ZIP_TARGET_DIR}/${SQLCL_FILE}" ]]; then
npm install -g phantomjs-prebuilt casperjs
echo "Downloading sqlcl from Oracle"
downloadFile ${OTN_USER} ${OTN_PASS} ${AGREEMENT_URL} ${DOWNLOAD_URL} "${ZIP_TARGET_DIR}/${SQLCL_FILE}"
else
echo "Installing sqlcl from cache..."
fi;

echo "Unzipping sqlcl into: ${ZIP_TARGET_DIR}"
unzip -q "${ZIP_TARGET_DIR}/${SQLCL_FILE}" -d ${OUTPUT_DIR}
7 changes: 7 additions & 0 deletions .travis/install_utplsql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -ev

cd ${UTPLSQL_DIR}/source

sql -S -L sys/${DB_SYS_PASSWORD}@//${CONNECTION_STR} AS SYSDBA @install_headless.sql
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VNNFRTC6YP8ZL"><img alt="Donate to Logger" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif"></a>

[![build](https://img.shields.io/travis/jgebal/Logger/3.2.0.svg?label=release%203.2.0)](https://travis-ci.org/jgebal/Logger)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=jgebal_Logger&metric=alert_status)](https://sonarcloud.io/dashboard?id=jgebal_Logger)

- [What is Logger?](#what-is-logger)
- [Documentation](#documentation)
- [Download](#download)
Expand Down
61 changes: 61 additions & 0 deletions scripts/create_user_headless.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Rem NAME
Rem create_user.sql
Rem
Rem DESCRIPTION
Rem Use this file to create a user / schema in which to install the logger packages
Rem
Rem NOTES
Rem Assumes the SYS / SYSTEM user is connected.
Rem
Rem REQUIREMENTS
Rem - Oracle 10.2+
Rem
Rem
Rem MODIFIED (MM/DD/YYYY)
Rem tmuth 11/02/2006 - Created

set define '&'

set verify off
prompt
prompt
prompt Logger create schema script.
prompt


set echo off
column 1 new_value 1 noprint
column 2 new_value 2 noprint
column 3 new_value 3 noprint
column 4 new_value 4 noprint
select null as "1", null as "2" , null as "3", null as "4" from dual where 1=0;
column sep new_value sep noprint

column logger_user new_value logger_user noprint
column logger_tablespace new_value logger_tablespace noprint
column temp_tablespace new_value temp_tablespace noprint
column logger_pass new_value logger_pass noprint

select coalesce('&&1','LOGGER_USER') logger_user,
coalesce('&&2','XNtxj8eEgA6X6b6f') logger_pass,
coalesce('&&3','USERS') logger_tablespace,
coalesce('&&4','TEMP') temp_tablespace
from dual;

create user &LOGGER_USER identified by &LOGGER_PASS default tablespace &LOGGER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
/

alter user &LOGGER_USER quota unlimited on &LOGGER_TABLESPACE
/

grant connect,create view, create job, create table, create sequence, create trigger, create procedure, create any context to &LOGGER_USER
/

prompt
prompt
prompt &LOGGER_USER user successfully created.
prompt Important!!! Connect as the &LOGGER_USER user and run the logger_install.sql script.
prompt
prompt

exit
25 changes: 25 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# must be unique in a given SonarQube instance
sonar.projectKey=jgebal_Logger
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=Logger
sonar.organization=jgebal-github

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
sonar.sources=./packages
sonar.exclusions=packages/logger_test.pkb
sonar.coverage.exclusions=**/*.pks,packages/logger_test.pkb
sonar.coverageReportPaths=./coverage.xml
sonar.tests=./tests
sonar.testExecutionReportPaths=./test_results.xml
sonar.links.issue=https://github.com/jgebal/Logger/issues
sonar.links.ci=https://travis-ci.org/jgebal/Logger
sonar.links.homepage=https://github.com/jgebal/Logger
sonar.projectDescription=Oracle database PL/SQL logger
sonar.plsql.file.suffixes=sql,tab,tps,pks,pkb,tpb,prc,fnc
sonar.language=plsql

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
Loading