summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSudarsana Babu Nagineni <sudarsana.babu@mapbox.com>2019-03-28 15:10:00 +0200
committerSudarsana Babu Nagineni <sudarsana.babu@mapbox.com>2019-03-29 14:31:44 +0200
commit4adfc5d3237bbca5c07898104267b17309f24ff3 (patch)
tree281f5e94aa7498cf984f652f07217e8f8c10552a
parent43f27e837cb444ba4263405aa4c39a651b222067 (diff)
downloadqtlocation-mapboxgl-4adfc5d3237bbca5c07898104267b17309f24ff3.tar.gz
[scripts] Add retry logic to fetch coverage report
Retry fetching coverage report from codecov in case of timeout issues.
-rwxr-xr-xscripts/publish_core_codecoverage.js39
1 files changed, 26 insertions, 13 deletions
diff --git a/scripts/publish_core_codecoverage.js b/scripts/publish_core_codecoverage.js
index b490a2fee7..43de662a13 100755
--- a/scripts/publish_core_codecoverage.js
+++ b/scripts/publish_core_codecoverage.js
@@ -121,7 +121,7 @@ function httpRequest() {
reject(error);
}).on('end', () => {
if (res.statusCode < 200 || res.statusCode >= 300) {
- return reject(new Error('Failed to fetch the results from codecov.io. StatusCode=' + res.statusCode));
+ return reject(new Error('Failed to fetch coverage report from codecov.io. StatusCode=' + res.statusCode));
}
try {
@@ -143,15 +143,28 @@ function httpRequest() {
});
}
-httpRequest().then((body) => {
- const dataSource = parseResponse(body);
- if (dataSource) {
- return uploadData(dataSource);
- } else {
- throw new Error('Failed to parse the results received from codecov.io.');
- }
-}).then(data => {
- console.log('Successfully uploaded code coverage metrics to S3');
-}).catch(err => {
- console.error('Failed to upload code coverage metrics to S3: ' + err.message);
-});
+var errResponse = false;
+const publishWithRetry = (maxRetries) => {
+ httpRequest().then((body) => {
+ const dataSource = parseResponse(body);
+ if (dataSource) {
+ return uploadData(dataSource);
+ } else {
+ errResponse = true;
+ throw new Error('Failed to parse coverage report received from codecov.io.');
+ }
+ }).then(data => {
+ console.log('Successfully uploaded code coverage metrics to S3');
+ }).catch(err => {
+ if (maxRetries > 1 && errResponse) {
+ console.log('Invalid coverage report received. Trying to retrieve again.');
+ errResponse = false;
+ return publishWithRetry(maxRetries - 1);
+ }
+
+ console.error('Failed to upload code coverage metrics to S3: ' + err.message);
+ });
+};
+
+// Fetch and publish code coverage report
+publishWithRetry(5);