Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2e17e8b67 | ||
|
|
621be0be95 | ||
|
|
5be1d38671 | ||
|
|
465b526e63 | ||
|
|
8b83831f82 | ||
|
|
0742efc19b | ||
|
|
5e4b342272 | ||
|
|
98c6f16055 | ||
|
|
9140050fd5 | ||
|
|
88dadfbcfc | ||
|
|
896d1bb258 | ||
|
|
57685c7c71 | ||
|
|
8c323b340c | ||
|
|
727cfbe442 | ||
|
|
24b1443a07 | ||
|
|
e9ef242655 | ||
|
|
adf9559c4f | ||
|
|
9bc31d5ccc | ||
|
|
d2278a10ef | ||
|
|
c1a6d8f06a |
@@ -0,0 +1,6 @@
|
|||||||
|
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||||
|
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
|
||||||
|
{
|
||||||
|
"name": "@actions/download-artifact",
|
||||||
|
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-16"
|
||||||
|
}
|
||||||
@@ -22,12 +22,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
- name: Setup Node 16
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 16.x
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
@@ -45,7 +46,7 @@ jobs:
|
|||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
# If index.js was different than expected, upload the expected version as an artifact
|
# If index.js was different than expected, upload the expected version as an artifact
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v3
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
# Override language selection by uncommenting this and choosing your languages
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
# with:
|
# with:
|
||||||
# languages: go, javascript, csharp, python, cpp, java
|
# languages: go, javascript, csharp, python, cpp, java
|
||||||
@@ -32,7 +32,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -46,4 +46,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Check licenses
|
name: Check licenses
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Install licensed
|
- name: Install licensed
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
uses: actions/publish-action@v0.1.0
|
uses: actions/publish-action@v0.2.1
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set Node.js 12.x
|
# using node 16 since that is what the latest version of the runner ships with
|
||||||
uses: actions/setup-node@v1
|
- name: Setup Node 16
|
||||||
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 16.x
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
- name: npm install
|
- name: npm install
|
||||||
run: npm install
|
run: npm install
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: "@actions/artifact"
|
name: "@actions/artifact"
|
||||||
version: 1.0.0
|
version: 1.1.1
|
||||||
type: npm
|
type: npm
|
||||||
summary: Actions artifact lib
|
summary: Actions artifact lib
|
||||||
homepage: https://github.com/actions/toolkit/tree/main/packages/artifact
|
homepage: https://github.com/actions/toolkit/tree/main/packages/artifact
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ See [action.yml](action.yml)
|
|||||||
Basic (download to the current working directory):
|
Basic (download to the current working directory):
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -34,7 +34,7 @@ steps:
|
|||||||
Download to a specific directory:
|
Download to a specific directory:
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -93,7 +93,7 @@ Example, if there are two artifacts `Artifact-A` and `Artifact-B`, and the direc
|
|||||||
Download all artifacts to a specific directory
|
Download all artifacts to a specific directory
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -107,7 +107,7 @@ steps:
|
|||||||
Download all artifacts to the current working directory
|
Download all artifacts to the current working directory
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v3
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ The `download-path` step output contains information regarding where the artifac
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v3
|
||||||
id: download
|
id: download
|
||||||
|
|||||||
+20
-2
@@ -1,13 +1,31 @@
|
|||||||
name: 'Download a Build Artifact'
|
name: 'Download a Build Artifact'
|
||||||
description: 'Download a build artifact that was previously uploaded in the workflow by the upload-artifact action'
|
description: 'Download a build artifact that was previously uploaded in the workflow by the upload-artifact action'
|
||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
name:
|
name:
|
||||||
description: 'Artifact name'
|
description: 'Artifact name'
|
||||||
required: false
|
required: false
|
||||||
path:
|
path:
|
||||||
description: 'Destination path'
|
description: 'Destination path'
|
||||||
required: false
|
required: false
|
||||||
|
github-token:
|
||||||
|
description: 'The GitHub token used to authenticate with the GitHub API.
|
||||||
|
This is required when downloading artifacts from a different repository or from a different workflow run.
|
||||||
|
If this is not specified, the action will attempt to download artifacts from the current repository and the current workflow run.'
|
||||||
|
required: false
|
||||||
|
repository:
|
||||||
|
description: 'The repository owner and the repository name joined together by "/".
|
||||||
|
If github-token is specified, this is the repository that artifacts will be downloaded from.'
|
||||||
|
required: false
|
||||||
|
default: ${{ github.repository }}
|
||||||
|
run-id:
|
||||||
|
description: 'The id of the workflow run where the desired download artifact was uploaded from.
|
||||||
|
If github-token is specified, this is the run that artifacts will be downloaded from.'
|
||||||
|
required: false
|
||||||
|
default: ${{ github.run_id }}
|
||||||
|
outputs:
|
||||||
|
download-path:
|
||||||
|
description: 'Path of artifact download'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
Vendored
+97333
-3389
File diff suppressed because one or more lines are too long
Generated
+384
-139
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -28,8 +28,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/actions/download-artifact#readme",
|
"homepage": "https://github.com/actions/download-artifact#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/artifact": "^1.0.0",
|
"@actions/artifact": "^2.0.0",
|
||||||
"@actions/core": "^1.10.0"
|
"@actions/core": "^1.10.0",
|
||||||
|
"@actions/github": "^5.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^12.12.6",
|
"@types/node": "^12.12.6",
|
||||||
|
|||||||
+5
-1
@@ -1,7 +1,11 @@
|
|||||||
export enum Inputs {
|
export enum Inputs {
|
||||||
Name = 'name',
|
Name = 'name',
|
||||||
Path = 'path'
|
Path = 'path',
|
||||||
|
GitHubToken = 'github-token',
|
||||||
|
Repository = 'repository',
|
||||||
|
RunID = 'run-id'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
DownloadPath = 'download-path'
|
DownloadPath = 'download-path'
|
||||||
}
|
}
|
||||||
|
|||||||
+108
-54
@@ -1,61 +1,115 @@
|
|||||||
import * as core from '@actions/core'
|
|
||||||
import * as artifact from '@actions/artifact'
|
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import {resolve} from 'path'
|
import * as path from 'path'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
import artifactClient from '@actions/artifact'
|
||||||
|
import type {Artifact, FindOptions} from '@actions/artifact'
|
||||||
import {Inputs, Outputs} from './constants'
|
import {Inputs, Outputs} from './constants'
|
||||||
|
|
||||||
|
const PARALLEL_DOWNLOADS = 5
|
||||||
|
|
||||||
|
export const chunk = <T>(arr: T[], n: number): T[][] =>
|
||||||
|
arr.reduce((acc, cur, i) => {
|
||||||
|
const index = Math.floor(i / n)
|
||||||
|
acc[index] = [...(acc[index] || []), cur]
|
||||||
|
return acc
|
||||||
|
}, [] as T[][])
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
const inputs = {
|
||||||
const name = core.getInput(Inputs.Name, {required: false})
|
name: core.getInput(Inputs.Name, {required: false}),
|
||||||
const path = core.getInput(Inputs.Path, {required: false})
|
path: core.getInput(Inputs.Path, {required: false}),
|
||||||
|
token: core.getInput(Inputs.GitHubToken, {required: false}),
|
||||||
let resolvedPath
|
repository: core.getInput(Inputs.Repository, {required: false}),
|
||||||
// resolve tilde expansions, path.replace only replaces the first occurrence of a pattern
|
runID: parseInt(core.getInput(Inputs.RunID, {required: false}))
|
||||||
if (path.startsWith(`~`)) {
|
|
||||||
resolvedPath = resolve(path.replace('~', os.homedir()))
|
|
||||||
} else {
|
|
||||||
resolvedPath = resolve(path)
|
|
||||||
}
|
|
||||||
core.debug(`Resolved path is ${resolvedPath}`)
|
|
||||||
|
|
||||||
const artifactClient = artifact.create()
|
|
||||||
if (!name) {
|
|
||||||
// download all artifacts
|
|
||||||
core.info('No artifact name specified, downloading all artifacts')
|
|
||||||
core.info(
|
|
||||||
'Creating an extra directory for each artifact that is being downloaded'
|
|
||||||
)
|
|
||||||
const downloadResponse = await artifactClient.downloadAllArtifacts(
|
|
||||||
resolvedPath
|
|
||||||
)
|
|
||||||
core.info(`There were ${downloadResponse.length} artifacts downloaded`)
|
|
||||||
for (const artifact of downloadResponse) {
|
|
||||||
core.info(
|
|
||||||
`Artifact ${artifact.artifactName} was downloaded to ${artifact.downloadPath}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// download a single artifact
|
|
||||||
core.info(`Starting download for ${name}`)
|
|
||||||
const downloadOptions = {
|
|
||||||
createArtifactFolder: false
|
|
||||||
}
|
|
||||||
const downloadResponse = await artifactClient.downloadArtifact(
|
|
||||||
name,
|
|
||||||
resolvedPath,
|
|
||||||
downloadOptions
|
|
||||||
)
|
|
||||||
core.info(
|
|
||||||
`Artifact ${downloadResponse.artifactName} was downloaded to ${downloadResponse.downloadPath}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// output the directory that the artifact(s) was/were downloaded to
|
|
||||||
// if no path is provided, an empty string resolves to the current working directory
|
|
||||||
core.setOutput(Outputs.DownloadPath, resolvedPath)
|
|
||||||
core.info('Artifact download has finished successfully')
|
|
||||||
} catch (err) {
|
|
||||||
core.setFailed(err.message)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!inputs.path) {
|
||||||
|
inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputs.path.startsWith(`~`)) {
|
||||||
|
inputs.path = inputs.path.replace('~', os.homedir())
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSingleArtifactDownload = !!inputs.name
|
||||||
|
const resolvedPath = path.resolve(inputs.path)
|
||||||
|
core.debug(`Resolved path is ${resolvedPath}`)
|
||||||
|
|
||||||
|
const options: FindOptions = {}
|
||||||
|
if (inputs.token) {
|
||||||
|
const [repositoryOwner, repositoryName] = inputs.repository.split('/')
|
||||||
|
if (!repositoryOwner || !repositoryName) {
|
||||||
|
throw new Error(
|
||||||
|
`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
options.findBy = {
|
||||||
|
token: inputs.token,
|
||||||
|
workflowRunId: inputs.runID,
|
||||||
|
repositoryName,
|
||||||
|
repositoryOwner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let artifacts: Artifact[] = []
|
||||||
|
|
||||||
|
if (isSingleArtifactDownload) {
|
||||||
|
core.info(`Downloading single artifact`)
|
||||||
|
|
||||||
|
const {artifact: targetArtifact} = await artifactClient.getArtifact(
|
||||||
|
inputs.name,
|
||||||
|
options
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!targetArtifact) {
|
||||||
|
throw new Error(`Artifact '${inputs.name}' not found`)
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(
|
||||||
|
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
|
||||||
|
)
|
||||||
|
|
||||||
|
artifacts = [targetArtifact]
|
||||||
|
} else {
|
||||||
|
core.info(
|
||||||
|
`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`
|
||||||
|
)
|
||||||
|
|
||||||
|
const listArtifactResponse = await artifactClient.listArtifacts({
|
||||||
|
latest: true,
|
||||||
|
...options
|
||||||
|
})
|
||||||
|
|
||||||
|
if (listArtifactResponse.artifacts.length === 0) {
|
||||||
|
throw new Error(
|
||||||
|
`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`)
|
||||||
|
artifacts = listArtifactResponse.artifacts
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadPromises = artifacts.map(artifact =>
|
||||||
|
artifactClient.downloadArtifact(artifact.id, {
|
||||||
|
...options,
|
||||||
|
path: isSingleArtifactDownload
|
||||||
|
? resolvedPath
|
||||||
|
: path.join(resolvedPath, artifact.name)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const chunkedPromises = chunk(downloadPromises, PARALLEL_DOWNLOADS)
|
||||||
|
for (const chunk of chunkedPromises) {
|
||||||
|
await Promise.all(chunk)
|
||||||
|
}
|
||||||
|
|
||||||
|
core.info(`Total of ${artifacts.length} artifact(s) downloaded`)
|
||||||
|
core.setOutput(Outputs.DownloadPath, resolvedPath)
|
||||||
|
core.info('Download artifact has finished successfully')
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run().catch(err =>
|
||||||
|
core.setFailed(`Unable to download artifact(s): ${err.message}`)
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user