Skip to content

Commit e146e84

Browse files
Merge pull request #12 from codecov/th/0.0.14
fix: make it smaller, and env, and 0.0.14
2 parents ad30c54 + 3a22531 commit e146e84

File tree

10 files changed

+166
-340
lines changed

10 files changed

+166
-340
lines changed

dist/codecov.sh

Lines changed: 56 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
CC_WRAPPER_VERSION="0.0.13"
2+
CC_WRAPPER_VERSION="0.0.14"
33
say() {
44
echo -e "$1"
55
}
@@ -11,6 +11,21 @@ exit_if_error() {
1111
exit 1;
1212
fi
1313
}
14+
lower() {
15+
echo $(echo $1 | sed 's/CC//' | sed 's/_/-//' | tr '[:upper:]' '[:lower:]')
16+
}
17+
write_existing_args() {
18+
if [ -n "$1" ];
19+
then
20+
echo " --$(lower $1) $(eval echo \$$1)"
21+
fi
22+
}
23+
write_truthy_args() {
24+
if [ "$1" = "true" ];
25+
then
26+
echo " --$(lower $1)"
27+
fi
28+
}
1429
b="\033[0;36m" # variables/constants
1530
g="\033[0;32m" # info/debug
1631
r="\033[0;31m" # errors
@@ -25,7 +40,6 @@ say " _____ _
2540
"
2641
CC_VERSION="${CC_VERSION:-latest}"
2742
CC_FAIL_ON_ERROR="${CC_FAIL_ON_ERROR:-false}"
28-
say
2943
if [ -n "$CC_BINARY" ];
3044
then
3145
if [ -f "$CC_BINARY" ];
@@ -90,113 +104,41 @@ CC_PUBLIC_PGP_KEY=$(curl https://keybase.io/codecovsecurity/pgp_keys.asc)
90104
say
91105
fi
92106
cc_cli_args=()
93-
if [ -n "$CC_AUTO_LOAD_PARAMS_FROM" ];
94-
then
95-
cc_cli_args+=( " --auto-load-params-from " "${CC_AUTO_LOAD_PARAMS_FROM}" )
96-
fi
97-
if [ -n "$CC_ENTERPRISE_URL" ];
98-
then
99-
cc_cli_args+=( " --enterprise-url " "${CC_ENTERPRISE_URL}" )
100-
fi
101-
unset CC_YML_PATH
102-
if [ -n "$CC_YML_PATH" ];
103-
then
104-
cc_cli_args+=( " --codecov-yml-path " "${CC_YML_PATH}" )
105-
fi
107+
cc_cli_args+=( $(write_existing_args CC_AUTO_LOAD_PARAMS_FROM) )
108+
cc_cli_args+=( $(write_existing_args CC_ENTERPRISE_URL) )
109+
cc_cli_args+=( $(write_existing_args CC_YML_PATH) )
106110
cc_cc_args=()
107-
if [ "$CC_FAIL_ON_ERROR" = "true" ];
108-
then
109-
cc_cc_args+=( " --fail-on-error" )
110-
fi
111-
if [ -n "$CC_GIT_SERVICE" ];
112-
then
113-
cc_cc_args+=( " --git-service " "${CC_GIT_SERVICE}" )
114-
fi
115-
if [ -n "$CC_PARENT_SHA" ];
116-
then
117-
cc_cc_args+=( " --parent-sha " "${CC_PARENT_SHA}" )
118-
fi
119-
if [ -n "$CC_PULL_REQUEST" ];
120-
then
121-
cc_cc_args+=( " --pr " "${CC_PULL_REQUEST}" )
122-
fi
123-
if [ -n "$CC_SHA" ];
124-
then
125-
cc_cc_args+=( " --sha " "${CC_SHA}" )
126-
fi
127-
if [ -n "$CC_SLUG" ];
128-
then
129-
cc_cc_args+=( " --slug " "${CC_SLUG}" )
130-
fi
111+
cc_cc_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
112+
cc_cc_args+=( $(write_existing_args CC_GIT_SERVICE) )
113+
cc_cc_args+=( $(write_existing_args CC_PARENT_SHA) )
114+
cc_cc_args+=( $(write_existing_args CC_PR) )
115+
cc_cc_args+=( $(write_existing_args CC_SHA) )
116+
cc_cc_args+=( $(write_existing_args CC_SLUG) )
131117
cc_create_report_args=()
132-
if [ -n "$CC_CODE" ];
133-
then
134-
cc_cr_args+=( " --code " "${CC_CODE}" )
135-
fi
136-
if [ "$CC_FAIL_ON_ERROR" = "true" ];
137-
then
138-
cc_cr_args+=( " --fail-on-error" )
139-
fi
140-
if [ -n "$CC_GIT_SERVICE" ];
141-
then
142-
cc_cr_args+=( " --git-service " "${CC_GIT_SERVICE}" )
143-
fi
144-
if [ -n "$CC_PULL_REQUEST" ];
145-
then
146-
cc_cr_args+=( " --pr " "${CC_PULL_REQUEST}" )
147-
fi
148-
if [ -n "$CC_SHA" ];
149-
then
150-
cc_cr_args+=( " --sha " "${CC_SHA}" )
151-
fi
152-
if [ -n "$CC_SLUG" ];
153-
then
154-
cc_cr_args+=( " --slug " "${CC_SLUG}" )
155-
fi
118+
cc_cr_args+=( $(write_existing_args CC_CODE) )
119+
cc_cr_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
120+
cc_cr_args+=( $(write_existing_args CC_GIT_SERVICE) )
121+
cc_cr_args+=( $(write_existing_args CC_PR) )
122+
cc_cr_args+=( $(write_existing_args CC_SHA) )
123+
cc_cr_args+=( $(write_existing_args CC_SLUG) )
156124
cc_du_args=()
157125
OLDIFS=$IFS;IFS=,
158-
if [ -n "$CC_BRANCH" ];
159-
then
160-
cc_du_args+=( " --branch " "${CC_BRANCH}" )
161-
fi
162-
if [ -n "$CC_BUILD" ];
163-
then
164-
cc_du_args+=( " --build " "${CC_BUILD}" )
165-
fi
166-
if [ -n "$CC_BUILD_URL" ];
167-
then
168-
cc_du_args+=( " --build-url " "${CC_BUILD_URL}" )
169-
fi
170-
if [ -n "$CC_CODE" ];
171-
then
172-
cc_du_args+=( " --code " "${CC_CODE}" )
173-
fi
174-
if [ "$CC_DISABLE_FILE_FIXES" = "true" ];
175-
then
176-
cc_du_args+=( " --disable-file-fixes" )
177-
fi
178-
if [ "$CC_DISABLE_SEARCH" = "true" ];
179-
then
180-
cc_du_args+=( " --disable-search" )
181-
fi
182-
if [ "$CC_DRY_RUN" = "true" ];
183-
then
184-
cc_du_args+=( " --dry-run" )
185-
fi
186-
if [ -n "$CC_ENV" ];
187-
then
188-
cc_du_args+=( " --env " "${CC_ENV}" )
189-
fi
190-
if [ -n "$CC_EXCLUDE_DIRS" ];
191-
then
192-
for directory in $CC_EXCLUDE_DIRS; do
126+
cc_du_args+=( $(write_existing_args CC_BRANCH) )
127+
cc_du_args+=( $(write_existing_args CC_BUILD) )
128+
cc_du_args+=( $(write_existing_args CC_BUILD_URL) )
129+
cc_du_args+=( $(write_existing_args CC_CODE) )
130+
cc_du_args+=( $(write_existing_args CC_DIR) )
131+
cc_du_args+=( $(write_truthy_args CC_DISABLE_FILE_FIXES) )
132+
cc_du_args+=( $(write_truthy_args CC_DISABLE_SEARCH) )
133+
cc_du_args+=( $(write_truthy_args CC_DRY_RUN) )
134+
cc_du_args+=( $(write_existing_args CC_ENV) )
135+
if [ -n "$CC_EXCLUDES" ];
136+
then
137+
for directory in $CC_EXCLUDES; do
193138
cc_du_args+=( " --exclude " "$directory" )
194139
done
195140
fi
196-
if [ "$CC_FAIL_ON_ERROR" = "true" ];
197-
then
198-
cc_du_args+=( " --fail-on-error" )
199-
fi
141+
cc_du_args+=( $(write_truthy_args CC_FAIL_ON_ERROR) )
200142
if [ -n "$CC_FILES" ];
201143
then
202144
for file in $CC_FILES; do
@@ -209,64 +151,24 @@ then
209151
cc_du_args+=( " --flag " "$flag" )
210152
done
211153
fi
212-
if [ -n "$CC_GIT_SERVICE" ];
213-
then
214-
cc_du_args+=( " --git-service " "${CC_GIT_SERVICE}" )
215-
fi
216-
if [ "$CC_HANDLE_NO_REPORTS_FOUND" = "true" ];
217-
then
218-
cc_du_args+=( " --handle-no-reports-found" )
219-
fi
220-
if [ -n "$CC_JOB_CODE" ];
221-
then
222-
cc_du_args+=( " --job-code " "${CC_JOB_CODE}" )
223-
fi
224-
if [ "$CC_LEGACY" = "true" ];
225-
then
226-
cc_du_args+=( " --legacy" )
227-
fi
228-
if [ -n "$CC_NAME" ];
229-
then
230-
cc_du_args+=( " --name " "${CC_NAME}" )
231-
fi
232-
if [ -n "$CC_NETWORK_FILTER" ];
233-
then
234-
cc_du_args+=( " --network-filter " "${CC_NETWORK_FILTER}" )
235-
fi
236-
if [ -n "$CC_NETWORK_PREFIX" ];
237-
then
238-
cc_du_args+=( " --network-prefix " "${CC_NETWORK_PREFIX}" )
239-
fi
240-
if [ -n "$CC_NETWORK_ROOT_FOLDER" ];
241-
then
242-
cc_du_args+=( " --network-root-folder " "${CC_NETWORK_ROOT_FOLDER}" )
243-
fi
154+
cc_du_args+=( $(write_existing_args CC_GIT_SERVICE) )
155+
cc_du_args+=( $(write_truthy_args CC_HANDLE_NO_REPORTS_FOUND) )
156+
cc_du_args+=( $(write_existing_args CC_JOB_CODE) )
157+
cc_du_args+=( $(write_truthy_args CC_LEGACY) )
158+
cc_du_args+=( $(write_existing_args CC_NAME) )
159+
cc_du_args+=( $(write_existing_args CC_NETWORK_FILTER) )
160+
cc_du_args+=( $(write_existing_args CC_NETWORK_PREFIX) )
161+
cc_du_args+=( $(write_existing_args CC_NETWORK_ROOT_FOLDER) )
244162
if [ -n "$CC_PLUGINS" ];
245163
then
246164
for plugin in $CC_PLUGINS; do
247165
cc_du_args+=( " --plugin " "$plugin" )
248166
done
249167
fi
250-
if [ -n "$CC_PULL_REQUEST" ];
251-
then
252-
cc_du_args+=( " --pr " "${CC_PULL_REQUEST}" )
253-
fi
254-
if [ -n "$CC_REPORT_TYPE" ];
255-
then
256-
cc_du_args+=( " --report-type " "${CC_REPORT_TYPE}" )
257-
fi
258-
if [ -n "$CC_SEARCH_DIR" ];
259-
then
260-
cc_du_args+=( " --coverage-files-search-root-folder " "${CC_SEARCH_DIR}" )
261-
fi
262-
if [ -n "$CC_SHA" ];
263-
then
264-
cc_du_args+=( " --sha " "${CC_SHA}" )
265-
fi
266-
if [ -n "$CC_SLUG" ];
267-
then
268-
cc_du_args+=( " --slug " "${CC_SLUG}" )
269-
fi
168+
cc_du_args+=( $(write_existing_args CC_PR) )
169+
cc_du_args+=( $(write_existing_args CC_REPORT_TYPE) )
170+
cc_du_args+=( $(write_existing_args CC_SHA) )
171+
cc_du_args+=( $(write_existing_args CC_SLUG) )
270172
IFS=$OLDIFS
271173
unset NODE_OPTIONS
272174
# See https://github.com/codecov/uploader/issues/475

env

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
CC_AUTO_LOAD_PARAMS_FROM
3+
CC_BINARY
4+
CC_BRANCH
5+
CC_BUILD
6+
CC_BUILD_URL
7+
CC_CODE
8+
CC_DIR
9+
CC_DISABLE_FILE_FIXES
10+
CC_DISABLE_SEARCH
11+
CC_DRY_RUN
12+
CC_ENTERPRISE_URL
13+
CC_ENV
14+
CC_EXCLUDES
15+
CC_FAIL_ON_ERROR
16+
CC_FILES
17+
CC_FLAGS
18+
CC_GIT_SERVICE
19+
CC_HANDLE_NO_REPORTS_FOUND
20+
CC_JOB_CODE
21+
CC_LEGACY
22+
CC_NAME
23+
CC_NETWORK_FILTER
24+
CC_NETWORK_PREFIX
25+
CC_NETWORK_ROOT_FOLDER
26+
CC_PARENT_SHA
27+
CC_PLUGINS
28+
CC_PR
29+
CC_PUBLIC_PGP_KEY
30+
CC_REPORT_TYPE
31+
CC_SHA
32+
CC_SKIP_VALIDATION
33+
CC_SLUG
34+
CC_TOKEN
35+
CC_TOKEN_VAR
36+
CC_VERSION
37+
CC_WRAPPER_VERSION
38+
CC_YML_PATH

package.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,31 @@ def package_scripts(source_dir, source_root, outfile):
99
cwd = os.getcwd()
1010
lines = _parse(os.path.join(cwd, source_dir, source_root))
1111

12+
cc_vars = set()
1213
with open(outfile, 'w') as f:
1314
f.write(BASH_LINE)
1415
for line in lines:
16+
cc_vars.update(_get_vars(line))
1517
f.write(line)
1618

1719
st = os.stat(outfile)
1820
os.chmod(outfile, st.st_mode | stat.S_IEXEC)
1921

22+
with open('env', 'w') as f:
23+
sorted_vars = sorted(list(cc_vars))
24+
for var in sorted_vars:
25+
f.write(f'{var}\n')
26+
2027
print(f"Current script is {len(''.join(lines))} chars.")
2128
if len(''.join(lines)) > 8192:
2229
print("Due to windows limitiations, script must be under 8192 chars.")
2330
exit(1)
2431

32+
def _get_vars(line):
33+
matcher = r'(CC_[^\r\n\t\f\v=]+)*'
34+
matcher = r'(CC_[\w_]+)*'
35+
return re.findall(matcher, line)
36+
2537
def _parse(file):
2638
lines = []
2739
with open(file, 'r') as f:

scripts/envs

Whitespace-only changes.

scripts/set_cli_args.sh

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
codecov_cli_args=()
44

5-
if [ -n "$CODECOV_AUTO_LOAD_PARAMS_FROM" ];
6-
then
7-
codecov_cli_args+=( " --auto-load-params-from " "${CODECOV_AUTO_LOAD_PARAMS_FROM}" )
8-
fi
9-
10-
if [ -n "$CODECOV_ENTERPRISE_URL" ];
11-
then
12-
codecov_cli_args+=( " --enterprise-url " "${CODECOV_ENTERPRISE_URL}" )
13-
fi
14-
15-
unset CODECOV_YML_PATH
16-
if [ -n "$CODECOV_YML_PATH" ];
17-
then
18-
codecov_cli_args+=( " --codecov-yml-path " "${CODECOV_YML_PATH}" )
19-
fi
20-
5+
codecov_cli_args+=( $(write_existing_args CODECOV_AUTO_LOAD_PARAMS_FROM) )
6+
codecov_cli_args+=( $(write_existing_args CODECOV_ENTERPRISE_URL) )
7+
codecov_cli_args+=( $(write_existing_args CODECOV_YML_PATH) )

scripts/set_create_commit_args.sh

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,9 @@
22

33
codecov_cc_args=()
44

5-
if [ "$CODECOV_FAIL_ON_ERROR" = "true" ];
6-
then
7-
codecov_cc_args+=( " --fail-on-error" )
8-
fi
9-
10-
if [ -n "$CODECOV_GIT_SERVICE" ];
11-
then
12-
codecov_cc_args+=( " --git-service " "${CODECOV_GIT_SERVICE}" )
13-
fi
14-
15-
if [ -n "$CODECOV_PARENT_SHA" ];
16-
then
17-
codecov_cc_args+=( " --parent-sha " "${CODECOV_PARENT_SHA}" )
18-
fi
19-
20-
if [ -n "$CODECOV_PULL_REQUEST" ];
21-
then
22-
codecov_cc_args+=( " --pr " "${CODECOV_PULL_REQUEST}" )
23-
fi
24-
25-
if [ -n "$CODECOV_SHA" ];
26-
then
27-
codecov_cc_args+=( " --sha " "${CODECOV_SHA}" )
28-
fi
29-
30-
if [ -n "$CODECOV_SLUG" ];
31-
then
32-
codecov_cc_args+=( " --slug " "${CODECOV_SLUG}" )
33-
fi
5+
codecov_cc_args+=( $(write_truthy_args CODECOV_FAIL_ON_ERROR) )
6+
codecov_cc_args+=( $(write_existing_args CODECOV_GIT_SERVICE) )
7+
codecov_cc_args+=( $(write_existing_args CODECOV_PARENT_SHA) )
8+
codecov_cc_args+=( $(write_existing_args CODECOV_PR) )
9+
codecov_cc_args+=( $(write_existing_args CODECOV_SHA) )
10+
codecov_cc_args+=( $(write_existing_args CODECOV_SLUG) )

0 commit comments

Comments
 (0)