From 7eaf77f5f1451f6bfe2ce9b60431d1da9cf2ff7b Mon Sep 17 00:00:00 2001 From: Jashandeep Sohi Date: Mon, 26 Jul 2021 21:35:31 -0700 Subject: [PATCH 1/3] add option to ignore prerelease on update --- README.md | 2 ++ __tests__/Action.test.ts | 12 +++++++----- __tests__/Inputs.test.ts | 23 +++++++++++++++++++++++ action.yml | 4 ++++ lib/Action.js | 2 +- lib/Inputs.js | 8 ++++++++ src/Action.ts | 2 +- src/Inputs.ts | 9 +++++++++ 8 files changed, 55 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8b52c4e6..70f6ee80 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ This action will create a GitHub release and optionally upload an artifact to it - **omitNameDuringUpdate**: Indicates if the release name should be omitted during updates. The name will still be applied for newly created releases. This will preserve the existing name during updates. - **owner**: Optionally specify the owner of the repo where the release should be generated. Defaults to current repo's owner. - **prerelease**: Optionally marks this release as prerelease. Set to true to enable. +- **omitPrereleaseDuringUpdate**: Indicates if the prerelease flag should be omitted during updates. The prerelease flag will still be applied for newly created releases. + This will preserve the existing prerelease state during updates. - **replacesArtifacts**: Indicates if existing release artifacts should be replaced. Defaults to `true`. - **repo**: Optionally specify the repo where the release should be generated. Defaults to current repo. - **tag**: An optional tag for the release. If this is omitted the git ref will be used (if it is a tag). diff --git a/__tests__/Action.test.ts b/__tests__/Action.test.ts index 7ab56a45..09f0bb8f 100644 --- a/__tests__/Action.test.ts +++ b/__tests__/Action.test.ts @@ -26,6 +26,7 @@ const discussionCategory = 'discussionCategory' const draft = true const id = 100 const prerelease = true +const updatePrerelease = false const releaseId = 101 const replacesArtifacts = true const tag = 'tag' @@ -153,7 +154,7 @@ describe("Action", () => { discussionCategory, draft, updateName, - prerelease + updatePrerelease ) expect(uploadMock).not.toBeCalled() }) @@ -195,7 +196,7 @@ describe("Action", () => { discussionCategory, draft, updateName, - prerelease + updatePrerelease ) expect(uploadMock).toBeCalledWith(artifacts, releaseId, url) assertOutputApplied() @@ -214,7 +215,7 @@ describe("Action", () => { discussionCategory, draft, updateName, - prerelease + updatePrerelease ) expect(uploadMock).not.toBeCalled() assertOutputApplied() @@ -233,7 +234,7 @@ describe("Action", () => { discussionCategory, draft, updateName, - prerelease + updatePrerelease ) expect(uploadMock).toBeCalledWith(artifacts, releaseId, url) assertOutputApplied() @@ -301,7 +302,8 @@ describe("Action", () => { tag: tag, token: token, updatedReleaseBody: updateBody, - updatedReleaseName: updateName + updatedReleaseName: updateName, + updatedPrerelease: updatePrerelease } }) const MockOutputs = jest.fn(() => { diff --git a/__tests__/Inputs.test.ts b/__tests__/Inputs.test.ts index 73d54503..a3aa65c1 100644 --- a/__tests__/Inputs.test.ts +++ b/__tests__/Inputs.test.ts @@ -349,6 +349,29 @@ describe('Inputs', () => { }) }) + describe('updatedPrerelease', () => { + it('returns false', () => { + mockGetInput + .mockReturnValueOnce('false') + .mockReturnValueOnce('false') + expect(inputs.updatedPrerelease).toBe(false) + }) + + it('returns true', () => { + mockGetInput + .mockReturnValueOnce('false') + .mockReturnValueOnce('true') + expect(inputs.updatedPrerelease).toBe(true) + }) + + it('returns undefined when omitted for update', () => { + mockGetInput + .mockReturnValueOnce('true') + .mockReturnValueOnce('false') + expect(inputs.updatedPrerelease).toBeUndefined() + }) + }) + function createGlobber(): ArtifactGlobber { const MockGlobber = jest.fn(() => { return { diff --git a/action.yml b/action.yml index 062ca8f2..442d03b0 100644 --- a/action.yml +++ b/action.yml @@ -71,6 +71,10 @@ inputs: description: "Optionally marks this release as prerelease. Set to true to enable." required: false default: '' + omitPrereleaseDuringUpdate: + description: 'Indicates if the prerelease flag should be omitted during updates. The prerelease flag will still be applied for newly created releases. This will preserve the existing prerelease state during updates.' + required: false + default: 'false' replacesArtifacts: description: "Indicates if existing release artifacts should be replaced. Defaults to true." required: false diff --git a/lib/Action.js b/lib/Action.js index c72ab744..afd76571 100644 --- a/lib/Action.js +++ b/lib/Action.js @@ -60,7 +60,7 @@ class Action { } updateRelease(id) { return __awaiter(this, void 0, void 0, function* () { - return yield this.releases.update(id, this.inputs.tag, this.inputs.updatedReleaseBody, this.inputs.commit, this.inputs.discussionCategory, this.inputs.draft, this.inputs.updatedReleaseName, this.inputs.prerelease); + return yield this.releases.update(id, this.inputs.tag, this.inputs.updatedReleaseBody, this.inputs.commit, this.inputs.discussionCategory, this.inputs.draft, this.inputs.updatedReleaseName, this.inputs.updatedPrerelease); }); } static noPublishedRelease(error) { diff --git a/lib/Inputs.js b/lib/Inputs.js index 108e2690..38467db2 100644 --- a/lib/Inputs.js +++ b/lib/Inputs.js @@ -109,6 +109,14 @@ class CoreInputs { const preRelease = core.getInput('prerelease'); return preRelease == 'true'; } + static get omitPrereleaseDuringUpdate() { + return core.getInput('omitPrereleaseDuringUpdate') == 'true'; + } + get updatedPrerelease() { + if (CoreInputs.omitPrereleaseDuringUpdate) + return undefined; + return this.prerelease; + } get replacesArtifacts() { const replaces = core.getInput('replacesArtifacts'); return replaces == 'true'; diff --git a/src/Action.ts b/src/Action.ts index 2f89dcf5..58c4b4a6 100644 --- a/src/Action.ts +++ b/src/Action.ts @@ -69,7 +69,7 @@ export class Action { this.inputs.discussionCategory, this.inputs.draft, this.inputs.updatedReleaseName, - this.inputs.prerelease + this.inputs.updatedPrerelease ) } diff --git a/src/Inputs.ts b/src/Inputs.ts index dde882ba..53433178 100644 --- a/src/Inputs.ts +++ b/src/Inputs.ts @@ -21,6 +21,7 @@ export interface Inputs { readonly token: string readonly updatedReleaseBody?: string readonly updatedReleaseName?: string + readonly updatedPrerelease?: boolean } export class CoreInputs implements Inputs { @@ -129,6 +130,14 @@ export class CoreInputs implements Inputs { return preRelease == 'true' } + private static get omitPrereleaseDuringUpdate(): boolean { + return core.getInput('omitPrereleaseDuringUpdate') == 'true' + } + + get updatedPrerelease(): boolean | undefined { + if (CoreInputs.omitPrereleaseDuringUpdate) return undefined + return this.prerelease + } get replacesArtifacts(): boolean { const replaces = core.getInput('replacesArtifacts') return replaces == 'true' From 8fa659e9a6a1f47d74e06c258eb225cd07fab93d Mon Sep 17 00:00:00 2001 From: Jashandeep Sohi Date: Wed, 28 Jul 2021 15:42:51 -0700 Subject: [PATCH 2/3] fix formatting --- README.md | 4 ++-- action.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 70f6ee80..9f25219d 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ This action will create a GitHub release and optionally upload an artifact to it - **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. - **omitName**: Indicates if the release name should be omitted. - **omitNameDuringUpdate**: Indicates if the release name should be omitted during updates. The name will still be applied for newly created releases. This will preserve the existing name during updates. -- **owner**: Optionally specify the owner of the repo where the release should be generated. Defaults to current repo's owner. -- **prerelease**: Optionally marks this release as prerelease. Set to true to enable. - **omitPrereleaseDuringUpdate**: Indicates if the prerelease flag should be omitted during updates. The prerelease flag will still be applied for newly created releases. This will preserve the existing prerelease state during updates. +- **owner**: Optionally specify the owner of the repo where the release should be generated. Defaults to current repo's owner. +- **prerelease**: Optionally marks this release as prerelease. Set to true to enable. - **replacesArtifacts**: Indicates if existing release artifacts should be replaced. Defaults to `true`. - **repo**: Optionally specify the repo where the release should be generated. Defaults to current repo. - **tag**: An optional tag for the release. If this is omitted the git ref will be used (if it is a tag). diff --git a/action.yml b/action.yml index 442d03b0..57342177 100644 --- a/action.yml +++ b/action.yml @@ -63,6 +63,10 @@ inputs: description: 'Indicates if the release name should be omitted during updates. The name will still be applied for newly created releases. This will preserve the existing name during updates.' required: false default: 'false' + omitPrereleaseDuringUpdate: + description: 'Indicates if the prerelease flag should be omitted during updates. The prerelease flag will still be applied for newly created releases. This will preserve the existing prerelease state during updates.' + required: false + default: 'false' owner: description: "Optionally specify the owner of the repo where the release should be generated. Defaults to current repo's owner." required: false @@ -71,10 +75,6 @@ inputs: description: "Optionally marks this release as prerelease. Set to true to enable." required: false default: '' - omitPrereleaseDuringUpdate: - description: 'Indicates if the prerelease flag should be omitted during updates. The prerelease flag will still be applied for newly created releases. This will preserve the existing prerelease state during updates.' - required: false - default: 'false' replacesArtifacts: description: "Indicates if existing release artifacts should be replaced. Defaults to true." required: false From 2cb90c8a372bcd3735bce3bdbca1608b76287a38 Mon Sep 17 00:00:00 2001 From: Jashandeep Sohi Date: Wed, 28 Jul 2021 15:54:16 -0700 Subject: [PATCH 3/3] rename prerelease getter to createdPrerelease --- __tests__/Action.test.ts | 16 ++++++++-------- __tests__/Inputs.test.ts | 6 +++--- __tests__/Integration.test.ts | 5 +++-- lib/Action.js | 2 +- lib/Inputs.js | 4 ++-- src/Action.ts | 2 +- src/Inputs.ts | 6 +++--- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/__tests__/Action.test.ts b/__tests__/Action.test.ts index 09f0bb8f..0f21b31d 100644 --- a/__tests__/Action.test.ts +++ b/__tests__/Action.test.ts @@ -25,7 +25,7 @@ const commit = 'commit' const discussionCategory = 'discussionCategory' const draft = true const id = 100 -const prerelease = true +const createPrerelease = true const updatePrerelease = false const releaseId = 101 const replacesArtifacts = true @@ -49,7 +49,7 @@ describe("Action", () => { await action.perform() - expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, prerelease) + expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease) expect(uploadMock).not.toBeCalled() assertOutputApplied() }) @@ -61,7 +61,7 @@ describe("Action", () => { await action.perform() - expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, prerelease) + expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease) expect(uploadMock).toBeCalledWith(artifacts, releaseId, url) assertOutputApplied() }) @@ -78,7 +78,7 @@ describe("Action", () => { await action.perform() - expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, prerelease) + expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease) expect(uploadMock).toBeCalledWith(artifacts, releaseId, url) assertOutputApplied() @@ -89,7 +89,7 @@ describe("Action", () => { await action.perform() - expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, prerelease) + expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease) expect(uploadMock).toBeCalledWith(artifacts, releaseId, url) assertOutputApplied() }) @@ -105,7 +105,7 @@ describe("Action", () => { expect(error).toEqual("error") } - expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, prerelease) + expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease) expect(uploadMock).not.toBeCalled() }) @@ -171,7 +171,7 @@ describe("Action", () => { expect(error).toEqual(expectedError) } - expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, prerelease) + expect(createMock).toBeCalledWith(tag, createBody, commit, discussionCategory, draft, createName, createPrerelease) expect(uploadMock).toBeCalledWith(artifacts, releaseId, url) }) @@ -296,7 +296,7 @@ describe("Action", () => { discussionCategory: discussionCategory, draft: draft, owner: "owner", - prerelease: prerelease, + createdPrerelease: createPrerelease, replacesArtifacts: replacesArtifacts, repo: "repo", tag: tag, diff --git a/__tests__/Inputs.test.ts b/__tests__/Inputs.test.ts index a3aa65c1..6f8d8aea 100644 --- a/__tests__/Inputs.test.ts +++ b/__tests__/Inputs.test.ts @@ -214,14 +214,14 @@ describe('Inputs', () => { }); }) - describe('prerelase', () => { + describe('createdPrerelase', () => { it('returns false', () => { - expect(inputs.prerelease).toBe(false) + expect(inputs.createdPrerelease).toBe(false) }) it('returns true', () => { mockGetInput.mockReturnValue('true') - expect(inputs.prerelease).toBe(true) + expect(inputs.createdPrerelease).toBe(true) }) }) diff --git a/__tests__/Integration.test.ts b/__tests__/Integration.test.ts index 810e0de8..d35fad6a 100644 --- a/__tests__/Integration.test.ts +++ b/__tests__/Integration.test.ts @@ -44,13 +44,14 @@ describe.skip('Integration Test', () => { discussionCategory: 'Release', draft: false, owner: "ncipollo", - prerelease: false, + createdPrerelease: false, replacesArtifacts: true, repo: "actions-playground", tag: "release-action-test", token: getToken(), updatedReleaseBody: "This release was generated by release-action's integration test", - updatedReleaseName: "Releases Action Integration Test" + updatedReleaseName: "Releases Action Integration Test", + updatedPrerelease: false } }) return new MockInputs(); diff --git a/lib/Action.js b/lib/Action.js index afd76571..5ce047ad 100644 --- a/lib/Action.js +++ b/lib/Action.js @@ -89,7 +89,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.prerelease); + 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); }); } } diff --git a/lib/Inputs.js b/lib/Inputs.js index 38467db2..2c5543c8 100644 --- a/lib/Inputs.js +++ b/lib/Inputs.js @@ -105,7 +105,7 @@ class CoreInputs { } return this.context.repo.owner; } - get prerelease() { + get createdPrerelease() { const preRelease = core.getInput('prerelease'); return preRelease == 'true'; } @@ -115,7 +115,7 @@ class CoreInputs { get updatedPrerelease() { if (CoreInputs.omitPrereleaseDuringUpdate) return undefined; - return this.prerelease; + return this.createdPrerelease; } get replacesArtifacts() { const replaces = core.getInput('replacesArtifacts'); diff --git a/src/Action.ts b/src/Action.ts index 58c4b4a6..34dadb02 100644 --- a/src/Action.ts +++ b/src/Action.ts @@ -104,7 +104,7 @@ export class Action { this.inputs.discussionCategory, this.inputs.draft, this.inputs.createdReleaseName, - this.inputs.prerelease + this.inputs.createdPrerelease ) } } diff --git a/src/Inputs.ts b/src/Inputs.ts index 53433178..5d22a3a5 100644 --- a/src/Inputs.ts +++ b/src/Inputs.ts @@ -14,7 +14,7 @@ export interface Inputs { readonly discussionCategory?: string readonly draft: boolean readonly owner: string - readonly prerelease: boolean + readonly createdPrerelease: boolean readonly replacesArtifacts: boolean readonly repo: string readonly tag: string @@ -125,7 +125,7 @@ export class CoreInputs implements Inputs { return this.context.repo.owner } - get prerelease(): boolean { + get createdPrerelease(): boolean { const preRelease = core.getInput('prerelease') return preRelease == 'true' } @@ -136,7 +136,7 @@ export class CoreInputs implements Inputs { get updatedPrerelease(): boolean | undefined { if (CoreInputs.omitPrereleaseDuringUpdate) return undefined - return this.prerelease + return this.createdPrerelease } get replacesArtifacts(): boolean { const replaces = core.getInput('replacesArtifacts')