Skip to content
Permalink
Browse files
Wrap request promise in try catch
  • Loading branch information
thomasrockhu committed Jul 17, 2020
1 parent e16d515 commit 8ddda09c145dc2a260658d97cb29242e3c25a332
Showing with 208 additions and 196 deletions.
  1. +1 −1 LICENSE
  2. +103 −97 dist/index.js
  3. +102 −96 index.js
  4. +1 −1 package-lock.json
  5. +1 −1 package.json
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Codecov
Copyright (c) 2019-2020 Codecov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -2236,121 +2236,127 @@ try {
url: "https://codecov.io/bash",
json: false
}, (error, response, body) => {
if (error && fail_ci) {
throw error;
} else if (error) {
core.warning(`Codecov warning: ${error.message}`);
}
try {
if (error && fail_ci) {
throw error;
} else if (error) {
core.warning(`Codecov warning: ${error.message}`);
}

fs.writeFile("codecov.sh", body, err => {
if (err && fail_ci) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
}

let output = "";
let execError = "";
const options = {};
options.listeners = {
stdout: data => {
output += data.toString();
},
stderr: data => {
execError += data.toString();
}
};

fs.writeFile("codecov.sh", body, err => {
if (err && fail_ci) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
}
options.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
GITHUB_REF: process.env.GITHUB_REF,
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY,
GITHUB_SHA: process.env.GITHUB_SHA,
GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || ''
});

let output = "";
let execError = "";
const options = {};
options.listeners = {
stdout: data => {
output += data.toString();
},
stderr: data => {
execError += data.toString();
if(token){
options.env.CODECOV_TOKEN = token
}
};

options.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
GITHUB_REF: process.env.GITHUB_REF,
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY,
GITHUB_SHA: process.env.GITHUB_SHA,
GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || ''
});

if(token){
options.env.CODECOV_TOKEN = token
}
const env_vars_arg = []
for (let env_var of env_vars.split(",")) {
let env_var_clean = env_var.trim();
if (env_var_clean) {
options.env[env_var_clean] = process.env[env_var_clean];
env_vars_arg.push(env_var_clean)
}
}

const env_vars_arg = []
for (let env_var of env_vars.split(",")) {
let env_var_clean = env_var.trim();
if (env_var_clean) {
options.env[env_var_clean] = process.env[env_var_clean];
env_vars_arg.push(env_var_clean)
const execArgs = ["codecov.sh"];
if (file) {
execArgs.push(
"-f", `${file}`
);
}
}

const execArgs = ["codecov.sh"];
if (file) {
execArgs.push(
"-f", `${file}`
);
}
if (files) {
files.split(',').forEach(f => {
execArgs.push(
"-f", `${f}`
);
});
}

if (files) {
files.split(',').forEach(f => {
if (dir) {
execArgs.push(
"-f", `${f}`
"-s", `${dir}`
);
});
}
}

if (dir) {
execArgs.push(
"-s", `${dir}`
"-n", `${name}`,
"-F", `${flags}`
);
}

execArgs.push(
"-n", `${name}`,
"-F", `${flags}`
);

if (fail_ci) {
execArgs.push(
"-Z"
);
}
if (fail_ci) {
execArgs.push(
"-Z"
);
}

if (env_vars_arg.length) {
execArgs.push(
"-e", env_vars_arg.join(",")
);
}
if (env_vars_arg.length) {
execArgs.push(
"-e", env_vars_arg.join(",")
);
}

if (write_path) {
execArgs.push(
"-q", `${write_path}`
);
}
if (write_path) {
execArgs.push(
"-q", `${write_path}`
);
}

exec.exec("bash", execArgs, options)
.catch(err => {
if (fail_ci) {
core.setFailed(
`Codecov failed with the following error: ${err.message}`
);
} else {
core.warning(`Codecov warning: ${err.message}`);
}
})
.then(() => {
unlinkFile();
});
exec.exec("bash", execArgs, options)
.catch(err => {
if (fail_ci) {
core.setFailed(
`Codecov failed with the following error: ${err.message}`
);
} else {
core.warning(`Codecov warning: ${err.message}`);
}
})
.then(() => {
unlinkFile();
});

const unlinkFile = () => {
fs.unlink("codecov.sh", err => {
if (err && fail_ci) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
}
});
};
});
const unlinkFile = () => {
fs.unlink("codecov.sh", err => {
if (err && fail_ci) {
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 (fail_ci) {

0 comments on commit 8ddda09

Please sign in to comment.