mirror of
https://github.com/softprops/action-gh-release.git
synced 2024-11-26 21:37:56 +03:00
error handling
This commit is contained in:
parent
e197e56931
commit
6fa875df0b
@ -37,23 +37,24 @@ exports.upload = (gh, url, path) => __awaiter(void 0, void 0, void 0, function*
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let [owner, repo] = config.github_repository.split("/");
|
const [owner, repo] = config.github_repository.split("/");
|
||||||
|
const tag = config.github_ref.replace("refs/tags/", "");
|
||||||
try {
|
try {
|
||||||
let release = yield gh.repos.getReleaseByTag({
|
let release = yield gh.repos.getReleaseByTag({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
tag: config.github_ref
|
tag
|
||||||
});
|
});
|
||||||
return release.data;
|
return release.data;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (error.status === 404) {
|
if (error.status === 404) {
|
||||||
console.log("Creating new release...");
|
|
||||||
try {
|
try {
|
||||||
const tag_name = config.github_ref.replace("refs/tags/", "");
|
const tag_name = tag;
|
||||||
const name = config.input_name || tag_name;
|
const name = config.input_name || tag;
|
||||||
const body = config.input_body;
|
const body = config.input_body;
|
||||||
const draft = config.input_draft;
|
const draft = config.input_draft;
|
||||||
|
console.log(`👩🏭 Creating new GitHub release for tag ${tag_name}...`);
|
||||||
let release = yield gh.repos.createRelease({
|
let release = yield gh.repos.createRelease({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
@ -65,12 +66,13 @@ exports.release = (config, gh) => __awaiter(void 0, void 0, void 0, function* ()
|
|||||||
return release.data;
|
return release.data;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.log(`created failed with status: ${error.status}`);
|
// presume a race with competing metrix runs
|
||||||
|
console.log(`GitHub release failed with status: ${error.status}`);
|
||||||
return exports.release(config, gh);
|
return exports.release(config, gh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log(`Unexpected error fetching github release for tag ${config.github_ref}: ${error}`);
|
console.log(`Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,22 +56,23 @@ export const release = async (
|
|||||||
config: Config,
|
config: Config,
|
||||||
gh: GitHub
|
gh: GitHub
|
||||||
): Promise<Release> => {
|
): Promise<Release> => {
|
||||||
let [owner, repo] = config.github_repository.split("/");
|
const [owner, repo] = config.github_repository.split("/");
|
||||||
|
const tag = config.github_ref.replace("refs/tags/", "");
|
||||||
try {
|
try {
|
||||||
let release = await gh.repos.getReleaseByTag({
|
let release = await gh.repos.getReleaseByTag({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
tag: config.github_ref
|
tag
|
||||||
});
|
});
|
||||||
return release.data;
|
return release.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.status === 404) {
|
if (error.status === 404) {
|
||||||
console.log("Creating new release...");
|
|
||||||
try {
|
try {
|
||||||
const tag_name = config.github_ref.replace("refs/tags/", "");
|
const tag_name = tag;
|
||||||
const name = config.input_name || tag_name;
|
const name = config.input_name || tag;
|
||||||
const body = config.input_body;
|
const body = config.input_body;
|
||||||
const draft = config.input_draft;
|
const draft = config.input_draft;
|
||||||
|
console.log(`👩🏭 Creating new GitHub release for tag ${tag_name}...`);
|
||||||
let release = await gh.repos.createRelease({
|
let release = await gh.repos.createRelease({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
@ -82,11 +83,12 @@ export const release = async (
|
|||||||
});
|
});
|
||||||
return release.data;
|
return release.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`created failed with status: ${error.status}`);
|
// presume a race with competing metrix runs
|
||||||
|
console.log(`GitHub release failed with status: ${error.status}`);
|
||||||
return release(config, gh);
|
return release(config, gh);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`Unexpected error fetching github release for tag ${config.github_ref}: ${error}`);
|
console.log(`Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user