Skip to content

Commit

Permalink
Add make_latest option (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcornelissen authored Dec 11, 2022
1 parent 3dd806f commit 0bf6967
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This action will create a GitHub release and optionally upload an artifact to it
| 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 | false | "" |
| draft | Optionally marks this release as a draft release. Set to true to enable. | false | "" |
| generateReleaseNotes | Indicates if release notes should be automatically generated. | false | false |
| makeLatest | Indicates if the release should be the "latest" release or not. release. | false | "legacy" |
| name | An optional name for the release. If this is omitted the tag will be used. | false | "" |
| omitBody | Indicates if the release body should be omitted. | false | false |
| 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. | false | false |
Expand Down
12 changes: 12 additions & 0 deletions __tests__/Action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const updateName = 'updateName'
const updatePrerelease = false
const updateOnlyUnreleased = false
const url = 'http://api.example.com'
const makeLatest = 'legacy'

describe("Action", () => {
beforeEach(() => {
Expand All @@ -63,6 +64,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease)
expect(uploadMock).not.toBeCalled()
Expand All @@ -83,6 +85,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
Expand All @@ -108,6 +111,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
Expand All @@ -128,6 +132,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
Expand Down Expand Up @@ -181,6 +186,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
Expand Down Expand Up @@ -231,6 +237,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
Expand All @@ -256,6 +263,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
Expand All @@ -282,6 +290,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
Expand All @@ -301,6 +310,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
Expand All @@ -320,6 +330,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
Expand Down Expand Up @@ -386,6 +397,7 @@ describe("Action", () => {
commit: commit,
discussionCategory: discussionCategory,
generateReleaseNotes: true,
makeLatest: makeLatest,
owner: "owner",
createdPrerelease: createPrerelease,
replacesArtifacts: replacesArtifacts,
Expand Down
22 changes: 22 additions & 0 deletions __tests__/Inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ describe('Inputs', () => {
});
})

describe('makeLatest', () => {
it('returns legacy', () => {
mockGetInput.mockReturnValueOnce('legacy')
expect(inputs.makeLatest).toBe('legacy')
})

it('returns false', () => {
mockGetInput.mockReturnValueOnce('false')
expect(inputs.makeLatest).toBe('false')
})

it('returns true', () => {
mockGetInput.mockReturnValueOnce('true')
expect(inputs.makeLatest).toBe('true')
})

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

describe('owner', () => {
it('returns owner from context', function () {
process.env.GITHUB_REPOSITORY = "owner/repo"
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ inputs:
description: 'Indicates if release notes should be automatically generated.'
required: false
default: 'false'
makeLatest:
description: 'Indicates if the release should be the "latest" release or not.'
required: false
default: 'legacy'
name:
description: 'An optional name for the release. If this is omitted the tag will be used.'
required: false
Expand Down
4 changes: 2 additions & 2 deletions lib/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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.updatedDraft, this.inputs.updatedReleaseName, this.inputs.updatedPrerelease);
return yield this.releases.update(id, this.inputs.tag, this.inputs.updatedReleaseBody, this.inputs.commit, this.inputs.discussionCategory, this.inputs.updatedDraft, this.inputs.makeLatest, this.inputs.updatedReleaseName, this.inputs.updatedPrerelease);
});
}
static noPublishedRelease(error) {
Expand Down Expand Up @@ -126,7 +126,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.createdDraft, this.inputs.generateReleaseNotes, 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.createdDraft, this.inputs.generateReleaseNotes, this.inputs.makeLatest, this.inputs.createdReleaseName, this.inputs.createdPrerelease);
});
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/Inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ class CoreInputs {
const generate = core.getInput('generateReleaseNotes');
return generate == 'true';
}
get makeLatest() {
const makeLatest = core.getInput('makeLatest');
if (makeLatest) {
return makeLatest;
}
return undefined;
}
get owner() {
let owner = core.getInput('owner');
if (owner) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GithubReleases {
this.inputs = inputs;
this.git = git;
}
create(tag, body, commitHash, discussionCategory, draft, generateReleaseNotes, name, prerelease) {
create(tag, body, commitHash, discussionCategory, draft, generateReleaseNotes, makeLatest, name, prerelease) {
return __awaiter(this, void 0, void 0, function* () {
// noinspection TypeScriptValidateJSTypes
return this.git.rest.repos.createRelease({
Expand All @@ -24,6 +24,7 @@ class GithubReleases {
discussion_category_name: discussionCategory,
draft: draft,
generate_release_notes: generateReleaseNotes,
make_latest: makeLatest,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.inputs.repo,
Expand Down Expand Up @@ -67,7 +68,7 @@ class GithubReleases {
});
});
}
update(id, tag, body, commitHash, discussionCategory, draft, name, prerelease) {
update(id, tag, body, commitHash, discussionCategory, draft, makeLatest, name, prerelease) {
return __awaiter(this, void 0, void 0, function* () {
// noinspection TypeScriptValidateJSTypes
return this.git.rest.repos.updateRelease({
Expand All @@ -76,6 +77,7 @@ class GithubReleases {
name: name,
discussion_category_name: discussionCategory,
draft: draft,
make_latest: makeLatest,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.inputs.repo,
Expand Down
2 changes: 2 additions & 0 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class Action {
this.inputs.commit,
this.inputs.discussionCategory,
this.inputs.updatedDraft,
this.inputs.makeLatest,
this.inputs.updatedReleaseName,
this.inputs.updatedPrerelease
)
Expand Down Expand Up @@ -132,6 +133,7 @@ export class Action {
this.inputs.discussionCategory,
this.inputs.createdDraft,
this.inputs.generateReleaseNotes,
this.inputs.makeLatest,
this.inputs.createdReleaseName,
this.inputs.createdPrerelease
)
Expand Down
10 changes: 10 additions & 0 deletions src/Inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Inputs {
readonly createdReleaseName?: string
readonly discussionCategory?: string
readonly generateReleaseNotes: boolean
readonly makeLatest?: string
readonly owner: string
readonly removeArtifacts: boolean
readonly replacesArtifacts: boolean
Expand Down Expand Up @@ -136,6 +137,15 @@ export class CoreInputs implements Inputs {
return generate == 'true'
}

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

return undefined
}

get owner(): string {
let owner = core.getInput('owner')
if (owner) {
Expand Down
6 changes: 6 additions & 0 deletions src/Releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Releases {
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<CreateReleaseResponse>
Expand All @@ -44,6 +45,7 @@ export interface Releases {
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<UpdateReleaseResponse>
Expand Down Expand Up @@ -74,6 +76,7 @@ export class GithubReleases implements Releases {
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<CreateReleaseResponse> {
Expand All @@ -84,6 +87,7 @@ export class GithubReleases implements Releases {
discussion_category_name: discussionCategory,
draft: draft,
generate_release_notes: generateReleaseNotes,
make_latest: makeLatest,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.inputs.repo,
Expand Down Expand Up @@ -134,6 +138,7 @@ export class GithubReleases implements Releases {
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<UpdateReleaseResponse> {
Expand All @@ -144,6 +149,7 @@ export class GithubReleases implements Releases {
name: name,
discussion_category_name: discussionCategory,
draft: draft,
make_latest: makeLatest,
owner: this.inputs.owner,
prerelease: prerelease,
repo: this.inputs.repo,
Expand Down

0 comments on commit 0bf6967

Please sign in to comment.