Fix missing update release body (#365)

* Update json5 deps

* Remove quote around env var `GITHUB_TOKEN`

* Factorize search by draft & tag

* Correct `_release` undefined when creating a new release

* Cleanup package-lock
This commit is contained in:
FirelightFlagboy 2024-07-17 20:14:48 +02:00 committed by GitHub
parent 08d85b1534
commit fb2d03176f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 112 additions and 71 deletions

View File

@ -50,7 +50,7 @@ inputs:
description: "Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Can be `true`, `false`, or `legacy`. Uses GitHub api default if not provided" description: "Specifies whether this release should be set as the latest release for the repository. Drafts and prereleases cannot be set as latest. Can be `true`, `false`, or `legacy`. Uses GitHub api default if not provided"
required: false required: false
env: env:
"GITHUB_TOKEN": "As provided by Github Actions" GITHUB_TOKEN: "As provided by Github Actions"
outputs: outputs:
url: url:
description: "URL to the Release HTML Page" description: "URL to the Release HTML Page"

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -6,6 +6,7 @@
"main": "lib/main.js", "main": "lib/main.js",
"scripts": { "scripts": {
"build": "ncc build src/main.ts --minify", "build": "ncc build src/main.ts --minify",
"build-debug": "ncc build src/main.ts --v8-cache --source-map",
"test": "jest", "test": "jest",
"fmt": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"", "fmt": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
"fmtcheck": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"", "fmtcheck": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",

View File

@ -208,45 +208,63 @@ export const release = async (
try { try {
// you can't get a an existing draft by tag // you can't get a an existing draft by tag
// so we must find one in the list of all releases // so we must find one in the list of all releases
let _release: Release | undefined = undefined;
if (config.input_draft) { 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); _release = response.data.find((release) => release.tag_name === tag);
if (release) {
return release;
} }
} } else {
} _release = (
let existingRelease = await releaser.getReleaseByTag({ await releaser.getReleaseByTag({
owner, owner,
repo, repo,
tag, tag,
}); })
).data;
}
if (_release === null || _release === undefined) {
return await createRelease(
tag,
config,
releaser,
owner,
repo,
discussion_category_name,
generate_release_notes,
maxRetries
);
}
const release_id = existingRelease.data.id; let existingRelease: Release = _release!;
console.log(
`Found release ${existingRelease.name} (with id=${existingRelease.id})`
);
const release_id = existingRelease.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;
@ -257,11 +275,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 make_latest = config.input_make_latest; const make_latest = config.input_make_latest;
@ -288,6 +306,29 @@ export const release = async (
throw error; throw error;
} }
return await createRelease(
tag,
config,
releaser,
owner,
repo,
discussion_category_name,
generate_release_notes,
maxRetries
);
}
};
async function createRelease(
tag: string,
config: Config,
releaser: Releaser,
owner: string,
repo: string,
discussion_category_name: string | undefined,
generate_release_notes: boolean | undefined,
maxRetries: number
) {
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);
@ -342,4 +383,3 @@ export const release = async (
return release(config, releaser, maxRetries - 1); return release(config, releaser, maxRetries - 1);
} }
} }
};