-
Notifications
You must be signed in to change notification settings - Fork 194
/
index.ts
79 lines (71 loc) · 2.1 KB
/
index.ts
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
const core = require('@actions/core');
const exec = require('@actions/exec');
const fs = require('fs');
const request = require('requestretry');
import buildExec from './buildExec';
import validateUploader from './validate';
let failCi;
try {
request({
json: false,
maxAttempts: 10,
timeout: 3000,
url: 'https://codecov.io/bash',
}, async (error, response, body) => {
const {execArgs, options, filepath, failCi} = buildExec();
try {
const isValid = validateUploader(body);
if (!isValid) {
const failure = 'Codecov failure: ' +
'Bash script checksums do not match published values. ' +
'Please contact security@codecov.io immediately.';
core.setFailed(failure);
throw new Error(failure);
}
if (error && failCi) {
throw error;
} else if (error) {
core.warning(`Codecov warning: ${error.message}`);
}
fs.writeFile(filepath, body, (err) => {
if (err && failCi) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
}
exec.exec('bash', execArgs, options)
.catch((err) => {
if (failCi) {
core.setFailed(
`Codecov failed with the following error: ${err.message}`,
);
} else {
core.warning(`Codecov warning: ${err.message}`);
}
})
.then(() => {
unlinkFile();
});
const unlinkFile = () => {
fs.unlink(filepath, (err) => {
if (err && failCi) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
}
});
};
});
} catch (error) {
core.setFailed(
`Codecov failed with the following error: ${error.message}`,
);
}
});
} catch (error) {
if (failCi) {
core.setFailed(`Codecov failed with the following error: ${error.message}`);
} else {
core.warning(`Codecov warning: ${error.message}`);
}
}