albacore 2.1.2 → 2.2.0.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,143 +1,143 @@
1
- require 'set'
2
- require 'map'
3
- require 'tmpdir'
4
- require 'fileutils'
5
- require 'pathname'
6
- require 'albacore/cmd_config'
7
- require 'albacore/cross_platform_cmd'
8
-
9
- module Albacore
10
- module TestRunner
11
- # the configuration object for the test runner
12
- class Config
13
- include CmdConfig
14
-
15
- # give this property the list of dlls you want to test
16
- attr_writer :files
17
-
18
- # constructor, no parameters
19
- def initialize
20
- @copy_local = false
21
- @clr_command = true
22
- @files = []
23
- end
24
-
25
- # Gets the configured options from the test runner configuration.
26
- #
27
- def opts
28
- Map.new(
29
- :files => files,
30
- :copy_local => @copy_local,
31
- :exe => @exe,
32
- :parameters => @parameters,
33
- :clr_command => @clr_command)
34
- end
35
-
36
- # Mark that it should be possible to copy the test files local
37
- # -- this is great if you are running a VM and the host disk is
38
- # mapped as a network drive, which crashes some test runners
39
- def copy_local
40
- @copy_local = true
41
- end
42
-
43
- # Call this on the confiuguration if you don't want 'mono' prefixed to the
44
- # exe path on non-windows systems.
45
- #
46
- def native_exe
47
- @clr_command = false
48
- end
49
-
50
- private
51
- def files
52
- if @files.respond_to? :each
53
- @files
54
- else
55
- [@files]
56
- end
57
- end
58
- end
59
-
60
- class Cmd
61
- include CrossPlatformCmd
62
-
63
- # expects both parameters and executable to be relative to the
64
- # work_dir parameter
65
- def initialize work_dir, executable, parameters, file, clr_command = true
66
- @work_dir, @executable = work_dir, executable
67
- @parameters = parameters.to_a.unshift(file)
68
- @clr_command = clr_command
69
- end
70
-
71
- def execute
72
- info { "executing in directory './#{@work_dir}'" }
73
- system @executable,
74
- @parameters,
75
- :work_dir => @work_dir,
76
- :clr_command => @clr_command
77
- end
78
- end
79
-
80
- class Task
81
- include Logging
82
-
83
- def initialize opts
84
- @opts = opts
85
- end
86
-
87
- def execute
88
- raise ArgumentError, 'missing :exe' unless @opts.get :exe
89
- raise ArgumentError, 'missing :files' unless @opts.get :files
90
- @opts.get(:files).each do |dll|
91
- raise ArgumentError, "could not find test dll '#{dll}' in dir #{FileUtils.pwd}" unless File.exists? dll
92
- execute_tests_for dll
93
- end
94
- end
95
-
96
- private
97
- def execute_tests_for dll
98
- handle_directory dll, @opts.get(:exe) do |dir, exe|
99
- filename = File.basename dll
100
- cmd = Albacore::TestRunner::Cmd.new dir,
101
- exe, @opts.get(:parameters, []),
102
- filename,
103
- @opts.get(:clr_command)
104
- cmd.execute
105
- end
106
- end
107
- def handle_directory dll, exe, &block
108
- if @opts.get(:copy_local)
109
- # TODO: #mktmpdir is not always reliable; consider contributing a patch to ruby?
110
- # Fails sometimes with "directory already exists"
111
- Dir.mktmpdir 'alba-test' do |dir|
112
- sut, runners = Paths.join(dir, 'sut').to_s, Paths.join(dir, 'runners').to_s
113
- [sut, runners].each { |d| FileUtils.mkdir_p d }
114
-
115
- sut_glob = Paths.join(File.dirname(dll), '*').as_unix.to_s
116
- debug { "copying recursively from #{sut_glob} [test_runner #handle_directory]" }
117
- FileUtils.cp_r(Dir.glob(sut_glob), sut, :verbose => true)
118
-
119
- runners_glob = Paths.join(File.dirname(exe), '*').as_unix.to_s
120
- debug { "copying the runners form #{runners_glob} [test_runner #handle_directory]" }
121
- FileUtils.cp_r(Dir.glob(runners_glob), runners, :verbose => true)
122
-
123
- # call back with the new paths, easy because we have copied everything
124
- yield [sut, Paths.join(runners, File.basename(exe)).to_s]
125
- end
126
- else
127
- dir, exe =
128
- case File.dirname dll
129
- when /^\.\./
130
- # if the dll is negative to this Rakefile, use absolute paths
131
- [Pathname.new(File.absolute_path(dll)), Pathname.new(File.absolute_path(exe))]
132
- else
133
- # otherwise, please continue with the basics
134
- [Pathname.new(File.dirname(dll)), Pathname.new(exe)]
135
- end
136
-
137
- exe_rel = exe.relative_path_from dir
138
- yield [File.dirname(dll), exe_rel.to_s]
139
- end
140
- end
141
- end
142
- end
143
- end
1
+ require 'set'
2
+ require 'map'
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+ require 'pathname'
6
+ require 'albacore/cmd_config'
7
+ require 'albacore/cross_platform_cmd'
8
+
9
+ module Albacore
10
+ module TestRunner
11
+ # the configuration object for the test runner
12
+ class Config
13
+ include CmdConfig
14
+
15
+ # give this property the list of dlls you want to test
16
+ attr_writer :files
17
+
18
+ # constructor, no parameters
19
+ def initialize
20
+ @copy_local = false
21
+ @clr_command = true
22
+ @files = []
23
+ end
24
+
25
+ # Gets the configured options from the test runner configuration.
26
+ #
27
+ def opts
28
+ Map.new(
29
+ :files => files,
30
+ :copy_local => @copy_local,
31
+ :exe => @exe,
32
+ :parameters => @parameters,
33
+ :clr_command => @clr_command)
34
+ end
35
+
36
+ # Mark that it should be possible to copy the test files local
37
+ # -- this is great if you are running a VM and the host disk is
38
+ # mapped as a network drive, which crashes some test runners
39
+ def copy_local
40
+ @copy_local = true
41
+ end
42
+
43
+ # Call this on the confiuguration if you don't want 'mono' prefixed to the
44
+ # exe path on non-windows systems.
45
+ #
46
+ def native_exe
47
+ @clr_command = false
48
+ end
49
+
50
+ private
51
+ def files
52
+ if @files.respond_to? :each
53
+ @files
54
+ else
55
+ [@files]
56
+ end
57
+ end
58
+ end
59
+
60
+ class Cmd
61
+ include CrossPlatformCmd
62
+
63
+ # expects both parameters and executable to be relative to the
64
+ # work_dir parameter
65
+ def initialize work_dir, executable, parameters, file, clr_command = true
66
+ @work_dir, @executable = work_dir, executable
67
+ @parameters = parameters.to_a.unshift(file)
68
+ @clr_command = clr_command
69
+ end
70
+
71
+ def execute
72
+ info { "executing in directory './#{@work_dir}'" }
73
+ system @executable,
74
+ @parameters,
75
+ :work_dir => @work_dir,
76
+ :clr_command => @clr_command
77
+ end
78
+ end
79
+
80
+ class Task
81
+ include Logging
82
+
83
+ def initialize opts
84
+ @opts = opts
85
+ end
86
+
87
+ def execute
88
+ raise ArgumentError, 'missing :exe' unless @opts.get :exe
89
+ raise ArgumentError, 'missing :files' unless @opts.get :files
90
+ @opts.get(:files).each do |dll|
91
+ raise ArgumentError, "could not find test dll '#{dll}' in dir #{FileUtils.pwd}" unless File.exists? dll
92
+ execute_tests_for dll
93
+ end
94
+ end
95
+
96
+ private
97
+ def execute_tests_for dll
98
+ handle_directory dll, @opts.get(:exe) do |dir, exe|
99
+ filename = File.basename dll
100
+ cmd = Albacore::TestRunner::Cmd.new dir,
101
+ exe, @opts.get(:parameters, []),
102
+ filename,
103
+ @opts.get(:clr_command)
104
+ cmd.execute
105
+ end
106
+ end
107
+ def handle_directory dll, exe, &block
108
+ if @opts.get(:copy_local)
109
+ # TODO: #mktmpdir is not always reliable; consider contributing a patch to ruby?
110
+ # Fails sometimes with "directory already exists"
111
+ Dir.mktmpdir 'alba-test' do |dir|
112
+ sut, runners = Paths.join(dir, 'sut').to_s, Paths.join(dir, 'runners').to_s
113
+ [sut, runners].each { |d| FileUtils.mkdir_p d }
114
+
115
+ sut_glob = Paths.join(File.dirname(dll), '*').as_unix.to_s
116
+ debug { "copying recursively from #{sut_glob} [test_runner #handle_directory]" }
117
+ FileUtils.cp_r(Dir.glob(sut_glob), sut, :verbose => true)
118
+
119
+ runners_glob = Paths.join(File.dirname(exe), '*').as_unix.to_s
120
+ debug { "copying the runners form #{runners_glob} [test_runner #handle_directory]" }
121
+ FileUtils.cp_r(Dir.glob(runners_glob), runners, :verbose => true)
122
+
123
+ # call back with the new paths, easy because we have copied everything
124
+ yield [sut, Paths.join(runners, File.basename(exe)).to_s]
125
+ end
126
+ else
127
+ dir, exe =
128
+ case File.dirname dll
129
+ when /^\.\./
130
+ # if the dll is negative to this Rakefile, use absolute paths
131
+ [Pathname.new(File.absolute_path(dll)), Pathname.new(File.absolute_path(exe))]
132
+ else
133
+ # otherwise, please continue with the basics
134
+ [Pathname.new(File.dirname(dll)), Pathname.new(exe)]
135
+ end
136
+
137
+ exe_rel = exe.relative_path_from dir
138
+ yield [File.dirname(dll), exe_rel.to_s]
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -1,49 +1,49 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'semver'
4
- require 'albacore/logging'
5
-
6
- module Albacore
7
- module AlbaSemVer
8
- class Error < StandardError
9
- attr_reader :original
10
- def initialize msg, original
11
- raise ArgumentError, "original is nil" unless original
12
- super msg
13
- @original = original
14
- end
15
- def message
16
- %Q{#{super.to_s}
17
- #{@original.to_s}}
18
- end
19
- end
20
- class Cmd
21
- def initialize
22
- end
23
- def execute
24
- puts "TODO: execute versioning"
25
- end
26
- end
27
- class Config
28
- include Logging
29
-
30
- attr_accessor :tag
31
-
32
- def initialize
33
- begin
34
- @semver = SemVer.find
35
- rescue SemVerMissingError => e
36
- raise Error.new("could not find .semver file - please run 'semver init'", e)
37
- end
38
- end
39
- end
40
- class Task
41
- def initialize cmd
42
- @cmd = cmd
43
- end
44
- def execute
45
- @cmd.execute
46
- end
47
- end
48
- end
49
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'semver'
4
+ require 'albacore/logging'
5
+
6
+ module Albacore
7
+ module AlbaSemVer
8
+ class Error < StandardError
9
+ attr_reader :original
10
+ def initialize msg, original
11
+ raise ArgumentError, "original is nil" unless original
12
+ super msg
13
+ @original = original
14
+ end
15
+ def message
16
+ %Q{#{super.to_s}
17
+ #{@original.to_s}}
18
+ end
19
+ end
20
+ class Cmd
21
+ def initialize
22
+ end
23
+ def execute
24
+ puts "TODO: execute versioning"
25
+ end
26
+ end
27
+ class Config
28
+ include Logging
29
+
30
+ attr_accessor :tag
31
+
32
+ def initialize
33
+ begin
34
+ @semver = SemVer.find
35
+ rescue SemVerMissingError => e
36
+ raise Error.new("could not find .semver file - please run 'semver init'", e)
37
+ end
38
+ end
39
+ end
40
+ class Task
41
+ def initialize cmd
42
+ @cmd = cmd
43
+ end
44
+ def execute
45
+ @cmd.execute
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,150 @@
1
+ require 'rake'
2
+ require 'albacore/dsl'
3
+ require 'map'
4
+
5
+ module Albacore
6
+ module Tasks
7
+ # The published message on a finished release
8
+ #
9
+ class ReleaseData
10
+ # The semver that was released
11
+ #
12
+ attr_reader :semver
13
+
14
+ # The enumerable thing of artifacts that were created from the release
15
+ #
16
+ attr_reader :artifacts
17
+
18
+ # Create a new ReleaseData object with a semver (XSemVer::SemVer instance)
19
+ # and a list of artifacts
20
+ #
21
+ def initialize semver, artifacts
22
+ raise ArgumentError, 'missing "semver" argument' unless semver
23
+ raise ArgumentError, 'missing "artifacts" argument' unless artifacts
24
+ raise ArgumentError, '"artifacts" should respond to #each' unless artifacts.respond_to? :each
25
+ @semver = semver
26
+ @artifacts = artifacts
27
+ end
28
+ end
29
+
30
+ # Inspiration from: https://github.com/bundler/bundler/blob/master/lib/bundler/gem_helper.rb
31
+ #
32
+ class Release
33
+ include ::Rake::DSL
34
+ include ::Albacore::DSL
35
+
36
+ def initialize name = :release, opts = {}
37
+ @name = name
38
+ @opts = Map.new(opts).apply \
39
+ pkg_dir: 'build/pkg',
40
+ nuget_exe: 'tools/NuGet.exe',
41
+ nuget_source: 'https://www.nuget.org/api/v2/package',
42
+ clr_command: true,
43
+ depend_on: :versioning,
44
+ semver: nil
45
+ semver = @opts.get :semver
46
+
47
+ unless semver
48
+ ::Albacore.subscribe :build_version do |data|
49
+ @semver = data.semver
50
+ end
51
+ else
52
+ @semver = semver
53
+ end
54
+
55
+ install
56
+ end
57
+
58
+ # Installs the rake tasks under the 'release' namespace with a named task
59
+ # (given as the first parameter to the c'tor) that calls all subtasks.
60
+ #
61
+ def install
62
+ namespace :release do
63
+ desc 'ensure the tree is not dirty'
64
+ task :guard_clean => @opts.get(:depend_on) do
65
+ guard_clean
66
+ end
67
+
68
+ task :scm_write => @opts.get(:depend_on) do
69
+ tag_version { git_push } unless already_tagged?
70
+ end
71
+
72
+ task :nuget_push => @opts.get(:depend_on) do
73
+ packages = Dir.glob "#{@opts.get :pkg_dir}/*.#{@semver.format "%M.%m.%p"}.nupkg"
74
+ packages.each do |package|
75
+ nuget_push package
76
+ end
77
+ end
78
+ end
79
+
80
+ desc 'release current package(s)'
81
+ task @name => [:'release:guard_clean', :'release:scm_write', :'release:nuget_push']
82
+ end
83
+
84
+ protected
85
+ def run *cmd
86
+ block = lambda { |ok, status, output| [output, status] }
87
+ sh(*cmd, &block)
88
+ end
89
+
90
+ def nuget_push package
91
+ exe = @opts.get :nuget_exe
92
+ api_key = @opts.get :api_key
93
+ params = %W|push #{package}|
94
+ params << api_key if api_key
95
+ params << %W|-Source #{@opts.get :nuget_source}|
96
+ system exe, params, clr_command: @opts.get(:clr_command)
97
+ end
98
+
99
+ def git_push
100
+ perform_git_push
101
+ perform_git_push ' --tags'
102
+ info "Pushed git commits and tags."
103
+ end
104
+
105
+ def perform_git_push(options = '')
106
+ cmd = "git push #{options}"
107
+ out, code = run cmd
108
+ raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
109
+ end
110
+
111
+ def already_tagged?
112
+ tags = run('git tag', silent: true)[0].split(/\n/)
113
+ if tags.include? version_tag
114
+ warn "Tag #{version_tag} has already been created."
115
+ true
116
+ end
117
+ end
118
+
119
+ def guard_clean
120
+ clean? && committed? or raise("There are files that need to be committed first.")
121
+ end
122
+
123
+ def clean?
124
+ run('git diff --exit-code', silent: true)[1] == 0
125
+ end
126
+
127
+ def committed?
128
+ run('git diff-index --quiet --cached HEAD', silent: true)[1] == 0
129
+ end
130
+
131
+ def tag_version
132
+ system 'git', %W|tag -a -m Version\ #{@semver.format '%M.%m.%p'} #{version_tag}|, silent: true
133
+ info "Tagged #{version_tag}."
134
+ yield if block_given?
135
+ rescue
136
+ error "Untagging #{version_tag} due to error."
137
+ system 'git', %W|tag -d #{version_tag}|, silent: true
138
+ raise
139
+ end
140
+
141
+ def version_tag
142
+ @semver.to_s
143
+ end
144
+
145
+ def gem_push?
146
+ ! %w{n no nil false off 0}.include?(ENV['gem_push'].to_s.downcase)
147
+ end
148
+ end
149
+ end
150
+ end