Skip to content

Commit

Permalink
Merge pull request #2 from teracyhq/develop
Browse files Browse the repository at this point in the history
merge remote branch teracy-dev/develop
  • Loading branch information
hieptranquoc authored Oct 3, 2018
2 parents a32c5ae + d1c6a82 commit d1bf129
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 31 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@ Change Log
==========


[v0.6.0-a4][] (2018-09-15)
--------------------------

- Tasks:
+ clean up config_default.yaml support for extensions

- Bug Fixes:
+ fix Util.exist always return true if it is String


Details: https://github.com/teracyhq/dev/milestone/11?closed=1


[v0.6.0-a3][] (2018-09-14)
--------------------------

- Improvements:
+ add tracing when something wrong
+ improve logging by adding filter, tracing
+ simply the config override mechanism and use teracy-dev-entry only for override

- Bug Fixes:
+ warn log did not display the yellow color


Details: https://github.com/teracyhq/dev/milestone/10?closed=1


[v0.6.0-a2][] (2018-08-26)
--------------------------

Expand Down Expand Up @@ -333,3 +361,5 @@ Release the first milestone

[v0.6.0-a1]: https://github.com/teracyhq/dev/milestone/7?closed=1
[v0.6.0-a2]: https://github.com/teracyhq/dev/milestone/9?closed=1
[v0.6.0-a3]: https://github.com/teracyhq/dev/milestone/10?closed=1
[v0.6.0-a4]: https://github.com/teracyhq/dev/milestone/11?closed=1
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ Installation and Usage

Follow the guide at http://dev.teracy.org/docs/getting_started.html

How to develop
--------------
Follow the commands below to pull the latest code of teracy-dev and you can continue to develop it.

.. code-block:: bash
$ cd ~/
$ git clone <your_forked_repo> teracy-dev
$ cd teracy-dev
$ git remote add upstream [email protected]:teracyhq/dev.git
$ git fetch upstream # get the changes from the upstream repo
$ git checkout develop # the develop branch to work on it
$ git branch -u upstream/develop # track the upstream's branch
$ git pull # update to the latest upstream's changes
License
-------
Expand Down
6 changes: 3 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# teracy-dev related settings
teracy-dev:
require_version: ">= 0.6.0-a3-SNAPSHOT"
require_version: ">= 0.6.0-a5-SNAPSHOT"
# location sync
location:
git: https://github.com/teracyhq/dev.git
Expand All @@ -14,8 +14,8 @@ teracy-dev:
extension: teracy-dev-core # extension_path, we'll lookup the extension by its lookup_path + extension_path
location: # auto download the extension into the lookup_path
git: https://github.com/teracyhq-incubator/teracy-dev-core.git
branch: v0.2.0
require_version: ">= 0.2.0"
branch: develop
require_version: ">= 0.3.0-SNAPSHOT"
enabled: true # when true, extension will be auto-downloaded if not available yet and will load this extension to be used
# extension must have manifest.yaml file to describe its name, version and optional description
# optional: config_default.yaml, teracy-dev-ext.rb will be auto loaded if available
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# The short X.Y version.
version = 'v0.6'
# The full version, including alpha/beta/rc tags.
release = 'v0.6.0-a3-SNAPSHOT'
release = 'v0.6.0-a5-SNAPSHOT'


# The language for content autogenerated by Sphinx. Refer to documentation
Expand Down
31 changes: 21 additions & 10 deletions lib/teracy-dev/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,31 @@ def initialize
def start
@processorsManager = Processors::Manager.new
@configManager = Config::Manager.new
@settingsManager = Settings::Manager.new
@extension_entry_path = File.join(TeracyDev::BASE_DIR, TeracyDev::EXTENSION_ENTRY_PATH)
# we sync teracy-dev and teracy-dev-entry before extensions
sync()
settings = build_settings().freeze
sync_teracy_dev(settings)
sync_teracy_dev_entry(settings)
require_teracy_dev_version(settings['teracy-dev']['require_version'])
configure_vagrant(settings)
end

private

def sync_teracy_dev(settings)
location = settings['teracy-dev']['location']
def sync
# teracy_dev_location and teracy_dev_entry_location is built from teracy-dev and teracy-dev-entry settings
# with the override mechanism
# extensions settings for these syncs are not accepted
teracy_dev_settings = @settingsManager.build_teracy_dev_settings()
entry_settings = @settingsManager.build_entry_settings(@extension_entry_path)
settings = Util.override(teracy_dev_settings, entry_settings)
@logger.debug("settings: #{settings}")
sync_teracy_dev(settings['teracy-dev']['location'])
sync_teracy_dev_entry(settings['teracy-dev']['entry_location'])
end


def sync_teracy_dev(location)
location.merge!({
"path" => TeracyDev::BASE_DIR
})
Expand All @@ -51,13 +65,12 @@ def sync_teracy_dev(settings)
end
end

def sync_teracy_dev_entry(settings)
path = File.join(TeracyDev::BASE_DIR, TeracyDev::EXTENSION_ENTRY_PATH)
def sync_teracy_dev_entry(location)
path = @extension_entry_path
lookup_path = TeracyDev::EXTENSION_ENTRY_PATH.split('/')[0..-2].join('/')
lookup_path = File.join(TeracyDev::BASE_DIR, lookup_path)
dir = TeracyDev::EXTENSION_ENTRY_PATH.split('/').last

