Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallbackToDownoadAction #192

Merged
merged 3 commits into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.