Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to ignore prerelease on update #96

Merged
merged 3 commits into from Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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.
jashandeep-sohi marked this conversation as resolved.
Show resolved Hide resolved
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).
Expand Down
12 changes: 7 additions & 5 deletions __tests__/Action.test.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -153,7 +154,7 @@ describe("Action", () => {
discussionCategory,
draft,
updateName,
prerelease
updatePrerelease
)
expect(uploadMock).not.toBeCalled()
})
Expand Down Expand Up @@ -195,7 +196,7 @@ describe("Action", () => {
discussionCategory,
draft,
updateName,
prerelease
updatePrerelease
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()
Expand All @@ -214,7 +215,7 @@ describe("Action", () => {
discussionCategory,
draft,
updateName,
prerelease
updatePrerelease
)
expect(uploadMock).not.toBeCalled()
assertOutputApplied()
Expand All @@ -233,7 +234,7 @@ describe("Action", () => {
discussionCategory,
draft,
updateName,
prerelease
updatePrerelease
)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
assertOutputApplied()
Expand Down Expand Up @@ -301,7 +302,8 @@ describe("Action", () => {
tag: tag,
token: token,
updatedReleaseBody: updateBody,
updatedReleaseName: updateName
updatedReleaseName: updateName,
updatedPrerelease: updatePrerelease
}
})
const MockOutputs = jest.fn<Outputs, any>(() => {
Expand Down
23 changes: 23 additions & 0 deletions __tests__/Inputs.test.ts
Expand Up @@ -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<ArtifactGlobber, any>(() => {
return {
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -71,6 +71,10 @@ inputs:
description: "Optionally marks this release as prerelease. Set to true to enable."
required: false
default: ''
omitPrereleaseDuringUpdate:
jashandeep-sohi marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 1 addition & 1 deletion lib/Action.js
Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions lib/Inputs.js
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/Action.ts
Expand Up @@ -69,7 +69,7 @@ export class Action {
this.inputs.discussionCategory,
this.inputs.draft,
this.inputs.updatedReleaseName,
this.inputs.prerelease
this.inputs.updatedPrerelease
)
}

Expand Down
9 changes: 9 additions & 0 deletions src/Inputs.ts
Expand Up @@ -21,6 +21,7 @@ export interface Inputs {
readonly token: string
readonly updatedReleaseBody?: string
readonly updatedReleaseName?: string
readonly updatedPrerelease?: boolean
}

export class CoreInputs implements Inputs {
Expand Down Expand Up @@ -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
}
jashandeep-sohi marked this conversation as resolved.
Show resolved Hide resolved
get replacesArtifacts(): boolean {
const replaces = core.getInput('replacesArtifacts')
return replaces == 'true'
Expand Down