lib/cide/cli.rb in cide-0.8.1 vs lib/cide/cli.rb in cide-0.9.0

- old
+ new

@@ -121,12 +121,12 @@ method_option 'upload', desc: 'Whenever to upload the result to S3', type: :boolean, default: true - method_option 'set_version', - desc: 'Tells cide the package version, otherwise extracted from git', + method_option 'build_id', + desc: 'Specifies the build id', default: nil # AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_REGION need to be passed # either trough the env or ~/.aws/credentials file method_option 'aws_bucket', @@ -142,24 +142,34 @@ guest_export_dir = '/cide/package' host_export_dir = File.join(build_root, 'package') FileUtils.rm_rf(build_root) - version = options.set_version || ( + build_id = options.build_id || ( + timestamp = Time.now.strftime('%Y-%m-%d_%H%M%S') git_branch = `git symbolic-ref --short -q HEAD || echo unknown`.strip git_rev = `git rev-parse --short HEAD`.strip - "#{git_branch}-#{git_rev}" + "#{timestamp}.#{git_branch}-#{git_rev}" ) - timestamp = Time.now.strftime('%Y-%m-%d_%H%M%S') - tar_name = "#{options.package}.#{timestamp}.#{version}.tar.gz" + tar_name = "#{options.package}.#{build_id}.tar.gz" tar_path = File.join(build_root, tar_name) banner 'Config' config = ConfigFile.load(Dir.pwd) say_status :config, config.inspect + version_data = + case config.package && config.package.add_version + when 'sha' + `git rev-parse HEAD`.strip + when 'short_sha' + `git rev-parse --short HEAD`.strip + when 'auto' + build_id + end + ## Build ## banner 'Build' builder = Builder.new(config) builder.build( pull: options.pull, @@ -182,9 +192,18 @@ runner.export!( guest_dir: guest_export_dir, host_dir: host_export_dir, ) + + ## Set version ## + if version_data + version_file = File.join(host_export_dir, '.packager', 'version') + FileUtils.mkdir_p(File.dirname(version_file)) + File.open(version_file, 'w') do |f| + f.puts version_data + end + end # Create archive puts "Package: #{tar_name}" system('tar', '-czf', tar_path, '-C', host_export_dir, '.')