Add prerelease

This commit is contained in:
Nick Cipollo
2019-12-13 16:05:44 -05:00
parent 5ce722314c
commit cb3417d207
10 changed files with 57 additions and 20 deletions

View File

@@ -12,6 +12,7 @@ This action will create a github release and optionally upload an artifact to it
- **commit**: An optional commit reference. This will be used to create the tag if it does not exist.
- **draft**: Optionally marks this release as a draft release. Set to `true` to enable.
- **name**: An optional name for the release. If this is omitted the tag will be used.
- **prerelease**: Optionally marks this release as prerelease. Set to true to enable.
- **tag**: An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).
- **token**: (**Required**) The Github token. Typically this will be `${{ secrets.GITHUB_TOKEN }}`.

View File

@@ -19,6 +19,7 @@ const commit = 'commit'
const draft = true
const id = 100
const name = 'name'
const prerelease = true
const tag = 'tag'
const token = 'token'
const url = 'http://api.example.com'
@@ -36,7 +37,7 @@ describe("Action", () => {
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(uploadMock).not.toBeCalled()
})
@@ -49,7 +50,7 @@ describe("Action", () => {
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
@@ -58,7 +59,7 @@ describe("Action", () => {
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
@@ -73,7 +74,7 @@ describe("Action", () => {
expect(error).toEqual("error")
}
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(uploadMock).not.toBeCalled()
})
@@ -114,7 +115,7 @@ describe("Action", () => {
expect(error).toEqual("error")
}
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name)
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
expect(uploadMock).not.toBeCalled()
})
@@ -129,7 +130,7 @@ describe("Action", () => {
expect(error).toEqual("error")
}
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
@@ -138,7 +139,7 @@ describe("Action", () => {
await action.perform()
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name)
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
expect(uploadMock).not.toBeCalled()
})
@@ -148,7 +149,7 @@ describe("Action", () => {
await action.perform()
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name)
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
@@ -194,6 +195,7 @@ describe("Action", () => {
commit: commit,
draft: draft,
name: name,
prerelease: prerelease,
tag: tag,
token: token,
readArtifact: () => artifactData

View File

@@ -133,6 +133,17 @@ describe('Inputs', () => {
})
})
describe('prerelase', () => {
it('returns false', () => {
expect(inputs.prerelease).toBe(false)
})
it('returns true', () => {
mockGetInput.mockReturnValue('true')
expect(inputs.prerelease).toBe(true)
})
})
describe('tag', () => {
it('returns input tag', () => {
mockGetInput.mockReturnValue('tag')

View File

@@ -29,6 +29,9 @@ inputs:
name:
description: 'An optional name for the release. If this is omitted the tag will be used.'
default: ''
prerelease:
description: "Optionally marks this release as prerelease. Set to true to enable."
default: ''
tag:
description: 'An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).'
default: ''

View File

@@ -48,7 +48,7 @@ class Action {
}
createRelease() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
const response = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name, this.inputs.prerelease);
return response.data.upload_url;
});
}
@@ -58,7 +58,7 @@ class Action {
}
updateRelease(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name, this.inputs.prerelease);
return response.data.upload_url;
});
}

View File

@@ -58,6 +58,10 @@ class CoreInputs {
}
return this.tag;
}
get prerelease() {
const draft = core.getInput('prerelease');
return draft == 'true';
}
get tag() {
const tag = core.getInput('tag');
if (tag) {

View File

@@ -14,13 +14,14 @@ class GithubReleases {
this.context = context;
this.git = git;
}
create(tag, body, commitHash, draft, name) {
create(tag, body, commitHash, draft, name, prerelease) {
return __awaiter(this, void 0, void 0, function* () {
return this.git.repos.createRelease({
body: body,
name: name,
draft: draft,
owner: this.context.repo.owner,
prerelease: prerelease,
repo: this.context.repo.repo,
target_commitish: commitHash,
tag_name: tag
@@ -36,7 +37,7 @@ class GithubReleases {
});
});
}
update(id, tag, body, commitHash, draft, name) {
update(id, tag, body, commitHash, draft, name, prerelease) {
return __awaiter(this, void 0, void 0, function* () {
return this.git.repos.updateRelease({
release_id: id,
@@ -44,6 +45,7 @@ class GithubReleases {
name: name,
draft: draft,
owner: this.context.repo.owner,
prerelease: prerelease,
repo: this.context.repo.repo,
target_commitish: commitHash,
tag_name: tag

View File

@@ -24,7 +24,7 @@ export class Action {
}
private async createOrUpdateRelease(): Promise<string> {
if(this.inputs.allowUpdates) {
if (this.inputs.allowUpdates) {
try {
const getResponse = await this.releases.getByTag(this.inputs.tag)
return await this.updateRelease(getResponse.data.id)
@@ -46,13 +46,14 @@ export class Action {
this.inputs.body,
this.inputs.commit,
this.inputs.draft,
this.inputs.name
this.inputs.name,
this.inputs.prerelease
)
return response.data.upload_url
}
private noRelease(error:any): boolean {
private noRelease(error: any): boolean {
const errorMessage = new ErrorMessage(error)
return errorMessage.status == 404
}
@@ -64,7 +65,8 @@ export class Action {
this.inputs.body,
this.inputs.commit,
this.inputs.draft,
this.inputs.name
this.inputs.name,
this.inputs.prerelease
)
return response.data.upload_url

View File

@@ -11,6 +11,7 @@ export interface Inputs {
readonly commit: string
readonly draft: boolean
readonly name: string
readonly prerelease: boolean
readonly tag: string
readonly token: string
}
@@ -77,6 +78,11 @@ export class CoreInputs implements Inputs {
return this.tag
}
get prerelease(): boolean {
const draft = core.getInput('prerelease')
return draft == 'true'
}
get tag(): string {
const tag = core.getInput('tag')
if (tag) {

View File

@@ -8,7 +8,8 @@ export interface Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string
name?: string,
prerelease?: boolean
): Promise<Response<ReposCreateReleaseResponse>>
getByTag(tag: string): Promise<Response<ReposGetReleaseByTagResponse>>
@@ -19,7 +20,8 @@ export interface Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string
name?: string,
prerelease?: boolean
): Promise<Response<ReposCreateReleaseResponse>>
uploadArtifact(
@@ -45,13 +47,15 @@ export class GithubReleases implements Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string
name?: string,
prerelease?: boolean
): Promise<Response<ReposCreateReleaseResponse>> {
return this.git.repos.createRelease({
body: body,
name: name,
draft: draft,
owner: this.context.repo.owner,
prerelease: prerelease,
repo: this.context.repo.repo,
target_commitish: commitHash,
tag_name: tag
@@ -72,7 +76,8 @@ export class GithubReleases implements Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string
name?: string,
prerelease?: boolean
): Promise<Response<ReposCreateReleaseResponse>> {
return this.git.repos.updateRelease({
release_id: id,
@@ -80,6 +85,7 @@ export class GithubReleases implements Releases {
name: name,
draft: draft,
owner: this.context.repo.owner,
prerelease: prerelease,
repo: this.context.repo.repo,
target_commitish: commitHash,
tag_name: tag