From b2abf1705491048a2d7074f7d90513044fd25d39 Mon Sep 17 00:00:00 2001 From: Jeremy Daley Date: Sat, 16 Apr 2022 03:10:58 -0400 Subject: [PATCH] Add input option to unpack (or not) downloaded artifact(s) (#150) Co-authored-by: Dawid Dziurla --- .github/workflows/download.yml | 19 +++++++++++++++++++ README.md | 3 +++ action.yml | 3 +++ main.js | 6 ++++++ 4 files changed, 31 insertions(+) diff --git a/.github/workflows/download.yml b/.github/workflows/download.yml index 7b3b5f70..1eccf2af 100644 --- a/.github/workflows/download.yml +++ b/.github/workflows/download.yml @@ -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: @@ -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 diff --git a/README.md b/README.md index 156d4848..c904a0ac 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/action.yml b/action.yml index 17f83d32..a6674754 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/main.js b/main.js index 1f03076c..b0c43f06 100644 --- a/main.js +++ b/main.js @@ -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") @@ -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 })