Skip to content

Commit

Permalink
Fixes #135 Add support for generate_release_notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ncipollo committed Nov 26, 2021
1 parent 66aaa1e commit 40bb172
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This action will create a GitHub release and optionally upload an artifact to it
- **commit**: An optional commit reference. This will be used to create the tag if it does not exist.
- **discussionCategory**: When provided this will generate a discussion of the specified category. The category must exist otherwise this will cause the action to fail. This isn't used with draft releases.
- **draft**: Optionally marks this release as a draft release. Set to `true` to enable.
- **generateReleaseNotes**: Indicates if release notes should be automatically generated. Set to `true` to enable.
- **name**: An optional name for the release. If this is omitted the tag will be used.
- **omitBody**: Indicates if the release body should be omitted.
- **omitBodyDuringUpdate**: Indicates if the release body should be omitted during updates. The body will still be applied for newly created releases. This will preserve the existing body during updates.
Expand Down
65 changes: 59 additions & 6 deletions __tests__/Action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const createName = 'createName'
const commit = 'commit'
const discussionCategory = 'discussionCategory'
const draft = true
const generateReleaseNotes = true
const id = 100
const createPrerelease = true
const updatePrerelease = false
Expand All @@ -51,7 +52,14 @@ describe("Action", () => {

await action.perform()

expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease)
expect(createMock).toBeCalledWith(tag,
createBody,
commit,
discussionCategory,
draft,
generateReleaseNotes,
createName,
createPrerelease)
expect(uploadMock).not.toBeCalled()
assertOutputApplied()
})
Expand All @@ -63,7 +71,15 @@ describe("Action", () => {

await action.perform()

expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease)
expect(createMock).toBeCalledWith(
tag,
createBody,
commit,
discussionCategory,
draft,
generateReleaseNotes,
createName,
createPrerelease)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()
})
Expand All @@ -80,7 +96,16 @@ describe("Action", () => {

await action.perform()

expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease)
expect(createMock).toBeCalledWith(
tag,
createBody,
commit,
discussionCategory,
draft,
generateReleaseNotes,
createName,
createPrerelease
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()

Expand All @@ -91,7 +116,16 @@ describe("Action", () => {

await action.perform()

expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease)
expect(createMock).toBeCalledWith(
tag,
createBody,
commit,
discussionCategory,
draft,
generateReleaseNotes,
createName,
createPrerelease
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()
})
Expand Down Expand Up @@ -125,7 +159,16 @@ describe("Action", () => {
expect(error).toEqual("error")
}

expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease)
expect(createMock).toBeCalledWith(
tag,
createBody,
commit,
discussionCategory,
draft,
generateReleaseNotes,
createName,
createPrerelease
)
expect(uploadMock).not.toBeCalled()
})

Expand Down Expand Up @@ -191,7 +234,16 @@ describe("Action", () => {
expect(error).toEqual(expectedError)
}

expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease)
expect(createMock).toBeCalledWith(
tag,
createBody,
commit,
discussionCategory,
draft,
generateReleaseNotes,
createName,
createPrerelease
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
})

