Skip to content

Commit

Permalink
Remove try/catch, attempting to bypass bug in core toolkit
Browse files Browse the repository at this point in the history
  • Loading branch information
coreybutler committed Jan 29, 2020
1 parent bdcca19 commit 132fefa
Showing 1 changed file with 57 additions and 61 deletions.
118 changes: 57 additions & 61 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,78 @@ const core = require('@actions/core');
const { GitHub, context } = require('@actions/github');

async function run() {
try {
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN)
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN)

// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo
// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo

// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const id = core.getInput('release_id', { required: false })
const tag = core.getInput('tag', { required: false })
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
const id = core.getInput('release_id', { required: false })
const tag = core.getInput('tag', { required: false })

if (!id && !tag) {
core.setFailed('At least one of the following inputs must be defined: release_id or tag.')
return
}

// Retrieve the release ID
let data
if (!id) {
data = await github.repos.getReleaseByTag({
owner,
repo,
tag
})

if (!data) {
console.log(JSON.stringify(data, null, 2))
core.setFailed(`Tag "${tag}" was not found or a release ID is not associated with it.`)
return
}

data = data.data
} else {
data = await github.repos.getRelease({
owner,
repo,
release_id: id
})

if (!data) {
console.log(JSON.stringify(data, null, 2))
core.setFailed(`Release "${id}" was not found.`)
return
}

data = data.data
}
if (!id && !tag) {
core.setFailed('At least one of the following inputs must be defined: release_id or tag.')
return
}

console.log(JSON.stringify(data, null, 2))

// API Documentation: https://developer.github.com/v3/repos/releases/#delete-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-delete-release
console.log(`Removing release ${id}`)
const response = await github.repos.deleteRelease({
// Retrieve the release ID
let data
if (!id) {
data = await github.repos.getReleaseByTag({
owner,
repo,
release_id: data.id
tag
})

console.log(JSON.stringify(response, null, 2))
if (!data) {
core.debug(JSON.stringify(data, null, 2))
core.setFailed(`Tag "${tag}" was not found or a release ID is not associated with it.`)
return
}

// Delete tag reference
console.log(`Removing reference: tags/${data.tag_name}`)
const tagresponse = await github.git.deleteRef({
data = data.data
} else {
data = await github.repos.getRelease({
owner,
repo,
ref: `tags/${data.tag_name}`
release_id: id
})

console.log(JSON.stringify(tagresponse, null, 2))
if (!data) {
core.debug(JSON.stringify(data, null, 2))
core.setFailed(`Release "${id}" was not found.`)
return
}

core.setOutput('release_id', data.id)
core.setOutput('tag', data.tag_name)
} catch (error) {
core.setFailed(error.message);
data = data.data
}

core.debug(JSON.stringify(data, null, 2))

// API Documentation: https://developer.github.com/v3/repos/releases/#delete-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-delete-release
core.debug(`Removing release ${data.id}`)
const response = await github.repos.deleteRelease({
owner,
repo,
release_id: data.id
})

core.debug(JSON.stringify(response, null, 2))

// Delete tag reference
core.debug(`Removing reference: tags/${data.tag_name}`)
const tagresponse = await github.git.deleteRef({
owner,
repo,
ref: `tags/${data.tag_name}`
})

core.debug(JSON.stringify(tagresponse, null, 2))

core.setOutput('release_id', data.id)
core.setOutput('tag', data.tag_name)
}

run()

0 comments on commit 132fefa

Please sign in to comment.