Add make_latest option (#283)

This commit is contained in:
Eric Cornelissen
2022-12-11 19:45:00 +01:00
committed by GitHub
parent 3dd806f2bf
commit 0bf6967166
10 changed files with 70 additions and 4 deletions

View File

@@ -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 |

View File

@@ -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(() => {
@@ -63,6 +64,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease)
expect(uploadMock).not.toBeCalled()
@@ -83,6 +85,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease)
expect(uploadMock).toBeCalledWith(artifacts, releaseId, url)
@@ -108,6 +111,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
@@ -128,6 +132,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
@@ -181,6 +186,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
@@ -231,6 +237,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
@@ -256,6 +263,7 @@ describe("Action", () => {
discussionCategory,
createDraft,
generateReleaseNotes,
makeLatest,
createName,
createPrerelease
)
@@ -282,6 +290,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
@@ -301,6 +310,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
@@ -320,6 +330,7 @@ describe("Action", () => {
commit,
discussionCategory,
updateDraft,
makeLatest,
updateName,
updatePrerelease
)
@@ -386,6 +397,7 @@ describe("Action", () => {
commit: commit,
discussionCategory: discussionCategory,
generateReleaseNotes: true,
makeLatest: makeLatest,
owner: "owner",
createdPrerelease: createPrerelease,
replacesArtifacts: replacesArtifacts,

View File

@@ -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"

View File

@@ -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

View File

@@ -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) {
@@ -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);
});
}
}

View File

@@ -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) {

View File

@@ -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({
@@ -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,
@@ -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({
@@ -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,

View File

@@ -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
)
@@ -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
)

View File

@@ -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
@@ -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) {

View File

@@ -25,6 +25,7 @@ export interface Releases {
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<CreateReleaseResponse>
@@ -44,6 +45,7 @@ export interface Releases {
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<UpdateReleaseResponse>
@@ -74,6 +76,7 @@ export class GithubReleases implements Releases {
discussionCategory?: string,
draft?: boolean,
generateReleaseNotes?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<CreateReleaseResponse> {
@@ -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,
@@ -134,6 +138,7 @@ export class GithubReleases implements Releases {
commitHash?: string,
discussionCategory?: string,
draft?: boolean,
makeLatest?: string,
name?: string,
prerelease?: boolean
): Promise<UpdateReleaseResponse> {
@@ -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,