Skip to content

Commit

Permalink
Add fallbackToDownoadAction (#192)
Browse files Browse the repository at this point in the history
* Add fallback to downloadAction

* Fix review comments

* Update main.js

Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
  • Loading branch information
leshikus and dawidd6 committed Oct 15, 2022
1 parent 84086c2 commit 730c88f
Show file tree
Hide file tree
Showing 226 changed files with 15,876 additions and 851 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/download.yml
Expand Up @@ -12,6 +12,18 @@ jobs:
steps:
- name: Wait
run: sleep 60
in-progress:
runs-on: ubuntu-latest
steps:
- name: Dump
run: |
mkdir artifact
echo temp > artifact/sha
- name: Upload a temporary artifact
uses: actions/upload-artifact@v3
with:
name: artifact
path: artifact
download-latest:
runs-on: ubuntu-latest
needs: wait
Expand Down Expand Up @@ -140,4 +152,34 @@ jobs:
dry_run: true
- name: Test
run: test ${{ steps.download.outputs.dry_run }} == false
download-in-progress:
runs-on: ubuntu-latest
needs: [wait, in-progress]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download
uses: ./
with:
workflow: upload.yml
name: artifact
path: artifact
workflow_conclusion: in_progress
- name: Test
run: grep temp artifact/sha
download-empty-conclusion:
runs-on: ubuntu-latest
needs: [wait, in-progress]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download
uses: ./
with:
workflow: upload.yml
name: artifact
path: artifact
workflow_conclusion:
- name: Test
run: grep $GITHUB_SHA artifact/sha

24 changes: 23 additions & 1 deletion main.js
@@ -1,10 +1,24 @@
const core = require('@actions/core')
const github = require('@actions/github')
const artifact = require('@actions/artifact')
const AdmZip = require('adm-zip')
const filesize = require('filesize')
const pathname = require('path')
const fs = require('fs')

async function downloadAction(name, path) {
const artifactClient = artifact.create()
const downloadOptions = {
createArtifactFolder: false
}
const downloadResponse = await artifactClient.downloadArtifact(
name,
path,
downloadOptions
)
core.setOutput("found_artifact", true)
}

async function main() {
try {
const token = core.getInput("github_token", { required: true })
Expand Down Expand Up @@ -137,7 +151,15 @@ async function main() {
}

if (!runID) {
return setExitMessage(ifNoArtifactFound, "no matching workflow run found with any artifacts?")
if (workflowConclusion && (workflowConclusion != 'in_progress')) {
return setExitMessage(ifNoArtifactFound, "no matching workflow run found with any artifacts?")
}

try {
return await downloadAction(name, path)
} catch (error) {
return setExitMessage(ifNoArtifactFound, "no matching artifact in this workflow?")
}
}

let artifacts = await client.paginate(client.rest.actions.listWorkflowRunArtifacts, {
Expand Down
151 changes: 144 additions & 7 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions node_modules/@actions/artifact/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 730c88f

Please sign in to comment.