diff --git a/__tests__/Action.test.ts b/__tests__/Action.test.ts index 2bf0bcf8..6425fd83 100644 --- a/__tests__/Action.test.ts +++ b/__tests__/Action.test.ts @@ -37,6 +37,7 @@ const updateBody = 'updateBody' const updateDraft = false const updateName = 'updateName' const updatePrerelease = false +const updateOnlyUnreleased = false const url = 'http://api.example.com' describe("Action", () => { @@ -317,7 +318,9 @@ describe("Action", () => { expect(applyReleaseDataMock).toBeCalledWith({id: releaseId, upload_url: url}) } - function createAction(allowUpdates: boolean, hasArtifact: boolean, removeArtifacts: boolean = false): Action { + function createAction(allowUpdates: boolean, + hasArtifact: boolean, + removeArtifacts: boolean = false): Action { let inputArtifact: Artifact[] if (hasArtifact) { inputArtifact = artifacts @@ -379,7 +382,8 @@ describe("Action", () => { updatedDraft: updateDraft, updatedReleaseBody: updateBody, updatedReleaseName: updateName, - updatedPrerelease: updatePrerelease + updatedPrerelease: updatePrerelease, + updateOnlyUnreleased: updateOnlyUnreleased } }) const MockOutputs = jest.fn(() => { diff --git a/__tests__/Integration.test.ts b/__tests__/Integration.test.ts index 9d83cea8..c5ad0380 100644 --- a/__tests__/Integration.test.ts +++ b/__tests__/Integration.test.ts @@ -57,7 +57,8 @@ describe.skip('Integration Test', () => { updatedDraft: false, updatedReleaseBody: "This release was generated by release-action's integration test", updatedReleaseName: "Releases Action Integration Test", - updatedPrerelease: false + updatedPrerelease: false, + updateOnlyUnreleased: false } }) return new MockInputs(); diff --git a/src/Inputs.ts b/src/Inputs.ts index d61cc3ba..e326f367 100644 --- a/src/Inputs.ts +++ b/src/Inputs.ts @@ -25,6 +25,7 @@ export interface Inputs { readonly updatedReleaseBody?: string readonly updatedReleaseName?: string readonly updatedPrerelease?: boolean + readonly updateOnlyUnreleased: boolean } export class CoreInputs implements Inputs { @@ -209,6 +210,10 @@ export class CoreInputs implements Inputs { if (CoreInputs.omitName || CoreInputs.omitNameDuringUpdate) return undefined return this.name } + + get updateOnlyUnreleased(): boolean { + return core.getInput('updateOnlyUnreleased') == 'true' + } private static get omitNameDuringUpdate(): boolean { return core.getInput('omitNameDuringUpdate') == 'true' diff --git a/src/ReleaseValidator.ts b/src/ReleaseValidator.ts new file mode 100644 index 00000000..21fc7173 --- /dev/null +++ b/src/ReleaseValidator.ts @@ -0,0 +1,17 @@ +import {Inputs} from "./Inputs"; +import {ReleaseByTagResponse} from "./Releases"; + +export class ReleaseValidator { + constructor(private inputs: Inputs) { + } + + validateReleaseUpdate(releaseResponse: ReleaseByTagResponse) { + if (!this.inputs.updateOnlyUnreleased) { + return + } + + if (!releaseResponse.data.draft && !releaseResponse.data.prerelease) { + throw new Error("Tried to update ${releaseResponse.data.name} which is neither a draft or prerelease. (updateOnlyUnreleased is on)") + } + } +} \ No newline at end of file