Skip to content

Commit

Permalink
Fixes #219 Add argument to allow only updating drafts and prereleases
Browse files Browse the repository at this point in the history
  • Loading branch information
ncipollo committed Oct 2, 2022
1 parent fc32419 commit 3361abf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
8 changes: 6 additions & 2 deletions __tests__/Action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -379,7 +382,8 @@ describe("Action", () => {
updatedDraft: updateDraft,
updatedReleaseBody: updateBody,
updatedReleaseName: updateName,
updatedPrerelease: updatePrerelease
updatedPrerelease: updatePrerelease,
updateOnlyUnreleased: updateOnlyUnreleased
}
})
const MockOutputs = jest.fn<Outputs, any>(() => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/Integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Inputs {
readonly updatedReleaseBody?: string
readonly updatedReleaseName?: string
readonly updatedPrerelease?: boolean
readonly updateOnlyUnreleased: boolean
}

export class CoreInputs implements Inputs {
Expand Down Expand Up @@ -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'
Expand Down
17 changes: 17 additions & 0 deletions src/ReleaseValidator.ts
Original file line number Diff line number Diff line change
@@ -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)")
}
}
}

0 comments on commit 3361abf

Please sign in to comment.