Skip to content

Commit

Permalink
Wrap request promise in try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu committed Jul 17, 2020
1 parent e16d515 commit 8ddda09
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 196 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
200 changes: 103 additions & 97 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 8ddda09

Please sign in to comment.