Skip to content

Commit

Permalink
Validate inputs that cannot be used together (dawidd6#160)
Browse files Browse the repository at this point in the history
* feat: Validate inputs that cannot be used together

* Fix reduce callback

* Simplify inputSet validation
  • Loading branch information
M1kep authored and iTrooz committed Jun 19, 2022
1 parent b7337e5 commit 02cd2c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/download.yml
Expand Up @@ -103,9 +103,10 @@ jobs:
skip_unpack: true
- name: Test
run: |
test -f artifact.zip
! test -d artifact
unzip -l artifact.zip
test -d artifact
test -f artifact/artifact.zip
! test -f artifact.zip
unzip -l artifact/artifact.zip
download-dry-run-exists:
runs-on: ubuntu-latest
needs: wait
Expand Down
25 changes: 20 additions & 5 deletions main.js
Expand Up @@ -36,6 +36,22 @@ async function main() {
core.info(`==> Repository: ${owner}/${repo}`)
core.info(`==> Workflow conclusion: ${workflowConclusion}`)

const uniqueInputSets = [
{
"pr": pr,
"commit": commit,
"branch": branch,
"run_id": runID
}
]
uniqueInputSets.forEach((inputSet) => {
const inputs = Object.values(inputSet)
const providedInputs = inputs.filter(input => input !== '')
if (providedInputs.length > 1) {
throw new Error(`The following inputs cannot be used together: ${Object.keys(inputSet).join(", ")}`)
}
})

if (pr) {
core.info(`==> PR: ${pr}`)
const pull = await client.pulls.get({
Expand Down Expand Up @@ -174,15 +190,14 @@ async function main() {
archive_format: "zip",
})

const dir = name ? path : pathname.join(path, artifact.name)
fs.mkdirSync(dir, { recursive: true })

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

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

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

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

core.startGroup(`==> Extracting: ${artifact.name}.zip`)
Expand Down

0 comments on commit 02cd2c5

Please sign in to comment.