Skip to content

Commit

Permalink
Add the support to omit artifact name
Browse files Browse the repository at this point in the history
  • Loading branch information
HyukjinKwon committed Aug 13, 2020
1 parent e20f5de commit 750b71a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inputs:
required: false
name:
description: Artifact name
required: true
required: false
path:
description: Where to unpack the artifact
required: false
Expand Down
48 changes: 28 additions & 20 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ async function main() {
try {
const token = core.getInput("github_token", { required: true })
const workflow = core.getInput("workflow", { required: true })
const name = core.getInput("name", { required: true })
const [owner, repo] = core.getInput("repo", { required: true }).split("/")
const path = core.getInput("path", { required: true })
const name = core.getInput("name")
let branch = core.getInput("branch")
let pr = core.getInput("pr")
let commit = core.getInput("commit")
Expand Down Expand Up @@ -82,30 +82,38 @@ async function main() {
run_id: run.id,
})

const artifact = artifacts.data.artifacts.find((artifact) => {
return artifact.name == name
})
let atfs;
if (name) {
atfs = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == name
})
}
else {
artfs = artifacts.data.artifacts
}

console.log("==> Artifact:", artifact.id)
for (const artifact of artfs) {
console.log("==> Artifact:", artifact.id)

const size = filesize(artifact.size_in_bytes, { base: 10 })
const size = filesize(artifact.size_in_bytes, { base: 10 })

console.log("==> Downloading:", name + ".zip", `(${size})`)
console.log("==> Downloading:", name + ".zip", `(${size})`)

const zip = await client.actions.downloadArtifact({
owner: owner,
repo: repo,
artifact_id: artifact.id,
archive_format: "zip",
})
const zip = await client.actions.downloadArtifact({
owner: owner,
repo: repo,
artifact_id: artifact.id,
archive_format: "zip",
})

const adm = new AdmZip(Buffer.from(zip.data))
adm.getEntries().forEach((entry) => {
const action = entry.isDirectory ? "creating" : "inflating"
const filepath = pathname.join(path, entry.entryName)
console.log(` ${action}: ${filepath}`)
})
adm.extractAllTo(path, true)
const adm = new AdmZip(Buffer.from(zip.data))
adm.getEntries().forEach((entry) => {
const action = entry.isDirectory ? "creating" : "inflating"
const filepath = pathname.join(path, entry.entryName)
console.log(` ${action}: ${filepath}`)
})
adm.extractAllTo(path, true)
}
} catch (error) {
core.setFailed(error.message)
}
Expand Down

0 comments on commit 750b71a

Please sign in to comment.