location = settings['teracy-dev']['entry_location']
location.merge!({
"lookup_path" => lookup_path,
"path" => path,
Expand Down Expand Up @@ -85,9 +98,7 @@ def sync_teracy_dev_entry(settings)
end

def build_settings
extension_entry_path = File.join(TeracyDev::BASE_DIR, TeracyDev::EXTENSION_ENTRY_PATH)
settingsManager = Settings::Manager.new
settings = settingsManager.build_settings(extension_entry_path)
settings = @settingsManager.build_settings(@extension_entry_path)
load_extension_entry_files(settings)
settings = process(settings)
# updating nodes here so that processors have change to adjust nodes by adjusting default
Expand Down
48 changes: 36 additions & 12 deletions lib/teracy-dev/location/git_synch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ def sync(location, sync_existing)
updated = true
end

if git_stage_has_untracked_changes?
@logger.warn("`#{path}` has untracked changes, auto update is aborted!\n #{`git status`}")

return false
end

if ref
updated = check_ref(current_ref, ref)
elsif tag
Expand Down Expand Up @@ -85,31 +91,36 @@ def check_ref(current_ref, ref_string)

def check_tag(current_ref, desired_tag)
@logger.debug("Sync with tags/#{desired_tag}")

updated = false

cmd = "git log #{desired_tag} -1 --pretty=%H"

tag_ref = `#{cmd}`.strip

if $?.success? != true
if !$?.success?
# fetch origin if tag is not present
`git fetch origin`
end

# re-check
tag_ref = `#{cmd}`.strip
# re-check
tag_ref = `#{cmd}`.strip

if $?.success? != true
# tag not found
@logger.warning("tag not found: #{desired_tag}")
return updated
if !$?.success?
# tag not found
@logger.warn("tag not found: #{desired_tag}")

return updated
end
end

@logger.debug("current_ref: #{current_ref} - tag_ref: #{tag_ref}")

if current_ref != tag_ref
`git checkout tags/#{desired_tag}`

updated = true
end

updated
end

Expand All @@ -130,23 +141,36 @@ def check_branch(current_ref, desired_branch)

@logger.debug("current_branch: #{current_branch} - desired_branch: #{desired_branch}")

# found no such branch, switch to found as tag
return check_tag(current_ref, desired_branch) if !File.exist?(
".git/refs/heads/#{desired_branch}")
quoted_branch = Regexp.quote(desired_branch).gsub("/", '\/')

remote_ref = `git show-ref --head | sed -n 's/ .*\\(refs\\/remotes\\/origin\\/#{desired_branch}\\).*//p'`.strip
remote_ref = `git show-ref --head | sed -n 's/ .*\\(refs\\/remotes\\/origin\\/#{quoted_branch}\\).*//p'`.strip

# remote origin ref is not exist mean remote origin branch is not exist
# if found no such remote branch, switch to found as tag
return check_tag(current_ref, desired_branch) if !Util.exist? remote_ref

@logger.debug("current_ref: #{current_ref} - remote_ref: #{remote_ref}")

if current_ref != remote_ref
`git checkout #{desired_branch}`

if !$?.success?
# create new local branch if it is not present
@logger.debug("No such branch! Creating one.")

`git checkout -b #{desired_branch}`
end

`git reset --hard origin/#{desired_branch}`
updated = true
end
updated
end

def git_stage_has_untracked_changes?()
!Util.exist? `git status | grep 'nothing to commit, working tree clean'`.strip
end

end
end
end
10 changes: 9 additions & 1 deletion lib/teracy-dev/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module TeracyDev
class Plugin
# install or uninstall plugins bases on the plugins config
def self.sync(plugins)
logger = TeracyDev::Logging.logger_for('Plugin')
logger = TeracyDev::Logging.logger_for(self)
plugins ||= []
plugin_manager = Vagrant::Plugin::Manager.instance
installed_plugins = plugin_manager.installed_plugins
Expand All @@ -17,6 +17,14 @@ def self.sync(plugins)

if !installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'installed'
logger.info("installing plugin: #{plugin}")

if plugin['sources'].nil? or plugin['sources'].empty?
plugin['sources'] = [
"https://rubygems.org/",
"https://gems.hashicorp.com/"
]
end

plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
reload_required = true
end
Expand Down
4 changes: 2 additions & 2 deletions lib/teracy-dev/settings/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def build_settings(entry_dir_path)
settings
end

private

def build_teracy_dev_settings()
config_file_path = File.join(File.dirname(__FILE__), '../../../config.yaml')
Expand All @@ -59,6 +58,7 @@ def build_entry_settings(lookup_dir)
settings
end

private

def build_extensions_settings(extensions)
@logger.debug("extensions: #{extensions}")
Expand All @@ -67,7 +67,7 @@ def build_extensions_settings(extensions)
next if extension['enabled'] != true
lookup_path = File.join(TeracyDev::BASE_DIR, extension['path']['lookup'] ||= DEFAULT_EXTESION_LOOKUP_PATH)
path = File.join(lookup_path, extension['path']['extension'])
extensions_settings << Util.build_settings_from(File.join(path, 'config_default.yaml'))
extensions_settings << Util.load_yaml_file(File.join(path, 'config.yaml'))
end
settings = {}
extensions_settings.reverse_each do |extension_settings|
Expand Down
3 changes: 2 additions & 1 deletion lib/teracy-dev/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ def self.exist?(value)
if !value.nil?
if value.instance_of? String
exist = !value.empty?
else
exist = true
end
exist = true
end
exist
end
Expand Down
2 changes: 1 addition & 1 deletion lib/teracy-dev/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TeracyDev
# sermver format
VERSION = '0.6.0-a3-SNAPSHOT'
VERSION = '0.6.0-a5-SNAPSHOT'
end

0 comments on commit d1bf129

Please sign in to comment.