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

@actions/artifact should allow downloading artifacts cross-workflow #1141

Closed
CAD97 opened this issue Jul 29, 2022 · 2 comments
Closed

@actions/artifact should allow downloading artifacts cross-workflow #1141

CAD97 opened this issue Jul 29, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@CAD97
Copy link

CAD97 commented Jul 29, 2022

Describe the enhancement

Accept an optional workflow run ID for which workflow run to download artifacts from. This will allow passing artifacts cross-workflow without falling back to using the REST API directly.

Code Snippet

const artifact = require('@actions/artifact');
const artifactClient = artifact.create()
const artifactName = 'my-artifact';
const path = 'some/directory'
const options = {
    createArtifactFolder: false
    runId: 'RUN_ID'
}

const downloadResponse = await artifactClient.downloadArtifact(artifactName, path, options)

With an actions/download-artifact action:

steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v3
  with:
    name: my-artifact
    path: some/directory
    run-id: RUN_ID

Additional information

Targets for the patch:

async listArtifacts(): Promise<ListArtifactsResponse> {
const artifactUrl = getArtifactUrl()

export function getArtifactUrl(): string {
const artifactUrl = `${getRuntimeUrl()}_apis/pipelines/workflows/${getWorkFlowRunId()}/artifacts?api-version=${getApiVersion()}`
debug(`Artifact Url: ${artifactUrl}`)
return artifactUrl
}

export function getWorkFlowRunId(): string {
const workFlowRunId = process.env['GITHUB_RUN_ID']
if (!workFlowRunId) {
throw new Error('Unable to get GITHUB_RUN_ID env variable')
}
return workFlowRunId
}

  • DownloadOptions gains a new runId which can be used to specify the workflow run id to download artifacts from instead of using process.env['GITHUB_RUN_ID'].
  • downloadAllArtifacts gains a new options?: DownloadAllOptions parameter which just contains the runId option.
  • This is passed down, replacing uses of getWorkFlowRunId() with options.runId ?? getWorkFlowRunId().
@CAD97
Copy link
Author

CAD97 commented Jul 29, 2022

See also actions/download-artifact#172 for exposing this functionality in the actions/download-artifact action.

@konradpabjan
Copy link
Contributor

With v4 upload-artifact and download-artifacts this is now supported! See actions/download-artifact#172 (comment)

https://github.com/actions/download-artifact?tab=readme-ov-file#download-artifacts-from-other-workflow-runs-or-repositories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants