Top Level Namespace

Includes:
FileTest

Defined Under Namespace

Classes: SemVerMetadata, String

Constant Summary collapse

ASTER =
'*'
CSPROJ =
'.csproj'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.commit_dataObject

load the commit data

returns: [short-commit
String, date

DateTime]



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/versioning.rb', line 125

def self.commit_data
  begin
    commit = `git rev-parse --short HEAD`.chomp()[0,6]
    git_date = `git log -1 --date=iso --pretty=format:%ad`
    commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H:%M:%S")
  rescue
    commit = (ENV['BUILD_VCS_NUMBER'] || "000000")[0,6]
    commit_date = Time.new.strftime("%Y-%m-%d %H:%M:%S")
  end
  [commit, commit_date]
end

.format_nuget(semver) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/versioning.rb', line 115

def self.format_nuget semver
  if semver.prerelease and not semver.prerelease.empty?
    "#{semver.major}.#{semver.minor}.#{semver.patch}-#{semver.prerelease.gsub(/\W/, '')}"
  else
    semver.format '%M.%m.%p'
  end
end

.versions(semver, &commit_data) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/versioning.rb', line 81

def self.versions semver, &commit_data
  {
    # just a monotonic inc
    :build_number   => semver.patch,
    :semver         => semver,

    # purely M.m.p format
    :formal_version => "#{ XSemVer::SemVer.new(semver.major, semver.minor, semver.patch).format "%M.%m.%p"}",

    # four-numbers version, useful if you're dealing with COM/Windows
    :long_version   => "#{semver.format '%M.%m.%p'}.0",

    # extensible number w/ git hash
    :build_version  => semver.format("%M.%m.%p%s") + ".#{yield[0]}",

    # nuget (not full semver 2.0.0 support) see http://nuget.codeplex.com/workitem/1796
    :nuget_version  => format_nuget(semver)
  }
end

.versions_no_semver(&commit_data) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/versioning.rb', line 101

def self.versions_no_semver &commit_data
  dt_ver = Time.new.strftime('%y.%-m.%-d') + ".#{(ENV['BUILD_NUMBER'] || '0')}"
  {

    :formal_version => dt_ver,

    # four-numbers version, useful if you're dealing with COM/Windows
    :long_version   => dt_ver,

    # extensible number w/ git hash
    :build_version  => dt_ver + ".#{yield[0]}"
  }
end

Instance Method Details

#add_files(stage, what_dlls, nuspec, folder = 'lib') ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/build.rb', line 15

def add_files stage, what_dlls, nuspec, folder='lib'
  [['net35', 'net-3.5'], ['net40', 'net-4.0'], ['net45', 'net-4.5']].each{|fw|
    takeFrom = File.join(stage, fw[1], what_dlls)
    Dir.glob(takeFrom).each do |f|
      nuspec.file(f.gsub("/", "\\"), "#{folder}\\#{fw[0]}")
    end
  }
end

#cleantask(props) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/build.rb', line 50

def cleantask props

  if props.has_key?(:output) && File.directory?(props[:output])
    FileUtils.rm_rf props[:output]
    waitfor { !exists?(props[:output]) }
  end

  if props.has_key?(:artifacts) && File.directory?(props[:artifacts])
    FileUtils.rm_rf props[:artifacts]
    waitfor { !exists?(props[:artifacts]) }
  end

  if props.has_key?(:output)
    Dir.mkdir props[:output]
  end
  if props.has_key?(:artifacts)
    Dir.mkdir props[:artifacts]
  end
end

#commit_dataObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/build.rb', line 24

def commit_data
  begin
    commit = `git rev-parse --short HEAD`.chomp()[0,6]
    git_date = `git log -1 --date=iso --pretty=format:%ad`
    commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
  rescue Exception => e
    puts e.inspect
    commit = (ENV['BUILD_VCS_NUMBER'] || "000000")[0,6]
    commit_date = Time.new.strftime("%Y-%m-%d %H%M%S")
  end
  [commit, commit_date]
end

#copy_output_files(fromDir, filePattern, outDir) ⇒ Object



2
3
4
5
6
7
# File 'lib/build.rb', line 2

def copy_output_files fromDir, filePattern, outDir
  FileUtils.mkdir_p outDir unless exists?(outDir)
  Dir.glob(File.join(fromDir, filePattern)){|file|
    copy(file, outDir) if File.file?(file)
  }
end

#get_commit_hash_and_dateObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/versioning.rb', line 6

def get_commit_hash_and_date
  begin
    commit = `git log -1 --pretty=format:%H`
    git_date = `git log -1 --date=iso --pretty=format:%ad`
    commit_date = DateTime.parse( git_date ).strftime("%Y-%m-%d %H%M%S")
  rescue
    commit = "git unavailable"
  end

  [commit, commit_date]
end

#nuget_content(nuget_name, path, dotnet_ver) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/package.rb', line 51

