1 Commits

Author SHA1 Message Date
Nick Cipollo
bcf031c066 Create 1.3.0 release
Some checks failed
PR Checks / check_pr (push) Has been cancelled
2019-12-12 19:10:13 -05:00
14 changed files with 95 additions and 152 deletions

View File

@@ -12,7 +12,6 @@ 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,7 +19,6 @@ 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'
@@ -37,29 +36,16 @@ describe("Action", () => {
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).not.toBeCalled()
})
it('creates release if no release exists to update', async () => {
const action = createAction(true, true)
const error = {
status: 404
}
getMock.mockRejectedValue(error)
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
it('creates release then uploads artifact', async () => {
const action = createAction(false, true)
await action.perform()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
@@ -74,12 +60,12 @@ describe("Action", () => {
expect(error).toEqual("error")
}
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).not.toBeCalled()
})
it('throws error when get fails', async () => {
const action = createAction(true, true)
const action = createAction(true, false)
const error = {
errors: [
{
@@ -87,7 +73,7 @@ describe("Action", () => {
}
]
}
createMock.mockRejectedValue(error)
getMock.mockRejectedValue("error")
expect.hasAssertions()
@@ -96,27 +82,34 @@ describe("Action", () => {
} catch (error) {
expect(error).toEqual("error")
}
expect(getMock).toBeCalledWith(tag)
expect(updateMock).not.toBeCalled()
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).not.toBeCalled()
})
it('throws error when update fails', async () => {
const action = createAction(true, true)
const action = createAction(true, false)
const error = {
errors: [
{
code: 'already_exists'
}
]
}
createMock.mockRejectedValue(error)
updateMock.mockRejectedValue("error")
expect.hasAssertions()
try {
await action.perform()
} catch (error) {
expect(error).toEqual("error")
}
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).not.toBeCalled()
})
it('throws error when upload fails', async () => {
@@ -130,28 +123,46 @@ describe("Action", () => {
expect(error).toEqual("error")
}
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
it('updates release but does not upload if no artifact', async () => {
const action = createAction(true, false)
const error = {
errors: [
{
code: 'already_exists'
}
]
}
createMock.mockRejectedValue(error)
await action.perform()
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).not.toBeCalled()
})
it('updates release then uploads artifact', async () => {
const action = createAction(true, true)
const error = {
errors: [
{
code: 'already_exists'
}
]
}
createMock.mockRejectedValue(error)
await action.perform()
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
expect(uploadMock).toBeCalledWith(artifacts, url)
})
function createAction(allowUpdates: boolean, hasArtifact: boolean): Action {
@@ -195,7 +206,6 @@ describe("Action", () => {
commit: commit,
draft: draft,
name: name,
prerelease: prerelease,
tag: tag,
token: token,
readArtifact: () => artifactData

View File

@@ -14,16 +14,15 @@ describe('ErrorMessage', () => {
code: 'already_exists',
resource: 'release'
}
],
status: 422
]
}
it('does not have error', () => {
it('does not have error', ()=> {
const errorMessage = new ErrorMessage(error)
expect(errorMessage.hasErrorWithCode('missing_field')).toBeFalsy()
})
it('has error', () => {
it('has error', ()=> {
const errorMessage = new ErrorMessage(error)
expect(errorMessage.hasErrorWithCode('missing')).toBeTruthy()
})
@@ -42,30 +41,22 @@ describe('ErrorMessage', () => {
code: 'already_exists',
resource: 'release'
}
],
status: 422
]
}
const errorMessage = new ErrorMessage(error)
const expectedString = "Error 422: something bad happened\nErrors:\n- release does not exist.\n- release already exists."
const expectedString = "something bad happened\nErrors:\n- release does not exist.\n- release already exists."
expect(errorMessage.toString()).toBe(expectedString)
})
it('generates message without errors', () => {
const error = {
message: 'something bad happened',
status: 422
message: 'something bad happened'
}
const errorMessage = new ErrorMessage(error)
expect(errorMessage.toString()).toBe('Error 422: something bad happened')
})
it('provides error status', () => {
const error = { status: 404 }
const errorMessage = new ErrorMessage(error)
expect(errorMessage.status).toBe(404)
expect(errorMessage.toString()).toBe('something bad happened')
})
})

View File

@@ -133,17 +133,6 @@ 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,9 +29,6 @@ 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

@@ -27,38 +27,34 @@ class Action {
}
createOrUpdateRelease() {
return __awaiter(this, void 0, void 0, function* () {
if (this.inputs.allowUpdates) {
try {
const getResponse = yield this.releases.getByTag(this.inputs.tag);
return yield this.updateRelease(getResponse.data.id);
}
catch (error) {
if (this.noRelease(error)) {
return yield this.createRelease();
}
else {
throw error;
}
}
}
else {
try {
return yield this.createRelease();
}
catch (error) {
if (this.releaseAlreadyExisted(error) && this.inputs.allowUpdates) {
return this.updateRelease();
}
else {
throw error;
}
}
});
}
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, this.inputs.prerelease);
const response = yield this.releases.create(this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
return response.data.upload_url;
});
}
noRelease(error) {
releaseAlreadyExisted(error) {
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
return errorMessage.status == 404;
return errorMessage.hasErrorWithCode('already_exists');
}
updateRelease(id) {
updateRelease() {
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, this.inputs.prerelease);
const getResponse = yield this.releases.getByTag(this.inputs.tag);
const id = getResponse.data.id;
const response = yield this.releases.update(id, this.inputs.tag, this.inputs.body, this.inputs.commit, this.inputs.draft, this.inputs.name);
return response.data.upload_url;
});
}

View File

@@ -15,21 +15,17 @@ class ErrorMessage {
return [];
}
}
get status() {
return this.error.status;
}
hasErrorWithCode(code) {
return this.githubErrors.some((err) => err.code == code);
}
toString() {
const message = this.error.message;
const errors = this.githubErrors;
const status = this.status;
if (errors.length > 0) {
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`;
}
else {
return `Error ${status}: ${message}`;
return message;
}
}
errorBulletedList(errors) {

View File

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

10
node_modules/.yarn-integrity generated vendored
View File

@@ -643,13 +643,5 @@
"yargs@^13.3.0": "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83"
},
"files": [],
"artifacts": {
"fsevents@1.2.9": [
"lib",
"lib/binding",
"lib/binding/Release",
"lib/binding/Release/node-v72-darwin-x64",
"lib/binding/Release/node-v72-darwin-x64/fse.node"
]
}
"artifacts": {}
}

View File

@@ -24,19 +24,14 @@ export class Action {
}
private async createOrUpdateRelease(): Promise<string> {
if (this.inputs.allowUpdates) {
try {
const getResponse = await this.releases.getByTag(this.inputs.tag)
return await this.updateRelease(getResponse.data.id)
} catch (error) {
if (this.noRelease(error)) {
return await this.createRelease()
} else {
throw error
}
}
} else {
try {
return await this.createRelease()
} catch (error) {
if (this.releaseAlreadyExisted(error) && this.inputs.allowUpdates) {
return this.updateRelease()
} else {
throw error
}
}
}
@@ -46,27 +41,28 @@ export class Action {
this.inputs.body,
this.inputs.commit,
this.inputs.draft,
this.inputs.name,
this.inputs.prerelease
this.inputs.name
)
return response.data.upload_url
}
private noRelease(error: any): boolean {
private releaseAlreadyExisted(error: any): boolean {
const errorMessage = new ErrorMessage(error)
return errorMessage.status == 404
return errorMessage.hasErrorWithCode('already_exists')
}
private async updateRelease(id: number): Promise<string> {
private async updateRelease(): Promise<string> {
const getResponse = await this.releases.getByTag(this.inputs.tag)
const id = getResponse.data.id
const response = await this.releases.update(
id,
this.inputs.tag,
this.inputs.body,
this.inputs.commit,
this.inputs.draft,
this.inputs.name,
this.inputs.prerelease
this.inputs.name
)
return response.data.upload_url

View File

@@ -18,10 +18,6 @@ export class ErrorMessage {
}
}
get status():number {
return this.error.status
}
hasErrorWithCode(code: String): boolean {
return this.githubErrors.some((err) => err.code == code)
}
@@ -29,11 +25,10 @@ export class ErrorMessage {
toString(): string {
const message = this.error.message
const errors = this.githubErrors
const status = this.status
if (errors.length > 0) {
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`
} else {
return `Error ${status}: ${message}`
return message
}
}

View File

@@ -11,7 +11,6 @@ export interface Inputs {
readonly commit: string
readonly draft: boolean
readonly name: string
readonly prerelease: boolean
readonly tag: string
readonly token: string
}
@@ -78,11 +77,6 @@ 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,8 +8,7 @@ export interface Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string,
prerelease?: boolean
name?: string
): Promise<Response<ReposCreateReleaseResponse>>
getByTag(tag: string): Promise<Response<ReposGetReleaseByTagResponse>>
@@ -20,8 +19,7 @@ export interface Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string,
prerelease?: boolean
name?: string
): Promise<Response<ReposCreateReleaseResponse>>
uploadArtifact(
@@ -47,15 +45,13 @@ export class GithubReleases implements Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string,
prerelease?: boolean
name?: string
): 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
@@ -76,8 +72,7 @@ export class GithubReleases implements Releases {
body?: string,
commitHash?: string,
draft?: boolean,
name?: string,
prerelease?: boolean
name?: string
): Promise<Response<ReposCreateReleaseResponse>> {
return this.git.repos.updateRelease({
release_id: id,
@@ -85,7 +80,6 @@ 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