Expand Down Expand Up @@ -315,6 +367,7 @@ describe("Action", () => {
commit: commit,
discussionCategory: discussionCategory,
draft: draft,
generateReleaseNotes: true,
owner: "owner",
createdPrerelease: createPrerelease,
replacesArtifacts: replacesArtifacts,
Expand Down
25 changes: 22 additions & 3 deletions __tests__/Inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ describe('Inputs', () => {
inputs = new CoreInputs(createGlobber(), context)
})

it('returns targetCommit', () => {
mockGetInput.mockReturnValue('42')
expect(inputs.commit).toBe('42')
describe('commit', () => {
it('returns commit', () => {
mockGetInput.mockReturnValueOnce('commit')
expect(inputs.commit).toBe('commit')
})

it('returns undefined when omitted', () => {
mockGetInput.mockReturnValueOnce('')
expect(inputs.commit).toBeUndefined()
})
})

it('returns token', () => {
Expand Down Expand Up @@ -202,6 +209,18 @@ describe('Inputs', () => {
})
})

describe('generateReleaseNotes', () => {
it('returns returns true', function () {
mockGetInput.mockReturnValue("true")
expect(inputs.generateReleaseNotes).toBe(true)
});

it('returns false when omitted', function () {
mockGetInput.mockReturnValue("")
expect(inputs.generateReleaseNotes).toBe(false)
});
})

describe('owner', () => {
it('returns owner from context', function () {
process.env.GITHUB_REPOSITORY = "owner/repo"
Expand Down
3 changes: 2 additions & 1 deletion __tests__/Integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ describe.skip('Integration Test', () => {
artifacts: artifacts(),
createdReleaseBody: "This release was generated by release-action's integration test",
createdReleaseName: "Releases Action Integration Test",
commit: "",
commit: undefined,
discussionCategory: 'Release',
draft: false,
generateReleaseNotes: true,
owner: "ncipollo",
createdPrerelease: false,
replacesArtifacts: true,
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ inputs:
description: "Optionally marks this release as a draft release. Set to true to enable."
required: false
default: ''
generateReleaseNotes:
description: 'Indicates if release notes should be automatically generated.'
required: false
default: 'false'
name:
description: 'An optional name for the release. If this is omitted the tag will be used.'
required: false
Expand Down
15 changes: 12 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Action {
}
createRelease() {
return __awaiter(this, void 0, void 0, function* () {
return yield this.releases.create(this.inputs.tag, this.inputs.createdReleaseBody, this.inputs.commit, this.inputs.discussionCategory, this.inputs.draft, this.inputs.createdReleaseName, this.inputs.createdPrerelease);
return yield this.releases.create(this.inputs.tag, this.inputs.createdReleaseBody, this.inputs.commit, this.inputs.discussionCategory, this.inputs.draft, this.inputs.generateReleaseNotes, this.inputs.createdReleaseName, this.inputs.createdPrerelease);
});
}
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ class CoreInputs {
return '';
}
get commit() {
return core.getInput('commit');
const commit = core.getInput('commit');
if (commit) {
return commit;
}
return undefined;
}
get createdReleaseName() {
if (CoreInputs.omitName)
Expand Down Expand Up @@ -98,6 +102,10 @@ class CoreInputs {
const draft = core.getInput('draft');
return draft == 'true';
}
get generateReleaseNotes() {
const generate = core.getInput('generateReleaseNotes');
return generate == 'true';
}
get owner() {
let owner = core.getInput('owner');
if (owner) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class GithubReleases {
this.inputs = inputs;
this.git = git;
}
create(tag, body, commitHash, discussionCategory, draft, name, prerelease) {
create(tag, body, commitHash, discussionCategory, draft, generateReleaseNotes, name, prerelease) {
return __awaiter(this, void 0, void 0, function* () {
// noinspection TypeScriptValidateJSTypes
return this.git.rest.repos.createRelease({
body: body,
name: name,
discussion_category_name: discussionCategory,
draft: draft,
generate_release_notes: generateReleaseNotes,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.inputs.repo,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "1.1.0",
"private": true,
"description": "An action which manages a github release",
"main": "dist/index.js",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"clean": "rm -rf lib/*",
"debug": "yarn clean && yarn install && yarn build",
"debug": "yarn clean && yarn install && yarn build && yarn package",
"package": "ncc build --source-map --license licenses.txt",
"release": "yarn clean && yarn install --production && yarn build && yarn package",
"test": "jest"
Expand Down
1 change: 1 addition & 0 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class Action {
this.inputs.commit,
this.inputs.discussionCategory,
this.inputs.draft,
this.inputs.generateReleaseNotes,
this.inputs.createdReleaseName,
this.inputs.createdPrerelease
)
Expand Down
16 changes: 13 additions & 3 deletions src/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export interface Inputs {
readonly allowUpdates: boolean
readonly artifactErrorsFailBuild: boolean
readonly artifacts: Artifact[]
readonly commit: string
readonly commit?: string
readonly createdReleaseBody?: string
readonly createdReleaseName?: string
readonly discussionCategory?: string
readonly draft: boolean
readonly generateReleaseNotes: boolean
readonly owner: string
readonly createdPrerelease: boolean
readonly removeArtifacts: boolean
Expand Down Expand Up @@ -83,8 +84,12 @@ export class CoreInputs implements Inputs {
return ''
}

get commit(): string {
return core.getInput('commit')
get commit(): string | undefined {
const commit = core.getInput('commit')
if (commit) {
return commit
}
return undefined
}

get createdReleaseName(): string | undefined {
Expand Down Expand Up @@ -117,6 +122,11 @@ export class CoreInputs implements Inputs {
const draft = core.getInput('draft')
return draft == 'true'
}

get generateReleaseNotes(): boolean {
const generate = core.getInput('generateReleaseNotes')
return generate == 'true'
}

get owner(): string {
let owner = core.getInput('owner')
Expand Down
3 changes: 3 additions & 0 deletions src/Releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Releases {
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
name?: string,
prerelease?: boolean
): Promise<CreateReleaseResponse>
Expand Down Expand Up @@ -72,6 +73,7 @@ export class GithubReleases implements Releases {
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
name?: string,
prerelease?: boolean
): Promise<CreateReleaseResponse> {
Expand All @@ -81,6 +83,7 @@ export class GithubReleases implements Releases {
name: name,
discussion_category_name: discussionCategory,
draft: draft,
generate_release_notes: generateReleaseNotes,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.inputs.repo,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"moduleResolution": "node",
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
Expand Down

0 comments on commit 40bb172

Please sign in to comment.