Skip to content

Commit

Permalink
Add input option to unpack (or not) downloaded artifact(s) (#150)
Browse files Browse the repository at this point in the history

Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
  • Loading branch information
daleyjem and dawidd6 committed Apr 16, 2022
1 parent 1a8ccca commit b2abf17
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
workflow: upload.yml
- name: Test
run: |
cat artifact/sha | grep $GITHUB_SHA
cat artifact1/sha1 | grep $GITHUB_SHA
cat artifact2/sha2 | grep $GITHUB_SHA
download-conclusion:
Expand All @@ -87,3 +88,21 @@ jobs:
workflow_conclusion: ''
- name: Test
run: cat artifact/sha | grep $GITHUB_SHA
download-skip-unpack:
runs-on: ubuntu-latest
needs: wait
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download
uses: ./
with:
workflow: upload.yml
name: artifact
path: artifact
skip_unpack: true
- name: Test
run: |
test -f artifact.zip
! test -d artifact
unzip -l artifact.zip
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
# Optional, search for the last workflow run whose stored an artifact named as in `name` input
# default false
search_artifacts: false
# Optional, choose to skip unpacking the downloaded artifact(s)
# default false
skip_unpack: false
```
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ inputs:
search_artifacts:
description: Search workflow runs for artifact with specified name
required: false
skip_unpack:
description: Choose to skip unpacking the downloaded artifact(s)
required: false
outputs:
error_message:
description: The error message, if an error occurs
Expand Down
6 changes: 6 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function main() {
const [owner, repo] = core.getInput("repo", { required: true }).split("/")
const path = core.getInput("path", { required: true })
const name = core.getInput("name")
const skipUnpack = core.getInput("skip_unpack")
let workflowConclusion = core.getInput("workflow_conclusion")
let pr = core.getInput("pr")
let commit = core.getInput("commit")
Expand Down Expand Up @@ -141,6 +142,11 @@ async function main() {
archive_format: "zip",
})

if (skipUnpack) {
fs.writeFileSync(`${artifact.name}.zip`, Buffer.from(zip.data), 'binary')
continue
}

const dir = name ? path : pathname.join(path, artifact.name)

fs.mkdirSync(dir, { recursive: true })
Expand Down

0 comments on commit b2abf17

Please sign in to comment.