mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-10 10:44:19 +00:00
parent
fe9a9bd329
commit
ce037ed31d
6 changed files with 122 additions and 53 deletions
|
@ -180,7 +180,8 @@ The following are optional as `step.with` keys
|
|||
| `token` | String | Secret GitHub Personal Access Token. Defaults to `${{ github.token }}` |
|
||||
| `discussion_category_name` | String | If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. For more information, see ["Managing categories for discussions in your repository."](https://docs.github.com/en/discussions/managing-discussions-for-your-community/managing-categories-for-discussions-in-your-repository) |
|
||||
| `generate_release_notes` | Boolean | Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes. See the [GitHub docs for this feature](https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes) for more information |
|
||||
| `append_body` | Boolean | Append existed body instead of overrides |
|
||||
| `append_body` | Boolean | Whether to append to the existing body instead of overwriting. |
|
||||
| `delete_on_existing` | Boolean | Whether or not to delete an existing release entirely when running this action. |
|
||||
|
||||
💡 When providing a `body` and `body_path` at the same time, `body_path` will be
|
||||
attempted first, then falling back on `body` if the path can not be read from.
|
||||
|
|
|
@ -51,7 +51,8 @@ describe("util", () => {
|
|||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -71,7 +72,8 @@ describe("util", () => {
|
|||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -91,7 +93,8 @@ describe("util", () => {
|
|||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
})
|
||||
);
|
||||
});
|
||||
|
@ -124,7 +127,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -149,7 +153,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd",
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -173,7 +178,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: "releases",
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -198,7 +204,34 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: true
|
||||
input_generate_release_notes: true,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it("supports deleting existing releases", () => {
|
||||
assert.deepStrictEqual(
|
||||
parseConfig({
|
||||
INPUT_DELETE_ON_EXISTING: "true"
|
||||
}),
|
||||
{
|
||||
github_ref: "",
|
||||
github_repository: "",
|
||||
github_token: "",
|
||||
input_append_body: false,
|
||||
input_body: undefined,
|
||||
input_body_path: undefined,
|
||||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_files: [],
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: true
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -226,7 +259,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -252,7 +286,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -277,7 +312,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
@ -301,7 +337,8 @@ describe("util", () => {
|
|||
input_fail_on_unmatched_files: false,
|
||||
input_target_commitish: undefined,
|
||||
input_discussion_category_name: undefined,
|
||||
input_generate_release_notes: false
|
||||
input_generate_release_notes: false,
|
||||
input_delete_on_existing: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -44,7 +44,10 @@ inputs:
|
|||
description: "Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes."
|
||||
required: false
|
||||
append_body:
|
||||
description: "Append existed body instead of overrites. Default is false."
|
||||
description: "Whether to append to the existing body instead of overwriting. Default is false."
|
||||
required: false
|
||||
delete_on_existing:
|
||||
description: "Whether or not to delete an existing release entirely when running this action."
|
||||
required: false
|
||||
env:
|
||||
"GITHUB_TOKEN": "As provided by Github Actions"
|
||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
102
src/github.ts
102
src/github.ts
|
@ -61,6 +61,12 @@ export interface Releaser {
|
|||
generate_release_notes: boolean | undefined;
|
||||
}): Promise<{ data: Release }>;
|
||||
|
||||
deleteRelease(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
release_id: number;
|
||||
}): Promise<{ data: Release }>;
|
||||
|
||||
allReleases(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
|
@ -112,6 +118,14 @@ export class GitHubReleaser implements Releaser {
|
|||
return this.github.rest.repos.updateRelease(params);
|
||||
}
|
||||
|
||||
deleteRelease(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
release_id: number;
|
||||
}): Promise<{ data: Release }> {
|
||||
return this.github.rest.repos.deleteRelease(params);
|
||||
}
|
||||
|
||||
allReleases(params: {
|
||||
owner: string;
|
||||
repo: string;
|
||||
|
@ -198,6 +212,48 @@ export const release = async (
|
|||
|
||||
const discussion_category_name = config.input_discussion_category_name;
|
||||
const generate_release_notes = config.input_generate_release_notes;
|
||||
|
||||
const createRelease = async () => {
|
||||
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}"`;
|
||||
}
|
||||
console.log(
|
||||
`👩🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
|
||||
);
|
||||
try {
|
||||
let release = await releaser.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name,
|
||||
name,
|
||||
body,
|
||||
draft,
|
||||
prerelease,
|
||||
target_commitish,
|
||||
discussion_category_name,
|
||||
generate_release_notes
|
||||
});
|
||||
return release.data;
|
||||
} 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 release(config, releaser, maxRetries - 1);
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
// you can't get a an existing draft by tag
|
||||
// so we must find one in the list of all releases
|
||||
|
@ -219,6 +275,13 @@ export const release = async (
|
|||
});
|
||||
|
||||
const release_id = existingRelease.data.id;
|
||||
|
||||
if (config.input_delete_on_existing) {
|
||||
console.log(`⚠ Deleting existing release ${owner}/${repo}@${release_id}`);
|
||||
await releaser.deleteRelease({ owner, repo, release_id });
|
||||
return createRelease();
|
||||
}
|
||||
|
||||
let target_commitish: string;
|
||||
if (
|
||||
config.input_target_commitish &&
|
||||
|
@ -272,44 +335,7 @@ export const release = async (
|
|||
return release.data;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
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}"`;
|
||||
}
|
||||
console.log(
|
||||
`👩🏭 Creating new GitHub release for tag ${tag_name}${commitMessage}...`
|
||||
);
|
||||
try {
|
||||
let release = await releaser.createRelease({
|
||||
owner,
|
||||
repo,
|
||||
tag_name,
|
||||
name,
|
||||
body,
|
||||
draft,
|
||||
prerelease,
|
||||
target_commitish,
|
||||
discussion_category_name,
|
||||
generate_release_notes
|
||||
});
|
||||
return release.data;
|
||||
} 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 release(config, releaser, maxRetries - 1);
|
||||
}
|
||||
return createRelease();
|
||||
} else {
|
||||
console.log(
|
||||
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
|
||||
|
|
|
@ -19,6 +19,7 @@ export interface Config {
|
|||
input_discussion_category_name?: string;
|
||||
input_generate_release_notes?: boolean;
|
||||
input_append_body?: boolean;
|
||||
input_delete_on_existing?: boolean;
|
||||
}
|
||||
|
||||
export const uploadUrl = (url: string): string => {
|
||||
|
@ -69,7 +70,8 @@ export const parseConfig = (env: Env): Config => {
|
|||
input_discussion_category_name:
|
||||
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
|
||||
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == "true",
|
||||
input_append_body: env.INPUT_APPEND_BODY == "true"
|
||||
input_append_body: env.INPUT_APPEND_BODY == "true",
|
||||
input_delete_on_existing: env.INPUT_DELETE_ON_EXISTING == "true"
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue