Skip to content

Commit

Permalink
Merge pull request #601 from hieptranquoc/task/#423-update-travis-ci
Browse files Browse the repository at this point in the history
@ #423 | update travis-ci
  • Loading branch information
hoatle committed May 24, 2019
2 parents c6c1eb2 + 828ff8d commit d59c4ea
Show file tree
Hide file tree
Showing 37 changed files with 1,546 additions and 472 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Session.vim
!.gitmodules
!.chef
!.travis
!.rubocop.yml
!.rubocop_todo.yml

# docs
_deploy
Expand Down
78 changes: 78 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
AllCops:
DisplayCopNames: true
StyleGuideCopsOnly: false
Exclude:
- "tmp/**/*"
- "vendor/**/*"
- "docs/**/*"
- "spec/fixtures/**/*"
- "workspace/**/*"
- "extensions/**/*"
Style/FrozenStringLiteralComment:
Enabled: false

Layout/TrailingWhitespace:
Enabled: true

Metrics/ClassLength:
Enabled: false

Metrics/LineLength:
Max: 100

Metrics/MethodLength:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Documentation:
Enabled: false

Style/DoubleNegation:
Enabled: false

Metrics/CyclomaticComplexity:
Max: 50

Metrics/PerceivedComplexity:
Max: 50

Performance/RangeInclude:
Enabled: false

Style/RescueStandardError:
EnforcedStyle: implicit

Style/IfInsideElse:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/RedundantReturn:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact

Metrics/BlockNesting:
Max: 5

Layout/SpaceAroundOperators:
Enabled: false

Style/MultilineIfModifier:
Enabled: false

Style/PreferredHashMethods:
EnforcedStyle: verbose

Style/RedundantBegin:
Enabled: false

Naming/FileName:
Enabled: false
34 changes: 29 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
sudo: required
dist: xenial

services:
- docker
git:
depth: 1

script:
- echo "OK"
jobs:
include:
- stage: "Check Style"
name: "check style"
before_install: bundle install
script: bundle exec rubocop

- stage: "Tests"
name: "tests"
script: bundle exec rspec

