-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathupload.py
307 lines (296 loc) · 9.9 KB
/
upload.py
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import logging
import os
import pathlib
import typing
import click
import sentry_sdk
from codecov_cli.fallbacks import CodecovOption, FallbackFieldEnum
from codecov_cli.helpers.args import get_cli_args
from codecov_cli.helpers.options import global_options
from codecov_cli.services.upload import do_upload_logic
from codecov_cli.types import CommandContext
from codecov_cli.helpers.upload_type import report_type_from_str, ReportType
logger = logging.getLogger("codecovcli")
def _turn_env_vars_into_dict(ctx, params, value):
return dict((v, os.getenv(v, None)) for v in value)
_global_upload_options = [
click.option(
"--code",
"--report-code",
"report_code",
help="The code of the report. If unsure, leave default",
default="default",
),
click.option(
"--network-root-folder",
help="Root folder from which to consider paths on the network section",
type=click.Path(path_type=pathlib.Path),
default=pathlib.Path.cwd,
show_default="Current working directory",
),
click.option(
"-s",
"--dir",
"--coverage-files-search-root-folder",
"--files-search-root-folder",
"files_search_root_folder",
help="Folder where to search for coverage files",
type=click.Path(path_type=pathlib.Path),
default=pathlib.Path.cwd,
show_default="Current Working Directory",
),
click.option(
"--exclude",
"--coverage-files-search-exclude-folder",
"--files-search-exclude-folder",
"files_search_exclude_folders",
help="Folders to exclude from search",
type=click.Path(path_type=pathlib.Path),
multiple=True,
default=[],
),
click.option(
"-f",
"--file",
"--coverage-files-search-direct-file",
"--files-search-direct-file",
"files_search_explicitly_listed_files",
help="Explicit files to upload. These will be added to the coverage files found for upload. If you wish to only upload the specified files, please consider using --disable-search to disable uploading other files.",
type=click.Path(path_type=pathlib.Path),
multiple=True,
default=[],
),
click.option(
"--disable-search",
help="Disable search for coverage files. This is helpful when specifying what files you want to upload with the --file option.",
is_flag=True,
default=False,
),
click.option(
"--disable-file-fixes",
help="Disable file fixes to ignore common lines from coverage (e.g. blank lines or empty brackets)",
is_flag=True,
default=False,
),
click.option(
"-b",
"--build",
"--build-code",
"build_code",
cls=CodecovOption,
help="Specify the build number manually",
fallback_field=FallbackFieldEnum.build_code,
),
click.option(
"--build-url",
"build_url",
cls=CodecovOption,
help="The URL of the build where this is running",
fallback_field=FallbackFieldEnum.build_url,
),
click.option(
"--job-code",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.job_code,
),
click.option(
"-n",
"--name",
help="Custom defined name of the upload. Visible in Codecov UI",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.build_code,
),
click.option(
"-B",
"--branch",
help="Branch to which this commit belongs to",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.branch,
),
click.option(
"-P",
"--pr",
"--pull-request-number",
"pull_request_number",
help="Specify the pull request number mannually. Used to override pre-existing CI environment variables",
cls=CodecovOption,
fallback_field=FallbackFieldEnum.pull_request_number,
),
click.option(
"-e",
"--env",
"--env-var",
"env_vars",
multiple=True,
callback=_turn_env_vars_into_dict,
help="Specify environment variables to be included with this build.",
),
click.option(
"-F",
"--flag",
"flags",
multiple=True,
default=[],
help="Flag the upload to group coverage metrics. Multiple flags allowed.",
),
click.option(
"--plugin",
"plugin_names",
multiple=True,
default=["xcode", "gcov", "pycoverage"],
),
click.option(
"-d",
"--dry-run",
"dry_run",
is_flag=True,
help="Don't upload files to Codecov",
),
click.option(
"--legacy",
"--use-legacy-uploader",
"use_legacy_uploader",
is_flag=True,
help="Use the legacy upload endpoint",
),
click.option(
"--handle-no-reports-found",
"handle_no_reports_found",
is_flag=True,
help="Raise no exceptions when no coverage reports found.",
),
click.option(
"--report-type",
"report_type_str",
help="The type of the file to upload, coverage by default. Possible values are: testing, coverage.",
default="coverage",
type=click.Choice(["coverage", "test_results"]),
),
click.option(
"--network-filter",
help="Specify a filter on the files listed in the network section of the Codecov report. This will only add files whose path begin with the specified filter. Useful for upload-specific path fixing",
),
click.option(
"--network-prefix",
help="Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing",
),
click.option(
"--gcov-args",
help="Extra arguments to pass to gcov",
),
click.option(
"--gcov-ignore",
help="Paths to ignore during gcov gathering",
),
click.option(
"--gcov-include",
help="Paths to include during gcov gathering",
),
click.option(
"--gcov-executable",
help="gcov executable to run. Defaults to 'gcov'",
),
click.option(
"--swift-project",
help="Specify the swift project",
),
]
def global_upload_options(func):
for option in reversed(_global_upload_options):
func = option(func)
return func
@click.command()
@global_upload_options
@global_options
@click.pass_context
def do_upload(
ctx: CommandContext,
commit_sha: str,
report_code: str,
branch: typing.Optional[str],
build_code: typing.Optional[str],
build_url: typing.Optional[str],
disable_file_fixes: bool,
disable_search: bool,
dry_run: bool,
env_vars: typing.Dict[str, str],
fail_on_error: bool,
files_search_exclude_folders: typing.List[pathlib.Path],
files_search_explicitly_listed_files: typing.List[pathlib.Path],
files_search_root_folder: pathlib.Path,
flags: typing.List[str],
gcov_args: typing.Optional[str],
gcov_executable: typing.Optional[str],
gcov_ignore: typing.Optional[str],
gcov_include: typing.Optional[str],
git_service: typing.Optional[str],
handle_no_reports_found: bool,
job_code: typing.Optional[str],
name: typing.Optional[str],
network_filter: typing.Optional[str],
network_prefix: typing.Optional[str],
network_root_folder: pathlib.Path,
plugin_names: typing.List[str],
pull_request_number: typing.Optional[str],
report_type_str: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
token: typing.Optional[str],
use_legacy_uploader: bool,
):
with sentry_sdk.start_transaction(op="task", name="Do Upload"):
with sentry_sdk.start_span(name="do_upload"):
versioning_system = ctx.obj["versioning_system"]
codecov_yaml = ctx.obj["codecov_yaml"] or {}
cli_config = codecov_yaml.get("cli", {})
ci_adapter = ctx.obj.get("ci_adapter")
enterprise_url = ctx.obj.get("enterprise_url")
args = get_cli_args(ctx)
logger.debug(
"Starting upload processing",
extra=dict(
extra_log_attributes=args,
),
)
report_type: ReportType = report_type_from_str(report_type_str)
do_upload_logic(
cli_config,
versioning_system,
ci_adapter,
branch=branch,
build_code=build_code,
build_url=build_url,
commit_sha=commit_sha,
disable_file_fixes=disable_file_fixes,
disable_search=disable_search,
dry_run=dry_run,
enterprise_url=enterprise_url,
env_vars=env_vars,
fail_on_error=fail_on_error,
files_search_exclude_folders=list(files_search_exclude_folders),
files_search_explicitly_listed_files=list(
files_search_explicitly_listed_files
),
files_search_root_folder=files_search_root_folder,
flags=flags,
gcov_args=gcov_args,
gcov_executable=gcov_executable,
gcov_ignore=gcov_ignore,
gcov_include=gcov_include,
git_service=git_service,
handle_no_reports_found=handle_no_reports_found,
job_code=job_code,
name=name,
network_filter=network_filter,
network_prefix=network_prefix,
network_root_folder=network_root_folder,
plugin_names=plugin_names,
pull_request_number=pull_request_number,
report_code=report_code,
slug=slug,
swift_project=swift_project,
token=token,
report_type=report_type,
use_legacy_uploader=use_legacy_uploader,
args=args,
)