Skip to content

Commit

Permalink
Build on Travis CI using shelljs
Browse files Browse the repository at this point in the history
  • Loading branch information
poulad committed Sep 6, 2018
1 parent ab5095c commit 88bf67a
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 44 deletions.
22 changes: 10 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
language: csharp
dist: trusty
sudo: false
mono: none
dotnet: 2.0.0
services:
- docker
branches:
except:
- master
script:
- cd test/UnitTests
- dotnet test --configuration Release --list-tests
- dotnet xunit -configuration Release -nobuild -stoponfail -verbose
- cd -
- cd test/IntegrationTests
- dotnet test --configuration Release --list-tests
- dotnet xunit -configuration Release -nobuild -stoponfail -verbose
- gh-pages
notifications:
email: false
install:
- docker pull microsoft/dotnet:2.0.0-sdk-stretch
- cd ci
- npm install
script:
- npm run travis-ci


## Notes:
### Limit concurrent jobs to only 1
Expand Down
74 changes: 74 additions & 0 deletions ci/build_travis-ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const $ = require('shelljs')
const path = require('path')
const fs = require('fs')
require('./logging')

$.config.fatal = true
const root = path.join(__dirname, '..')

const dotnet_image = "microsoft/dotnet:2.0.0-sdk-stretch"

function unit_test(configuration) {
console.info(`Unit testing on .NET Core`)
console.debug(`Configuration: ${configuration}`)

const commands = [
`cd /app/test/UnitTests/`,
`dotnet restore`,
`dotnet build --configuration ${configuration}`,
`dotnet xunit -configuration ${configuration} -nobuild -verbose`
]
.reduce((prev, curr) => `${prev} && ${curr}`, 'echo')

$.exec(
`docker run --rm --tty --volume "${root}:/app/" "${dotnet_image}" ` +
`sh -c "${commands}"`
)
}

function generate_app_settings_file() {
console.info(`Generate appsettings.Development.json from environment variables`)

const appSettings = {
'ApiToken': process.env['TelegramBot_ApiToken'],
'AllowedUserNames': process.env['TelegramBot_AllowedUserNames'],
'SuperGroupChatId': process.env['TelegramBot_SuperGroupChatId']
}

for (const field in appSettings)
if (!appSettings[field])
console.warn(`There is no value set for field ${field}.`)

fs.writeFileSync(`${root}/test/IntegrationTests/appsettings.Development.json`, JSON.stringify(appSettings))
}

function systems_integration_test(configuration) {
console.info(`Systems Integration testing on .NET Core`)
console.debug(`Configuration: ${configuration}`)

const commands = [
`cd /app/test/IntegrationTests/`,
`dotnet restore`,
`dotnet build --configuration ${configuration}`,
`dotnet xunit -configuration ${configuration} -stoponfail -nobuild -verbose`
]
.reduce((prev, curr) => `${prev} && ${curr}`, 'echo')

$.exec(
`docker run --rm --tty --volume "${root}:/app/" "${dotnet_image}" ` +
`sh -c "${commands}"`
)
}

console.info(`Docker Image: ${dotnet_image}`)

unit_test('Debug')
unit_test('Release')

const branch = process.env['TRAVIS_BRANCH']
if (branch === 'develop') {
generate_app_settings_file()
systems_integration_test('Release')
} else {
console.warn(`Branch is "${branch}". Skipping systems integration tests...`)
}
14 changes: 14 additions & 0 deletions ci/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const chalk = require('chalk');
const $ = require('shelljs')

if (process.env['TRAVIS']) {
console.info = m => $.echo("\n\033[1;34m#", m, "\033[0m")
console.debug = m => $.echo("\n\033[0;32m##", m, "\033[0m")
console.warn = m => $.echo("\n\033[1;33m##", m, "\033[0m")
console.error = m => $.echo("\n\033[1;31m##", m, "\033[0m")
} else {
console.info = m => console.log(chalk.blue.bold(`\n# ${m}\n`))
console.debug = m => console.log(chalk.green.bold(`\n## ${m}\n`))
console.warn = m => console.log(chalk.yellow.bold(`\n## ${m}\n`))
console.error = m => console.log(chalk.red.bold(`\n## ${m}\n`))
}
241 changes: 241 additions & 0 deletions ci/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ci/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "build",
"version": "1.0.0",
"scripts": {
"travis-ci": "node build_travis-ci.js"
},
"private": true,
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/shelljs": "^0.8.0",
"chalk": "^2.4.1",
"shelljs": "^0.8.2"
}
}
Loading

0 comments on commit 88bf67a

Please sign in to comment.