- stage: Deploy
services:
- docker
env:
- DOCKER_FILE=Dockerfile CI_REGISTRY_IMAGE=$DOCS_DOCKER_IMAGE CI_BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
before_script:
- chmod ugo+x ./.travis/deploy.sh
- git config --global user.name "Teracy Bot"
- git config --global user.email "teracy.com@gmail.com"
- export REPO_URL="https://$GH_TOKEN@github.com/$GH_REPO.git"
- . ./.travis/setup.sh
- echo $DEPLOY_HTML_DIR
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH | sed -e 's/[\/]/-/g' | sed -e 's/[\#]//g'; fi`
- export CONTAINER_IMAGE=$CI_REGISTRY_IMAGE:$TAG
script: ./.travis/deploy.sh
12 changes: 12 additions & 0 deletions .travis/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

function docker_build {
docker build -f $DOCKER_FILE \
--build-arg CI_BUILD_ID=$TRAVIS_BUILD_ID \
--build-arg CI_BUILD_REF=$TRAVIS_COMMIT \
--build-arg CI_BUILD_REF_NAME=$TRAVIS_BRANCH \
--build-arg CI_BUILD_TIME=$CI_BUILD_TIME \
--build-arg CI_REGISTRY_IMAGE=$CI_REGISTRY_IMAGE \
--build-arg CI_PROJECT_NAME=$TRAVIS_REPO_SLUG \
--pull -t $CONTAINER_IMAGE .
}
24 changes: 24 additions & 0 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

. ./.travis/common.sh

docker login -u=$DOCKER_USERNAME -p=$DOCKER_PASSWORD

function deploy_docs {
cd docs
make setup_gh_pages
make deploy
cd ..
}

function deploy_docker_img {
docker push $CONTAINER_IMAGE
}

# build teracy-dev-docs distributed Docker image
cd docs
docker_build
deploy_docker_img
cd ..
# allow this to be failed
deploy_docs
9 changes: 9 additions & 0 deletions .travis/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

#setup travis-ci configuration basing one the being-built branch

if [[ $TRAVIS_BRANCH == 'master' ]] ; then
export DEPLOY_HTML_DIR=docs
else
export DEPLOY_HTML_DIR=docs/$TRAVIS_BRANCH
fi
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'

ruby '>= 2.4.4'

# gem 'rake', >= 11.2.2'

group:test do
gem 'rspec'
gem 'rubocop', require: false
end
49 changes: 49 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
diff-lcs (1.3)
jaro_winkler (1.5.2)
parallel (1.14.0)
parser (2.6.0.0)
ast (~> 2.4.0)
powerpack (0.1.2)
psych (3.1.0)
rainbow (3.0.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.65.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
powerpack (~> 0.1)
psych (>= 3.1.0)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.4.0)
ruby-progressbar (1.10.0)
unicode-display_width (1.4.1)

PLATFORMS
ruby

DEPENDENCIES
rspec
rubocop

RUBY VERSION
ruby 2.6.1p33

BUNDLED WITH
2.0.1
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if ARGV[0] && !unloadable_sub_commands.include?(ARGV[0])
TeracyDev.init
rescue
# add tracing for easier debugging and fixing
puts $@
puts $ERROR_POSITION
raise
end

Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx_deployment.mk
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ setup_gh_pages: init_gh_pages
@cd $(DEPLOY_DIR);\
git fetch origin;\
git reset --hard origin/$(DEPLOY_BRANCH);\
git branch --set-upstream $(DEPLOY_BRANCH) origin/$(DEPLOY_BRANCH)
git branch --set-upstream-to=origin/$(DEPLOY_BRANCH) $(DEPLOY_BRANCH)
@echo "Now you can deploy to Github Pages with 'make generate' and then 'make deploy'"

generate: html
Expand Down
Empty file removed extensions/.gitkeep
Empty file.
17 changes: 6 additions & 11 deletions lib/teracy-dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
require_relative 'teracy-dev/logging/mask_filter'
require_relative 'teracy-dev/location/git_synch'


# define public APIs here
module TeracyDev

# TODO(hoatle): find a way to add warning log for these deprecated var
# deprecated, use TeracyDev::Env instead
BASE_DIR = File.join(File.dirname(__FILE__), '..')
Expand All @@ -23,28 +21,25 @@ module TeracyDev
EXTENSION_ENTRY_PATH = ENV['TERACY_DEV_EXTENSION_ENTRY_PATH'] ||= 'workspace/teracy-dev-entry'

# deprecated, use TeracyDev::Env instead
DEFAULT_EXTENSION_LOOKUP_PATH = 'extensions' # relative to the Vagrantfile

DEFAULT_EXTENSION_LOOKUP_PATH = 'extensions'.freeze # relative to the Vagrantfile

@@logger = TeracyDev::Logging.logger_for(self)
@logger = TeracyDev::Logging.logger_for(self)

# we can only create one Loader instance and accessible on this only
@@loader = TeracyDev::Loader.new
@loader = TeracyDev::Loader.new

def self.register_processor(processor, weight = 5)
@@loader.processorsManager.register(processor, weight)
@loader.processors_manager.register(processor, weight)
end

def self.register_configurator(configurator, weight = 5)
@@loader.configManager.register(configurator, weight)
@loader.config_manager.register(configurator, weight)
end


def self.init
Logging.add_acceptor(Logging::PrognameAcceptor.new)
Logging.add_filter(Logging::MaskFilter.new)
Location::Manager.add_synch(Location::GitSynch.new)
@@loader.start
@loader.start
end

end
10 changes: 3 additions & 7 deletions lib/teracy-dev/config/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ def configure(settings, config, type:)
end

protected
# sub class should override this
def configure_common(settings, config)

end

# sub class should override this
def configure_node(settings, config)

end
def configure_common(settings, config); end

# sub class should override this
def configure_node(settings, config); end
end
end
end
17 changes: 8 additions & 9 deletions lib/teracy-dev/config/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ module TeracyDev
module Config
# Manage the vagrant configuration from the provided settings hash object
class Manager
@@instance = nil
@instance = nil

def initialize
if !!@@instance
raise "TeracyDev::Config::Manager can only be initialized once"
end
@@instance = self
raise 'TeracyDev::Config::Manager can only be initialized once' if !!@instance

@instance = self
@logger = TeracyDev::Logging.logger_for(self.class.name)
@items = []
end

def register(configurator, weight)
if !configurator.respond_to?(:configure)
unless configurator.respond_to?(:configure)
@logger.warn("configurator #{configurator} must implement configure method, ignored")
return
end

unless weight.is_a? Integer and (0..9).include?(weight)
@logger.warn("#{configurator}'s weight (#{weight}) must be an integer and have value in range (0..9), otherwise it will be set to default (5)")
unless weight.is_a?(Integer) && (0..9).include?(weight)
@logger.warn("#{configurator}'s weight (#{weight}) " \
'must be an integer and have value in range (0..9),' \
'otherwise it will be set to default (5)')
weight = 5
end

Expand All @@ -40,7 +40,6 @@ def configure(settings, config, type:)
configurator.configure(Util.deep_copy(settings).freeze, config, type: type)
end
end

end
end
end
2 changes: 1 addition & 1 deletion lib/teracy-dev/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Env

EXTENSION_ENTRY_PATH = ENV['TERACY_DEV_EXTENSION_ENTRY_PATH'] ||= 'workspace/teracy-dev-entry'

DEFAULT_EXTENSION_LOOKUP_PATH = 'extensions' # relative to the Vagrantfile
DEFAULT_EXTENSION_LOOKUP_PATH = 'extensions'.freeze # relative to the Vagrantfile
end
end
Loading

0 comments on commit d59c4ea

Please sign in to comment.