Skip to content

Commit e58a9e5

Browse files
authored
Unzip (#325)
* 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
1 parent 6d05268 commit e58a9e5

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

.github/workflows/download.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ jobs:
155155
! test -d artifact/artifact
156156
! test -f artifact.zip
157157
unzip -l artifact/artifact.zip
158+
download-use-unzip:
159+
runs-on: ubuntu-latest
160+
needs: wait
161+
steps:
162+
- name: Checkout
163+
uses: actions/checkout@v4
164+
- name: Download
165+
uses: ./
166+
with:
167+
workflow: upload.yml
168+
name: artifact
169+
path: artifact
170+
use_unzip: true
171+
- name: Test
172+
run: |
173+
test -d artifact
174+
! test -d artifact/artifact
175+
! test -f artifact.zip
176+
! test -f artifact/artifact.zip
177+
cat artifact/sha | grep $GITHUB_SHA
158178
download-dry-run-exists:
159179
runs-on: ubuntu-latest
160180
needs: wait

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
7878
# Optional, include forks when searching for artifacts
7979
# default false
8080
allow_forks: true
81+
# Optional, choose to unpack the downloaded artifact(s) using `unzip` system utility
82+
# default false
83+
use_unzip: false
8184
```
8285
8386
## Troubleshooting

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ inputs:
8888
8989
fail, warn or ignore
9090
default: fail
91+
use_unzip:
92+
description: Use system provided `unzip` utility instead of JS library for unpacking
93+
required: false
94+
default: false
9195
outputs:
9296
error_message:
9397
description: The error message, if an error occurs

main.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const core = require('@actions/core')
2+
const exec = require('@actions/exec')
23
const github = require('@actions/github')
34
const artifact = require('@actions/artifact')
45
const AdmZip = require('adm-zip')
@@ -37,6 +38,7 @@ async function main() {
3738
const nameIsRegExp = core.getBooleanInput("name_is_regexp")
3839
const skipUnpack = core.getBooleanInput("skip_unpack")
3940
const ifNoArtifactFound = core.getInput("if_no_artifact_found")
41+
const useUnzip = core.getBooleanInput("use_unzip")
4042
let workflow = core.getInput("workflow")
4143
let workflowSearch = core.getBooleanInput("workflow_search")
4244
let workflowConclusion = core.getInput("workflow_conclusion")
@@ -270,17 +272,22 @@ async function main() {
270272

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

273-
const adm = new AdmZip(Buffer.from(zip.data))
274-
275275
core.startGroup(`==> Extracting: ${artifact.name}.zip`)
276-
adm.getEntries().forEach((entry) => {
277-
const action = entry.isDirectory ? "creating" : "inflating"
278-
const filepath = pathname.join(dir, entry.entryName)
279-
280-
core.info(` ${action}: ${filepath}`)
281-
})
276+
if (useUnzip) {
277+
const zipPath = `${pathname.join(dir, artifact.name)}.zip`
278+
fs.writeFileSync(zipPath, Buffer.from(zip.data), 'binary')
279+
await exec.exec("unzip", [zipPath, "-d", dir])
280+
fs.rmSync(zipPath)
281+
} else {
282+
const adm = new AdmZip(Buffer.from(zip.data))
283+
adm.getEntries().forEach((entry) => {
284+
const action = entry.isDirectory ? "creating" : "inflating"
285+
const filepath = pathname.join(dir, entry.entryName)
282286

283-
adm.extractAllTo(dir, true)
287+
core.info(` ${action}: ${filepath}`)
288+
})
289+
adm.extractAllTo(dir, true)
290+
}
284291
core.endGroup()
285292
}
286293
} catch (error) {

0 commit comments

Comments
 (0)