Skip to content

Commit

Permalink
Only run on certain actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Aug 21, 2019
1 parent fbb2dfb commit 0ff0a09
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ const fs = require('fs');
async function run() {
try {
const payload = process.env.GITHUB_EVENT_PATH ? require(process.env.GITHUB_EVENT_PATH) : {}
const { release: { id: release_id, draft: isDraft }} = payload
if (isDraft) {
// Only upload to non-draft releases
return
const { action: action, release: { id: release_id }} = payload
// https://developer.github.com/v3/activity/events/types/#releaseevent
switch (action) {
case "published":
case "created":
case "prereleased":
break
default:
console.log(`Skipping release: ${action}`)
return
}

const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/')
Expand All @@ -25,6 +31,13 @@ async function run() {
const { data: { upload_url: url } } = await octokit.repos.getRelease({owner, repo, release_id})
console.log(`Upload URL: ${url}`)

const { data: assets } = await octokit.repos.listAssetsForRelease({owner, repo, release_id})
assets.forEach(({ id: asset_id, name: asset_name }) => {
if (asset_name == name) {
octokit.repos.deleteReleaseAsset({owner, repo, asset_id})
}
})

const headers = {
'content-type': contentType,
'content-length': fs.statSync(path).size,
Expand Down

0 comments on commit 0ff0a09

Please sign in to comment.