-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
227 lines (192 loc) · 4.64 KB
/
Rakefile
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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# frozen_string_literal: true
require 'confidante'
require 'lino'
require 'rake_git'
require 'rubocop/rake_task'
require 'tempfile'
require 'yaml'
task default: %i[
build:code:fix
library:dependencies:install
library:lint:fix
library:type:check
library:format:fix
library:build
library:test:all
]
task check: %i[
build:code:check
library:dependencies:install
library:lint:check
library:type:check
library:format:check
library:build
library:test:all
]
namespace :git do
RakeGit.define_commit_task(
argument_names: [:message]
) do |t, args|
t.message = args.message
end
end
RuboCop::RakeTask.new
namespace :build do
namespace :code do
desc 'Run all checks on the test code'
task check: [:rubocop]
desc 'Attempt to automatically fix issues with the test code'
task fix: [:'rubocop:autocorrect_all']
end
end
namespace :poetry do
desc 'Login to PyPI'
task :login_to_pypi, [:api_token] do |_, args|
invoke_poetry_command(
'config', 'pypi-token.pypi', args.api_token
)
end
end
namespace :library do
desc 'Run all checks'
task check: %i[lint:check format:check type:check]
desc 'Run and fix all checks'
task fix: %i[lint:fix format:fix type:check]
namespace :dependencies do
desc 'Install dependencies'
task :install do
invoke_poetry_command('install')
end
end
task build: %i[dependencies:install] do
invoke_poetry_command('build')
end
namespace :lint do
desc 'Check linting'
task check: %i[dependencies:install] do
invoke_poetry_task('lint-check')
end
desc 'Fix linting'
task fix: %i[dependencies:install] do
invoke_poetry_task('lint-fix')
end
end
namespace :format do
desc 'Check formatting'
task check: %i[dependencies:install] do
invoke_poetry_task('format-check')
end
desc 'Fix formatting'
task fix: %i[dependencies:install] do
invoke_poetry_task('format-fix')
end
end
namespace :type do
desc 'Check types'
task check: %i[dependencies:install] do
invoke_poetry_task('type-check')
end
end
namespace :test do
desc 'Run unit tests'
task :unit, [
:filter
] => %i[dependencies:install] do |_, args|
arguments = args[:filter] ? ['--filter', args[:filter].to_s] : []
invoke_poetry_task('test-unit', *arguments)
end
desc 'Run report aggregation'
task report: %i[dependencies:install] do
invoke_poetry_task('test-report')
end
desc 'Run all tests'
task all: %i[unit report]
end
namespace :version do
desc 'Bump version'
task :bump, [:type] do |_, args|
args.with_defaults(type: 'patch')
invoke_poetry_command('version', args.type)
end
end
desc 'Publish library'
task :publish do
invoke_poetry_command('publish', '--build')
end
namespace :publish do
desc 'Publish prerelease version'
task :prerelease do
Rake::Task['library:version:bump'].invoke('prerelease')
Rake::Task['library:publish'].invoke
end
desc 'Publish release version'
task :release do
Rake::Task['library:version:bump'].invoke('patch')
Rake::Task['library:publish'].invoke
end
end
end
namespace :repository do
desc 'Sets the git author for CI'
task :set_ci_author do
Lino
.builder_for_command('git')
.with_subcommand('config') do |sub|
sub.with_flag('--global')
.with_option('user.name', 'InfraBlocks CI')
end
.build
.execute
Lino
.builder_for_command('git')
.with_subcommand('config') do |sub|
sub.with_flag('--global')
.with_option('user.email', '[email protected]')
end
.build
.execute
end
desc 'commits the version bump'
task :commit_release do
version = read_poetry_version
Lino
.builder_for_command('git')
.with_subcommand('commit') do |sub|
sub.with_flag('-a')
.with_option(
'-m',
"\"Bump version to #{version} for prerelease [no ci]\""
)
end
.build
.execute
end
desc 'pushes the branch'
task :push do
Lino
.builder_for_command('git')
.with_subcommand('push')
.build
.execute
end
end
def read_poetry_version
stdout = Tempfile.new
Lino
.builder_for_command('poetry')
.with_arguments(['version'])
.build
.execute(stdout: stdout)
stdout.rewind
stdout.read.split[1]
end
def invoke_poetry_task(task_name, *args)
invoke_poetry_command('run', 'poe', task_name, *args)
end
def invoke_poetry_command(command, *args)
Lino
.builder_for_command('poetry')
.with_subcommands([command, *args])
.build
.execute
end