def nuget_content nuget_name, path, dotnet_ver

  content = {}

   = SemVerMetadata.new ".semver/#{nuget_name}.semver"

  content[:files] = {}
  content[:files]['lib'] = .files

  file_names = .assemblies.map{ |x|
    "#{path}/#{x}"
  }
  assemblies = []
  file_names.each{ |file|
    assemblies.concat(file.expand_with(['dll','pdb','xml']))
  }
  content[:files]['lib'].concat assemblies

  content[:dependencies] = .depends

  content[:version] = read_versions[nuget_name][:nuget_version]
  content[:target_framework] = dotnet_ver

  content
end

#nuget_pack(id, config, artifact_path) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/package.rb', line 1

def nuget_pack id, config, artifact_path
  require 'albacore/task_types/nugets_pack'

  p = Albacore::NugetsPack::Config.new

  p.configuration = BUILD_CONFIG

  if !config.has_key? :projects || config[:projects] == ''
    raise 'At least one project is required to build'.red
  end

  p.files = config[:projects]

  if config.has_key? :nuspec && config[:nuspec] != ''
    p.nuspec = config[:nuspec]
  end

  p.out = artifact_path

  p. do |m|
    m.id = id
    m.title = PRODUCT
    m.description = PRODUCT_DESCRIPTION
    m.authors = COMPANY
    m.version = config[:version]
    if config.has_key? :dependencies
      config[:dependencies].each { |name, version|
        m.add_dependency name, version
      }
    end
  end

  p.target = config[:target_framework]
  p.with_package do |p|
    if config.has_key? :files
      config[:files].each { |folder, files|
        files.each{ |file|
          p.add_file file, folder
        }
      }
    end
  end
  
  p.gen_symbols
  p.nuget_gem_exe
  #p.leave_nuspec

  Albacore::NugetsPack::ProjectTask.new(p.opts).execute
end

#project_outputs(props) ⇒ Object



9
10
11
12
13
# File 'lib/build.rb', line 9

def project_outputs props
  props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.dll" }.
    concat( props[:projects].map{ |p| "src/#{p}/bin/#{BUILD_CONFIG}/#{p}.exe" } ).
    find_all{ |path| exists?(path) }
end

#read_versionsObject

put semver versions in a map



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/versioning.rb', line 19

def read_versions

  return $version_map if !$version_map.empty?
  
  files = Dir['.semver/**/*.semver']
  files.each { | file |
    v = SemVer.new
    v.load file
    v.patch = (ENV['BUILD_NUMBER'] || v.patch).to_i
    version = versions(v, &method(:commit_data))

    sm = SemVerMetadata.new file
    assemblies = sm.assemblies
    sm.assemblies.each { |a|
      $version_map[a] = version
    }

    name = file
      .gsub(/.semver/, '')
      .gsub('/', '')

    $version_map[name] = version
  }

  # this is for assemblies not versioned with semver
  $version_map[ASTER] = versions_no_semver(&method(:commit_data))

  $version_map
end

#run_vsconsole_tests(settings, params = nil, assemblies = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/build.rb', line 70

def run_vsconsole_tests settings, params = nil, assemblies = nil

  raise 'Settings file name is required' if settings.nil?

  if assemblies.nil?
    assemblies = FileList["**/#{OUTPUT_PATH}/*.Tests.dll"]
    filelist = assemblies.map { |assembly| File.join(Dir.pwd, assembly)}
  end

  test_runner :tests do |tests|
    tests.files = filelist
    tests.exe = 'C:/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/TestWindow/VSTest.console.exe'
    if (params != nil)
      params.each { | p |
        tests.add_parameter p 
      }
    end
    tests.add_parameter '/InIsolation'
    tests.add_parameter '/Logger:trx'
    tests.add_parameter "/Settings:#{Dir.pwd}/#{settings}.runsettings"
  end

end

#update_assembly_versionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/versioning.rb', line 49

def update_assembly_versions
  require 'albacore/task_types/asmver'

  $version_map = read_versions

  files = FileList['**/*' + CSPROJ]
  files.each { |f|
      
    ns =  File.basename(f, CSPROJ)

    asm_file = File.join File.dirname(f), '/Properties/AssemblyVersion.cs'
    next if ns.nil? || ns.to_s == '' || !File.file?(asm_file)

    c = Albacore::Asmver::Config.new
    c.file_path = asm_file

    if ($version_map.key? ns)
      c.attributes assembly_configuration: BUILD_CONFIG,
            assembly_version: $version_map[ns][:long_version],
            assembly_file_version: $version_map[ns][:long_version],
            assembly_informational_version: $version_map[ns][:build_version]
    else 
      c.attributes assembly_configuration: BUILD_CONFIG,
            assembly_version: $version_map[ASTER][:long_version],
            assembly_file_version: $version_map[ASTER][:long_version],
            assembly_informational_version: $version_map[ASTER][:build_version]
    end
    
    Albacore::Asmver::Task.new(c.opts).execute
  }
end

#waitfor(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/build.rb', line 37

def waitfor &block
  checks = 0

  until block.call || checks >10
    sleep 0.5
    checks += 1
  end

  raise 'Waitfor timeout expired. Make sure that you aren\'t ' \
    'running something from the build output folders, or that you ' \
    'have browsed to it through Explorer.'.red if checks > 10
end