File tree Expand file tree Collapse file tree 4 files changed +76
-16
lines changed Expand file tree Collapse file tree 4 files changed +76
-16
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,26 @@ Following tasks are generated
69
69
* ` rake go5:testrace `
70
70
* ` rake go5:fmt `
71
71
72
+ #### Example (Add additional tasks)
73
+ ``` ruby
74
+ # Rakefile
75
+ require " go_gem/rake_task"
76
+
77
+ go_task = GoGem ::RakeTask .new (" gem_name" )
78
+
79
+ namespace :go do
80
+ desc " Run golangci-lint"
81
+ task :lint do
82
+ go_task.within_target_dir do
83
+ sh " which golangci-lint" do |ok , _ |
84
+ raise " golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
85
+ end
86
+ sh GoGem ::RakeTask .build_env_vars, " golangci-lint run"
87
+ end
88
+ end
89
+ end
90
+ ```
91
+
72
92
#### Available configurations
73
93
* ` task_namespace ` : task namespace (default: ` :go ` )
74
94
* ` go_bin_path ` : path to go binary (default: ` "go" ` )
Original file line number Diff line number Diff line change @@ -22,6 +22,24 @@ module GoGem
22
22
# t.go_test_args = "-mod=readonly"
23
23
# t.target_dir = "/dir/to/go-mod/"
24
24
# end
25
+ #
26
+ # @example additional tasks
27
+ # # Rakefile
28
+ # require "go_gem/rake_task"
29
+ #
30
+ # t = GoGem::RakeTask.new("gem_name")
31
+ #
32
+ # namespace :go do
33
+ # desc "Run golangci-lint"
34
+ # task :lint do
35
+ # t.within_target_dir do
36
+ # sh "which golangci-lint" do |ok, _|
37
+ # raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
38
+ # end
39
+ # sh GoGem::RakeTask.build_env_vars, "golangci-lint run"
40
+ # end
41
+ # end
42
+ # end
25
43
class RakeTask < ::Rake ::TaskLib
26
44
DEFAULT_TASK_NAMESPACE = :go
27
45
@@ -110,6 +128,18 @@ def self.build_env_vars
110
128
}
111
129
end
112
130
131
+ # @yield
132
+ def within_target_dir
133
+ Dir . chdir ( target_dir ) do # rubocop:disable Style/ExplicitBlockArgument
134
+ yield
135
+ end
136
+ end
137
+
138
+ # @return [String]
139
+ def ext_dir
140
+ File . join ( "ext" , gem_name )
141
+ end
142
+
113
143
private
114
144
115
145
def define_go_test_task
@@ -138,17 +168,5 @@ def define_go_fmt_task
138
168
end
139
169
end
140
170
end
141
-
142
- # @yield
143
- def within_target_dir
144
- Dir . chdir ( target_dir ) do # rubocop:disable Style/ExplicitBlockArgument
145
- yield
146
- end
147
- end
148
-
149
- # @return [String]
150
- def ext_dir
151
- File . join ( "ext" , gem_name )
152
- end
153
171
end
154
172
end
Original file line number Diff line number Diff line change 17
17
it { should be_task_defined ( "go:test" ) }
18
18
it { should be_task_defined ( "go:testrace" ) }
19
19
it { should be_task_defined ( "go:fmt" ) }
20
+
21
+ describe "Add additional tasks" do
22
+ include Rake ::DSL
23
+
24
+ subject do
25
+ t = GoGem ::RakeTask . new ( gem_name )
26
+
27
+ namespace :go do
28
+ task :test2 do
29
+ t . within_target_dir do
30
+ sh "go test"
31
+ end
32
+ end
33
+ end
34
+
35
+ Rake ::Task
36
+ end
37
+
38
+ it { should be_task_defined ( "go:test2" ) }
39
+ end
20
40
end
21
41
22
42
context "with params" do
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
- GoGem ::RakeTask . new ( "" ) do |t |
3
+ go_task = GoGem ::RakeTask . new ( "" ) do |t |
4
4
t . target_dir = repo_root
5
5
t . go_test_args = "#{ GoGem ::RakeTask ::DEFAULT_GO_TEST_ARGS } #{ ENV [ "GO_TEST_ARGS" ] } "
6
6
end
7
7
8
8
namespace :go do
9
9
desc "Run golangci-lint"
10
10
task :lint do
11
- sh "which golangci-lint" do |ok , _ |
12
- raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
11
+ go_task . within_target_dir do
12
+ sh "which golangci-lint" do |ok , _ |
13
+ raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
14
+ end
15
+ sh GoGem ::RakeTask . build_env_vars , "golangci-lint run"
13
16
end
14
- sh GoGem ::RakeTask . build_env_vars , "golangci-lint run"
15
17
end
16
18
17
19
desc "Run all build tasks in go"
You can’t perform that action at this time.
0 commit comments