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 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge remote-tracking branch 'softprops/master' into patch-1
  • Loading branch information
galargh committed Jul 17, 2024
commit 0e226ebb8be35f346849e94327b9ec4c013a5583
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

172 changes: 77 additions & 95 deletions src/github.ts
Original file line number Diff line number Diff line change
@@ -206,27 +206,19 @@ export const release = async (
const discussion_category_name = config.input_discussion_category_name;
const generate_release_notes = config.input_generate_release_notes;
try {
let existingRelease: Release | undefined;
// you can't get an existing draft by tag
// so we must find one in the list of all releases
let _release: Release | undefined = undefined;
for await (const response of releaser.allReleases({
owner,
repo,
})) {
existingRelease = response.data.find(
(release) => release.tag_name === tag
);
if (existingRelease !== undefined) {
_release = response.data.find((release) => release.tag_name === tag);
if (_release !== undefined) {
break;
}
} else {
_release = (
await releaser.getReleaseByTag({
owner,
repo,
tag,
})
).data;
}
if (_release === null || _release === undefined) {
if (_release === undefined) {
return await createRelease(
tag,
config,
@@ -238,95 +230,85 @@ export const release = async (
maxRetries
);
}
if (existingRelease !== undefined) {
const release_id = existingRelease.id;
let target_commitish: string;
if (
config.input_target_commitish &&
config.input_target_commitish !== existingRelease.target_commitish
) {
console.log(
`Updating commit from "${existingRelease.target_commitish}" to "${config.input_target_commitish}"`
);
target_commitish = config.input_target_commitish;
} else {
target_commitish = existingRelease.target_commitish;
}

const tag_name = tag;
const name = config.input_name || existingRelease.name || tag;
// revisit: support a new body-concat-strategy input for accumulating
// 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
// no one wants
const workflowBody = releaseBody(config) || "";
const existingReleaseBody = existingRelease.body || "";
let body: string;
if (config.input_append_body && workflowBody && existingReleaseBody) {
body = existingReleaseBody + "\n" + workflowBody;
} else {
body = workflowBody || existingReleaseBody;
}
let existingRelease: Release = _release!;
console.log(
`Found release ${existingRelease.name} (with id=${existingRelease.id})`
);

const draft =
config.input_draft !== undefined
? config.input_draft
: existingRelease.draft;
const prerelease =
config.input_prerelease !== undefined
? config.input_prerelease
: existingRelease.prerelease;
const release_id = existingRelease.id;
let target_commitish: string;
if (
config.input_target_commitish &&
config.input_target_commitish !== existingRelease.target_commitish
) {
console.log(
`Updating commit from "${existingRelease.target_commitish}" to "${config.input_target_commitish}"`
);
target_commitish = config.input_target_commitish;
} else {
target_commitish = existingRelease.target_commitish;
}

const release = await releaser.updateRelease({
owner,
repo,
release_id,
tag_name,
target_commitish,
name,
body,
draft,
prerelease,
discussion_category_name,
generate_release_notes,
});
return release.data;
const tag_name = tag;
const name = config.input_name || existingRelease.name || tag;
// revisit: support a new body-concat-strategy input for accumulating
// 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
// no one wants
const workflowBody = releaseBody(config) || "";
const existingReleaseBody = existingRelease.body || "";
let body: string;
if (config.input_append_body && workflowBody && existingReleaseBody) {
body = existingReleaseBody + "\n" + workflowBody;
} else {
const tag_name = tag;
const name = config.input_name || tag;
const body = releaseBody(config);
const draft = config.input_draft;
const prerelease = config.input_prerelease;
const target_commitish = config.input_target_commitish;
let commitMessage: string = "";
if (target_commitish) {
commitMessage = ` using commit "${target_commitish}"`;
}
body = workflowBody || existingReleaseBody;
}

const draft =
config.input_draft !== undefined
? config.input_draft
: existingRelease.draft;
const prerelease =
config.input_prerelease !== undefined
? config.input_prerelease
: existingRelease.prerelease;

const make_latest = config.input_make_latest;

const release = await releaser.updateRelease({
owner,
repo,
release_id,
tag_name,
target_commitish,
name,
body,
draft,
prerelease,
discussion_category_name,
generate_release_notes,
make_latest,
});
return release.data;
} catch (error) {
if (error.status !== 404) {
console.log(
`👩‍🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
);
let release = await releaser.createRelease({
owner,
repo,
tag_name,
name,
body,
draft,
prerelease,
target_commitish,
discussion_category_name,
generate_release_notes,
});
return release.data;
throw error;
}
} catch (error) {
// presume a race with competing metrix runs
console.log(
`⚠️ GitHub release failed with status: ${error.status}\n${JSON.stringify(
error.response.data.errors
)}\nretrying... (${maxRetries - 1} retries remaining)`

return await createRelease(
tag,
config,
releaser,
owner,
repo,
discussion_category_name,
generate_release_notes,
maxRetries
);
return release(config, releaser, maxRetries - 1);
}
};

You are viewing a condensed version of this merge commit. You can view the full changes here.