Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updating release draft status from true to false #316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

56 changes: 20 additions & 36 deletions src/github.ts
Expand Up @@ -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;
} }
} }
let existingRelease = await releaser.getReleaseByTag({ if (existingRelease !== undefined) {
owner, const release_id = existingRelease.id;
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;
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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;
}
}
}; };