Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e75a11bff3 | ||
|
|
cb3417d207 | ||
|
|
5ce722314c | ||
|
|
734853d8c8 | ||
|
|
b25a3c63b3 |
@@ -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.
|
- **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.
|
- **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.
|
- **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).
|
- **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 }}`.
|
- **token**: (**Required**) The Github token. Typically this will be `${{ secrets.GITHUB_TOKEN }}`.
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const commit = 'commit'
|
|||||||
const draft = true
|
const draft = true
|
||||||
const id = 100
|
const id = 100
|
||||||
const name = 'name'
|
const name = 'name'
|
||||||
|
const prerelease = true
|
||||||
const tag = 'tag'
|
const tag = 'tag'
|
||||||
const token = 'token'
|
const token = 'token'
|
||||||
const url = 'http://api.example.com'
|
const url = 'http://api.example.com'
|
||||||
@@ -36,16 +37,29 @@ describe("Action", () => {
|
|||||||
|
|
||||||
await action.perform()
|
await action.perform()
|
||||||
|
|
||||||
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
|
expect(createMock).toBeCalledWith(tag, body, commit, draft, name, prerelease)
|
||||||
expect(uploadMock).not.toBeCalled()
|
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 () => {
|
it('creates release then uploads artifact', async () => {
|
||||||
const action = createAction(false, true)
|
const action = createAction(false, true)
|
||||||
|
|
||||||
await action.perform()
|
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)
|
expect(uploadMock).toBeCalledWith(artifacts, url)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -60,12 +74,12 @@ describe("Action", () => {
|
|||||||
expect(error).toEqual("error")
|
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()
|
expect(uploadMock).not.toBeCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws error when get fails', async () => {
|
it('throws error when get fails', async () => {
|
||||||
const action = createAction(true, false)
|
const action = createAction(true, true)
|
||||||
const error = {
|
const error = {
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
@@ -73,7 +87,7 @@ describe("Action", () => {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
createMock.mockRejectedValue(error)
|
createMock.mockRejectedValue(error)
|
||||||
getMock.mockRejectedValue("error")
|
getMock.mockRejectedValue("error")
|
||||||
expect.hasAssertions()
|
expect.hasAssertions()
|
||||||
@@ -82,34 +96,27 @@ describe("Action", () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error).toEqual("error")
|
expect(error).toEqual("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
|
expect(getMock).toBeCalledWith(tag)
|
||||||
|
expect(updateMock).not.toBeCalled()
|
||||||
expect(uploadMock).not.toBeCalled()
|
expect(uploadMock).not.toBeCalled()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws error when update fails', async () => {
|
it('throws error when update fails', async () => {
|
||||||
const action = createAction(true, false)
|
const action = createAction(true, true)
|
||||||
const error = {
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
code: 'already_exists'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
createMock.mockRejectedValue(error)
|
|
||||||
updateMock.mockRejectedValue("error")
|
updateMock.mockRejectedValue("error")
|
||||||
|
|
||||||
expect.hasAssertions()
|
expect.hasAssertions()
|
||||||
try {
|
try {
|
||||||
await action.perform()
|
await action.perform()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
expect(error).toEqual("error")
|
expect(error).toEqual("error")
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
|
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
|
||||||
expect(uploadMock).not.toBeCalled()
|
expect(uploadMock).not.toBeCalled()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws error when upload fails', async () => {
|
it('throws error when upload fails', async () => {
|
||||||
@@ -123,46 +130,28 @@ describe("Action", () => {
|
|||||||
expect(error).toEqual("error")
|
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)
|
expect(uploadMock).toBeCalledWith(artifacts, url)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates release but does not upload if no artifact', async () => {
|
it('updates release but does not upload if no artifact', async () => {
|
||||||
const action = createAction(true, false)
|
const action = createAction(true, false)
|
||||||
const error = {
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
code: 'already_exists'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
createMock.mockRejectedValue(error)
|
|
||||||
|
|
||||||
await action.perform()
|
await action.perform()
|
||||||
|
|
||||||
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
|
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
|
||||||
expect(uploadMock).not.toBeCalled()
|
expect(uploadMock).not.toBeCalled()
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updates release then uploads artifact', async () => {
|
it('updates release then uploads artifact', async () => {
|
||||||
const action = createAction(true, true)
|
const action = createAction(true, true)
|
||||||
const error = {
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
code: 'already_exists'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
createMock.mockRejectedValue(error)
|
|
||||||
|
|
||||||
await action.perform()
|
await action.perform()
|
||||||
|
|
||||||
expect(createMock).toBeCalledWith(tag, body, commit, draft, name)
|
expect(updateMock).toBeCalledWith(id, tag, body, commit, draft, name, prerelease)
|
||||||
expect(uploadMock).toBeCalledWith(artifacts, url)
|
expect(uploadMock).toBeCalledWith(artifacts, url)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function createAction(allowUpdates: boolean, hasArtifact: boolean): Action {
|
function createAction(allowUpdates: boolean, hasArtifact: boolean): Action {
|
||||||
@@ -206,6 +195,7 @@ describe("Action", () => {
|
|||||||
commit: commit,
|
commit: commit,
|
||||||
draft: draft,
|
draft: draft,
|
||||||
name: name,
|
name: name,
|
||||||
|
prerelease: prerelease,
|
||||||
tag: tag,
|
tag: tag,
|
||||||
token: token,
|
token: token,
|
||||||
readArtifact: () => artifactData
|
readArtifact: () => artifactData
|
||||||
|
|||||||
@@ -14,15 +14,16 @@ describe('ErrorMessage', () => {
|
|||||||
code: 'already_exists',
|
code: 'already_exists',
|
||||||
resource: 'release'
|
resource: 'release'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
it('does not have error', ()=> {
|
it('does not have error', () => {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
expect(errorMessage.hasErrorWithCode('missing_field')).toBeFalsy()
|
expect(errorMessage.hasErrorWithCode('missing_field')).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has error', ()=> {
|
it('has error', () => {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
expect(errorMessage.hasErrorWithCode('missing')).toBeTruthy()
|
expect(errorMessage.hasErrorWithCode('missing')).toBeTruthy()
|
||||||
})
|
})
|
||||||
@@ -41,22 +42,30 @@ describe('ErrorMessage', () => {
|
|||||||
code: 'already_exists',
|
code: 'already_exists',
|
||||||
resource: 'release'
|
resource: 'release'
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
|
|
||||||
const expectedString = "something bad happened\nErrors:\n- release does not exist.\n- release already exists."
|
const expectedString = "Error 422: something bad happened\nErrors:\n- release does not exist.\n- release already exists."
|
||||||
expect(errorMessage.toString()).toBe(expectedString)
|
expect(errorMessage.toString()).toBe(expectedString)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('generates message without errors', () => {
|
it('generates message without errors', () => {
|
||||||
const error = {
|
const error = {
|
||||||
message: 'something bad happened'
|
message: 'something bad happened',
|
||||||
|
status: 422
|
||||||
}
|
}
|
||||||
|
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
|
|
||||||
expect(errorMessage.toString()).toBe('something bad happened')
|
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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -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', () => {
|
describe('tag', () => {
|
||||||
it('returns input tag', () => {
|
it('returns input tag', () => {
|
||||||
mockGetInput.mockReturnValue('tag')
|
mockGetInput.mockReturnValue('tag')
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ inputs:
|
|||||||
name:
|
name:
|
||||||
description: 'An optional name for the release. If this is omitted the tag will be used.'
|
description: 'An optional name for the release. If this is omitted the tag will be used.'
|
||||||
default: ''
|
default: ''
|
||||||
|
prerelease:
|
||||||
|
description: "Optionally marks this release as prerelease. Set to true to enable."
|
||||||
|
default: ''
|
||||||
tag:
|
tag:
|
||||||
description: 'An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).'
|
description: 'An optional tag for the release. If this is omitted the git ref will be used (if it is a tag).'
|
||||||
default: ''
|
default: ''
|
||||||
|
|||||||
@@ -27,34 +27,38 @@ class Action {
|
|||||||
}
|
}
|
||||||
createOrUpdateRelease() {
|
createOrUpdateRelease() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
if (this.inputs.allowUpdates) {
|
||||||
return yield this.createRelease();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
else {
|
||||||
if (this.releaseAlreadyExisted(error) && this.inputs.allowUpdates) {
|
return yield this.createRelease();
|
||||||
return this.updateRelease();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
createRelease() {
|
createRelease() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
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;
|
return response.data.upload_url;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
releaseAlreadyExisted(error) {
|
noRelease(error) {
|
||||||
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
|
const errorMessage = new ErrorMessage_1.ErrorMessage(error);
|
||||||
return errorMessage.hasErrorWithCode('already_exists');
|
return errorMessage.status == 404;
|
||||||
}
|
}
|
||||||
updateRelease() {
|
updateRelease(id) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const getResponse = yield this.releases.getByTag(this.inputs.tag);
|
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 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;
|
return response.data.upload_url;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,21 @@ class ErrorMessage {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
get status() {
|
||||||
|
return this.error.status;
|
||||||
|
}
|
||||||
hasErrorWithCode(code) {
|
hasErrorWithCode(code) {
|
||||||
return this.githubErrors.some((err) => err.code == code);
|
return this.githubErrors.some((err) => err.code == code);
|
||||||
}
|
}
|
||||||
toString() {
|
toString() {
|
||||||
const message = this.error.message;
|
const message = this.error.message;
|
||||||
const errors = this.githubErrors;
|
const errors = this.githubErrors;
|
||||||
|
const status = this.status;
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return message;
|
return `Error ${status}: ${message}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorBulletedList(errors) {
|
errorBulletedList(errors) {
|
||||||
|
|||||||
@@ -58,6 +58,10 @@ class CoreInputs {
|
|||||||
}
|
}
|
||||||
return this.tag;
|
return this.tag;
|
||||||
}
|
}
|
||||||
|
get prerelease() {
|
||||||
|
const draft = core.getInput('prerelease');
|
||||||
|
return draft == 'true';
|
||||||
|
}
|
||||||
get tag() {
|
get tag() {
|
||||||
const tag = core.getInput('tag');
|
const tag = core.getInput('tag');
|
||||||
if (tag) {
|
if (tag) {
|
||||||
|
|||||||
@@ -14,13 +14,14 @@ class GithubReleases {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.git = git;
|
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 __awaiter(this, void 0, void 0, function* () {
|
||||||
return this.git.repos.createRelease({
|
return this.git.repos.createRelease({
|
||||||
body: body,
|
body: body,
|
||||||
name: name,
|
name: name,
|
||||||
draft: draft,
|
draft: draft,
|
||||||
owner: this.context.repo.owner,
|
owner: this.context.repo.owner,
|
||||||
|
prerelease: prerelease,
|
||||||
repo: this.context.repo.repo,
|
repo: this.context.repo.repo,
|
||||||
target_commitish: commitHash,
|
target_commitish: commitHash,
|
||||||
tag_name: tag
|
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 __awaiter(this, void 0, void 0, function* () {
|
||||||
return this.git.repos.updateRelease({
|
return this.git.repos.updateRelease({
|
||||||
release_id: id,
|
release_id: id,
|
||||||
@@ -44,6 +45,7 @@ class GithubReleases {
|
|||||||
name: name,
|
name: name,
|
||||||
draft: draft,
|
draft: draft,
|
||||||
owner: this.context.repo.owner,
|
owner: this.context.repo.owner,
|
||||||
|
prerelease: prerelease,
|
||||||
repo: this.context.repo.repo,
|
repo: this.context.repo.repo,
|
||||||
target_commitish: commitHash,
|
target_commitish: commitHash,
|
||||||
tag_name: tag
|
tag_name: tag
|
||||||
|
|||||||
10
node_modules/.yarn-integrity
generated
vendored
10
node_modules/.yarn-integrity
generated
vendored
@@ -643,5 +643,13 @@
|
|||||||
"yargs@^13.3.0": "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83"
|
"yargs@^13.3.0": "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83"
|
||||||
},
|
},
|
||||||
"files": [],
|
"files": [],
|
||||||
"artifacts": {}
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,14 +24,19 @@ export class Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createOrUpdateRelease(): Promise<string> {
|
private async createOrUpdateRelease(): Promise<string> {
|
||||||
try {
|
if (this.inputs.allowUpdates) {
|
||||||
return await this.createRelease()
|
try {
|
||||||
} catch (error) {
|
const getResponse = await this.releases.getByTag(this.inputs.tag)
|
||||||
if (this.releaseAlreadyExisted(error) && this.inputs.allowUpdates) {
|
return await this.updateRelease(getResponse.data.id)
|
||||||
return this.updateRelease()
|
} catch (error) {
|
||||||
} else {
|
if (this.noRelease(error)) {
|
||||||
throw error
|
return await this.createRelease()
|
||||||
|
} else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return await this.createRelease()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,28 +46,27 @@ export class Action {
|
|||||||
this.inputs.body,
|
this.inputs.body,
|
||||||
this.inputs.commit,
|
this.inputs.commit,
|
||||||
this.inputs.draft,
|
this.inputs.draft,
|
||||||
this.inputs.name
|
this.inputs.name,
|
||||||
|
this.inputs.prerelease
|
||||||
)
|
)
|
||||||
|
|
||||||
return response.data.upload_url
|
return response.data.upload_url
|
||||||
}
|
}
|
||||||
|
|
||||||
private releaseAlreadyExisted(error: any): boolean {
|
private noRelease(error: any): boolean {
|
||||||
const errorMessage = new ErrorMessage(error)
|
const errorMessage = new ErrorMessage(error)
|
||||||
return errorMessage.hasErrorWithCode('already_exists')
|
return errorMessage.status == 404
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateRelease(): Promise<string> {
|
private async updateRelease(id: number): Promise<string> {
|
||||||
const getResponse = await this.releases.getByTag(this.inputs.tag)
|
|
||||||
const id = getResponse.data.id
|
|
||||||
|
|
||||||
const response = await this.releases.update(
|
const response = await this.releases.update(
|
||||||
id,
|
id,
|
||||||
this.inputs.tag,
|
this.inputs.tag,
|
||||||
this.inputs.body,
|
this.inputs.body,
|
||||||
this.inputs.commit,
|
this.inputs.commit,
|
||||||
this.inputs.draft,
|
this.inputs.draft,
|
||||||
this.inputs.name
|
this.inputs.name,
|
||||||
|
this.inputs.prerelease
|
||||||
)
|
)
|
||||||
|
|
||||||
return response.data.upload_url
|
return response.data.upload_url
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ export class ErrorMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get status():number {
|
||||||
|
return this.error.status
|
||||||
|
}
|
||||||
|
|
||||||
hasErrorWithCode(code: String): boolean {
|
hasErrorWithCode(code: String): boolean {
|
||||||
return this.githubErrors.some((err) => err.code == code)
|
return this.githubErrors.some((err) => err.code == code)
|
||||||
}
|
}
|
||||||
@@ -25,10 +29,11 @@ export class ErrorMessage {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
const message = this.error.message
|
const message = this.error.message
|
||||||
const errors = this.githubErrors
|
const errors = this.githubErrors
|
||||||
|
const status = this.status
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return `${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
return `Error ${status}: ${message}\nErrors:\n${this.errorBulletedList(errors)}`
|
||||||
} else {
|
} else {
|
||||||
return message
|
return `Error ${status}: ${message}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export interface Inputs {
|
|||||||
readonly commit: string
|
readonly commit: string
|
||||||
readonly draft: boolean
|
readonly draft: boolean
|
||||||
readonly name: string
|
readonly name: string
|
||||||
|
readonly prerelease: boolean
|
||||||
readonly tag: string
|
readonly tag: string
|
||||||
readonly token: string
|
readonly token: string
|
||||||
}
|
}
|
||||||
@@ -77,6 +78,11 @@ export class CoreInputs implements Inputs {
|
|||||||
return this.tag
|
return this.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get prerelease(): boolean {
|
||||||
|
const draft = core.getInput('prerelease')
|
||||||
|
return draft == 'true'
|
||||||
|
}
|
||||||
|
|
||||||
get tag(): string {
|
get tag(): string {
|
||||||
const tag = core.getInput('tag')
|
const tag = core.getInput('tag')
|
||||||
if (tag) {
|
if (tag) {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ export interface Releases {
|
|||||||
body?: string,
|
body?: string,
|
||||||
commitHash?: string,
|
commitHash?: string,
|
||||||
draft?: boolean,
|
draft?: boolean,
|
||||||
name?: string
|
name?: string,
|
||||||
|
prerelease?: boolean
|
||||||
): Promise<Response<ReposCreateReleaseResponse>>
|
): Promise<Response<ReposCreateReleaseResponse>>
|
||||||
|
|
||||||
getByTag(tag: string): Promise<Response<ReposGetReleaseByTagResponse>>
|
getByTag(tag: string): Promise<Response<ReposGetReleaseByTagResponse>>
|
||||||
@@ -19,7 +20,8 @@ export interface Releases {
|
|||||||
body?: string,
|
body?: string,
|
||||||
commitHash?: string,
|
commitHash?: string,
|
||||||
draft?: boolean,
|
draft?: boolean,
|
||||||
name?: string
|
name?: string,
|
||||||
|
prerelease?: boolean
|
||||||
): Promise<Response<ReposCreateReleaseResponse>>
|
): Promise<Response<ReposCreateReleaseResponse>>
|
||||||
|
|
||||||
uploadArtifact(
|
uploadArtifact(
|
||||||
@@ -45,13 +47,15 @@ export class GithubReleases implements Releases {
|
|||||||
body?: string,
|
body?: string,
|
||||||
commitHash?: string,
|
commitHash?: string,
|
||||||
draft?: boolean,
|
draft?: boolean,
|
||||||
name?: string
|
name?: string,
|
||||||
|
prerelease?: boolean
|
||||||
): Promise<Response<ReposCreateReleaseResponse>> {
|
): Promise<Response<ReposCreateReleaseResponse>> {
|
||||||
return this.git.repos.createRelease({
|
return this.git.repos.createRelease({
|
||||||
body: body,
|
body: body,
|
||||||
name: name,
|
name: name,
|
||||||
draft: draft,
|
draft: draft,
|
||||||
owner: this.context.repo.owner,
|
owner: this.context.repo.owner,
|
||||||
|
prerelease: prerelease,
|
||||||
repo: this.context.repo.repo,
|
repo: this.context.repo.repo,
|
||||||
target_commitish: commitHash,
|
target_commitish: commitHash,
|
||||||
tag_name: tag
|
tag_name: tag
|
||||||
@@ -72,7 +76,8 @@ export class GithubReleases implements Releases {
|
|||||||
body?: string,
|
body?: string,
|
||||||
commitHash?: string,
|
commitHash?: string,
|
||||||
draft?: boolean,
|
draft?: boolean,
|
||||||
name?: string
|
name?: string,
|
||||||
|
prerelease?: boolean
|
||||||
): Promise<Response<ReposCreateReleaseResponse>> {
|
): Promise<Response<ReposCreateReleaseResponse>> {
|
||||||
return this.git.repos.updateRelease({
|
return this.git.repos.updateRelease({
|
||||||
release_id: id,
|
release_id: id,
|
||||||
@@ -80,6 +85,7 @@ export class GithubReleases implements Releases {
|
|||||||
name: name,
|
name: name,
|
||||||
draft: draft,
|
draft: draft,
|
||||||
owner: this.context.repo.owner,
|
owner: this.context.repo.owner,
|
||||||
|
prerelease: prerelease,
|
||||||
repo: this.context.repo.repo,
|
repo: this.context.repo.repo,
|
||||||
target_commitish: commitHash,
|
target_commitish: commitHash,
|
||||||
tag_name: tag
|
tag_name: tag
|
||||||
|
|||||||
Reference in New Issue
Block a user