Skip to content

Commit fe9a9bd

Browse files
authored
add append_body option (softprops#199)
1 parent 8a65c81 commit fe9a9bd

File tree

6 files changed

+53
-9
lines changed

6 files changed

+53
-9
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ The following are optional as `step.with` keys
176176
| `tag_name` | String | Name of a tag. defaults to `github.ref` |
177177
| `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing |
178178
| `repository` | String | Name of a target repository in `<owner>/<repo>` format. Defaults to GITHUB_REPOSITORY env variable |
179-
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Defaults to repository default branch. |
179+
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Defaults to repository default branch. |
180180
| `token` | String | Secret GitHub Personal Access Token. Defaults to `${{ github.token }}` |
181181
| `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) |
182182
| `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 |
183+
| `append_body` | Boolean | Append existed body instead of overrides |
183184

184185
💡 When providing a `body` and `body_path` at the same time, `body_path` will be
185186
attempted first, then falling back on `body` if the path can not be read from.
@@ -192,11 +193,11 @@ release will retain its original info.
192193

193194
The following outputs can be accessed via `${{ steps.<step-id>.outputs }}` from this action
194195

195-
| Name | Type | Description |
196-
| ------------ | ------ | --------------------------------------- |
197-
| `url` | String | Github.com URL for the release |
198-
| `id` | String | Release ID |
199-
| `upload_url` | String | URL for uploading assets to the release |
196+
| Name | Type | Description |
197+
| ------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
198+
| `url` | String | Github.com URL for the release |
199+
| `id` | String | Release ID |
200+
| `upload_url` | String | URL for uploading assets to the release |
200201
| `assets` | String | JSON array containing information about each uploaded asset, in the format given [here](https://docs.github.com/en/rest/reference/repos#upload-a-release-asset--code-samples) (minus the `uploader` field) |
201202

202203
As an example, you can use `${{ fromJSON(steps.<step-id>.outputs.assets)[0].browser_download_url }}` to get the download URL of the first asset.

__tests__/util.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ describe("util", () => {
113113
github_ref: "",
114114
github_repository: "",
115115
github_token: "",
116+
input_append_body: false,
116117
input_body: undefined,
117118
input_body_path: undefined,
118119
input_draft: undefined,
@@ -137,6 +138,7 @@ describe("util", () => {
137138
github_ref: "",
138139
github_repository: "",
139140
github_token: "",
141+
input_append_body: false,
140142
input_body: undefined,
141143
input_body_path: undefined,
142144
input_draft: undefined,
@@ -160,6 +162,7 @@ describe("util", () => {
160162
github_ref: "",
161163
github_repository: "",
162164
github_token: "",
165+
input_append_body: false,
163166
input_body: undefined,
164167
input_body_path: undefined,
165168
input_draft: undefined,
@@ -184,6 +187,7 @@ describe("util", () => {
184187
github_ref: "",
185188
github_repository: "",
186189
github_token: "",
190+
input_append_body: false,
187191
input_body: undefined,
188192
input_body_path: undefined,
189193
input_draft: undefined,
@@ -211,6 +215,7 @@ describe("util", () => {
211215
github_ref: "",
212216
github_repository: "",
213217
github_token: "env-token",
218+
input_append_body: false,
214219
input_body: undefined,
215220
input_body_path: undefined,
216221
input_draft: false,
@@ -236,6 +241,7 @@ describe("util", () => {
236241
github_ref: "",
237242
github_repository: "",
238243
github_token: "input-token",
244+
input_append_body: false,
239245
input_body: undefined,
240246
input_body_path: undefined,
241247
input_draft: false,
@@ -260,6 +266,7 @@ describe("util", () => {
260266
github_ref: "",
261267
github_repository: "",
262268
github_token: "",
269+
input_append_body: false,
263270
input_body: undefined,
264271
input_body_path: undefined,
265272
input_draft: false,
@@ -274,6 +281,30 @@ describe("util", () => {
274281
}
275282
);
276283
});
284+
it("parses basic config with append_body", () => {
285+
assert.deepStrictEqual(
286+
parseConfig({
287+
INPUT_APPEND_BODY: "true"
288+
}),
289+
{
290+
github_ref: "",
291+
github_repository: "",
292+
github_token: "",
293+
input_append_body: true,
294+
input_body: undefined,
295+
input_body_path: undefined,
296+
input_draft: undefined,
297+
input_prerelease: undefined,
298+
input_files: [],
299+
input_name: undefined,
300+
input_tag_name: undefined,
301+
input_fail_on_unmatched_files: false,
302+
input_target_commitish: undefined,
303+
input_discussion_category_name: undefined,
304+
input_generate_release_notes: false
305+
}
306+
);
307+
});
277308
});
278309
describe("isTag", () => {
279310
it("returns true for tags", async () => {

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ inputs:
4343
generate_release_notes:
4444
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."
4545
required: false
46+
append_body:
47+
description: "Append existed body instead of overrites. Default is false."
48+
required: false
4649
env:
4750
"GITHUB_TOKEN": "As provided by Github Actions"
4851
outputs:

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,14 @@ export const release = async (
238238
// body parts as a release gets updated. some users will likely want this while
239239
// others won't previously this was duplicating content for most which
240240
// no one wants
241-
let body = releaseBody(config) || existingRelease.data.body || "";
241+
const workflowBody = releaseBody(config) || "";
242+
const existingReleaseBody = existingRelease.data.body || "";
243+
let body: string;
244+
if (config.input_append_body && workflowBody && existingReleaseBody) {
245+
body = existingReleaseBody + "\n" + workflowBody;
246+
} else {
247+
body = workflowBody || existingReleaseBody;
248+
}
242249

243250
const draft =
244251
config.input_draft !== undefined

src/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Config {
1818
input_target_commitish?: string;
1919
input_discussion_category_name?: string;
2020
input_generate_release_notes?: boolean;
21+
input_append_body?: boolean;
2122
}
2223

2324
export const uploadUrl = (url: string): string => {
@@ -67,7 +68,8 @@ export const parseConfig = (env: Env): Config => {
6768
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
6869
input_discussion_category_name:
6970
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
70-
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == "true"
71+
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == "true",
72+
input_append_body: env.INPUT_APPEND_BODY == "true"
7173
};
7274
};
7375

0 commit comments

Comments
 (0)