Skip to content

Commit

Permalink
Unzip (#325)
Browse files Browse the repository at this point in the history
* action: add use_unzip input

* main: implement use_unzip input

* workflows: test use_unzip

* main: remove zip file at the end

* workflows: test if zip is removed

* main: fix

* main: try this

* main: debug

* main: forgot await

* workflows: debug

* workflows: should be ok now

* README: update
  • Loading branch information
dawidd6 authored Jan 22, 2025
1 parent 6d05268 commit e58a9e5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/download.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ jobs:
! test -d artifact/artifact
! test -f artifact.zip
unzip -l artifact/artifact.zip
download-use-unzip:
runs-on: ubuntu-latest
needs: wait
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download
uses: ./
with:
workflow: upload.yml
name: artifact
path: artifact
use_unzip: true
- name: Test
run: |
test -d artifact
! test -d artifact/artifact
! test -f artifact.zip
! test -f artifact/artifact.zip
cat artifact/sha | grep $GITHUB_SHA
download-dry-run-exists:
runs-on: ubuntu-latest
needs: wait
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
# Optional, include forks when searching for artifacts
# default false
allow_forks: true
# Optional, choose to unpack the downloaded artifact(s) using `unzip` system utility
# default false
use_unzip: false
```
## Troubleshooting
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ inputs:
fail, warn or ignore
default: fail
use_unzip:
description: Use system provided `unzip` utility instead of JS library for unpacking
required: false
default: false
outputs:
error_message:
description: The error message, if an error occurs
Expand Down
25 changes: 16 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const core = require('@actions/core')
const exec = require('@actions/exec')
const github = require('@actions/github')
const artifact = require('@actions/artifact')
const AdmZip = require('adm-zip')
Expand Down Expand Up @@ -37,6 +38,7 @@ async function main() {
const nameIsRegExp = core.getBooleanInput("name_is_regexp")
const skipUnpack = core.getBooleanInput("skip_unpack")
const ifNoArtifactFound = core.getInput("if_no_artifact_found")
const useUnzip = core.getBooleanInput("use_unzip")
let workflow = core.getInput("workflow")
let workflowSearch = core.getBooleanInput("workflow_search")
let workflowConclusion = core.getInput("workflow_conclusion")
Expand Down Expand Up @@ -270,17 +272,22 @@ async function main() {

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

const adm = new AdmZip(Buffer.from(zip.data))

core.startGroup(`==> Extracting: ${artifact.name}.zip`)
adm.getEntries().forEach((entry) => {
const action = entry.isDirectory ? "creating" : "inflating"
const filepath = pathname.join(dir, entry.entryName)

core.info(` ${action}: ${filepath}`)
})
if (useUnzip) {
const zipPath = `${pathname.join(dir, artifact.name)}.zip`
fs.writeFileSync(zipPath, Buffer.from(zip.data), 'binary')
await exec.exec("unzip", [zipPath, "-d", dir])
fs.rmSync(zipPath)
} else {
const adm = new AdmZip(Buffer.from(zip.data))
adm.getEntries().forEach((entry) => {
const action = entry.isDirectory ? "creating" : "inflating"
const filepath = pathname.join(dir, entry.entryName)

adm.extractAllTo(dir, true)
core.info(` ${action}: ${filepath}`)
})
adm.extractAllTo(dir, true)
}
core.endGroup()
}
} catch (error) {
Expand Down

0 comments on commit e58a9e5

Please sign in to comment.