mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-11 19:04:20 +00:00
fix: updating release draft status
This commit is contained in:
parent
d4e8205d7e
commit
25b3878b4c
2 changed files with 85 additions and 101 deletions
4
dist/index.js
vendored
4
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -199,47 +199,41 @@ export const release = async (
|
||||||
const discussion_category_name = config.input_discussion_category_name;
|
const discussion_category_name = config.input_discussion_category_name;
|
||||||
const generate_release_notes = config.input_generate_release_notes;
|
const generate_release_notes = config.input_generate_release_notes;
|
||||||
try {
|
try {
|
||||||
// you can't get a an existing draft by tag
|
let existingRelease: Release | undefined;
|
||||||
// so we must find one in the list of all releases
|
|
||||||
if (config.input_draft) {
|
|
||||||
for await (const response of releaser.allReleases({
|
for await (const response of releaser.allReleases({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
})) {
|
})) {
|
||||||
let release = response.data.find((release) => release.tag_name === tag);
|
existingRelease = response.data.find(
|
||||||
if (release) {
|
(release) => release.tag_name === tag
|
||||||
return release;
|
);
|
||||||
|
if (existingRelease !== undefined) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (existingRelease !== undefined) {
|
||||||
let existingRelease = await releaser.getReleaseByTag({
|
const release_id = existingRelease.id;
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
tag,
|
|
||||||
});
|
|
||||||
|
|
||||||
const release_id = existingRelease.data.id;
|
|
||||||
let target_commitish: string;
|
let target_commitish: string;
|
||||||
if (
|
if (
|
||||||
config.input_target_commitish &&
|
config.input_target_commitish &&
|
||||||
config.input_target_commitish !== existingRelease.data.target_commitish
|
config.input_target_commitish !== existingRelease.target_commitish
|
||||||
) {
|
) {
|
||||||
console.log(
|
console.log(
|
||||||
`Updating commit from "${existingRelease.data.target_commitish}" to "${config.input_target_commitish}"`
|
`Updating commit from "${existingRelease.target_commitish}" to "${config.input_target_commitish}"`
|
||||||
);
|
);
|
||||||
target_commitish = config.input_target_commitish;
|
target_commitish = config.input_target_commitish;
|
||||||
} else {
|
} else {
|
||||||
target_commitish = existingRelease.data.target_commitish;
|
target_commitish = existingRelease.target_commitish;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tag_name = tag;
|
const tag_name = tag;
|
||||||
const name = config.input_name || existingRelease.data.name || tag;
|
const name = config.input_name || existingRelease.name || tag;
|
||||||
// revisit: support a new body-concat-strategy input for accumulating
|
// revisit: support a new body-concat-strategy input for accumulating
|
||||||
// body parts as a release gets updated. some users will likely want this while
|
// body parts as a release gets updated. some users will likely want this while
|
||||||
// others won't previously this was duplicating content for most which
|
// others won't previously this was duplicating content for most which
|
||||||
// no one wants
|
// no one wants
|
||||||
const workflowBody = releaseBody(config) || "";
|
const workflowBody = releaseBody(config) || "";
|
||||||
const existingReleaseBody = existingRelease.data.body || "";
|
const existingReleaseBody = existingRelease.body || "";
|
||||||
let body: string;
|
let body: string;
|
||||||
if (config.input_append_body && workflowBody && existingReleaseBody) {
|
if (config.input_append_body && workflowBody && existingReleaseBody) {
|
||||||
body = existingReleaseBody + "\n" + workflowBody;
|
body = existingReleaseBody + "\n" + workflowBody;
|
||||||
|
@ -250,11 +244,11 @@ export const release = async (
|
||||||
const draft =
|
const draft =
|
||||||
config.input_draft !== undefined
|
config.input_draft !== undefined
|
||||||
? config.input_draft
|
? config.input_draft
|
||||||
: existingRelease.data.draft;
|
: existingRelease.draft;
|
||||||
const prerelease =
|
const prerelease =
|
||||||
config.input_prerelease !== undefined
|
config.input_prerelease !== undefined
|
||||||
? config.input_prerelease
|
? config.input_prerelease
|
||||||
: existingRelease.data.prerelease;
|
: existingRelease.prerelease;
|
||||||
|
|
||||||
const release = await releaser.updateRelease({
|
const release = await releaser.updateRelease({
|
||||||
owner,
|
owner,
|
||||||
|
@ -270,8 +264,7 @@ export const release = async (
|
||||||
generate_release_notes,
|
generate_release_notes,
|
||||||
});
|
});
|
||||||
return release.data;
|
return release.data;
|
||||||
} catch (error) {
|
} else {
|
||||||
if (error.status === 404) {
|
|
||||||
const tag_name = tag;
|
const tag_name = tag;
|
||||||
const name = config.input_name || tag;
|
const name = config.input_name || tag;
|
||||||
const body = releaseBody(config);
|
const body = releaseBody(config);
|
||||||
|
@ -285,7 +278,6 @@ export const release = async (
|
||||||
console.log(
|
console.log(
|
||||||
`👩🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
|
`👩🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
|
||||||
);
|
);
|
||||||
try {
|
|
||||||
let release = await releaser.createRelease({
|
let release = await releaser.createRelease({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
|
@ -299,22 +291,14 @@ export const release = async (
|
||||||
generate_release_notes,
|
generate_release_notes,
|
||||||
});
|
});
|
||||||
return release.data;
|
return release.data;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// presume a race with competing metrix runs
|
// presume a race with competing metrix runs
|
||||||
console.log(
|
console.log(
|
||||||
`⚠️ GitHub release failed with status: ${
|
`⚠️ GitHub release failed with status: ${error.status}\n${JSON.stringify(
|
||||||
error.status
|
error.response.data.errors
|
||||||
}\n${JSON.stringify(error.response.data.errors)}\nretrying... (${
|
)}\nretrying... (${maxRetries - 1} retries remaining)`
|
||||||
maxRetries - 1
|
|
||||||
} retries remaining)`
|
|
||||||
);
|
);
|
||||||
return release(config, releaser, maxRetries - 1);
|
return release(config, releaser, maxRetries - 1);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue