mirror of
https://github.com/actions/download-artifact.git
synced 2025-08-19 14:09:52 +08:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
381af06b42 | ||
|
83fcc74d04 | ||
|
1ac47ba4b6 |
18
.github/workflows/test.yml
vendored
18
.github/workflows/test.yml
vendored
@@ -68,16 +68,24 @@ jobs:
|
||||
name: 'Artifact-A'
|
||||
path: some/new/path
|
||||
|
||||
# Test downloading an artifact using tilde expansion
|
||||
- name: Download artifact A
|
||||
uses: ./
|
||||
with:
|
||||
name: 'Artifact-A'
|
||||
path: ~/some/path/with/a/tilde
|
||||
|
||||
- name: Verify successful download
|
||||
run: |
|
||||
$file = "some/new/path/file-A.txt"
|
||||
if(!(Test-Path -path $file))
|
||||
$file1 = "some/new/path/file-A.txt"
|
||||
$file2 = "~/some/path/with/a/tilde/file-A.txt"
|
||||
if(!(Test-Path -path $file1) -or !(Test-Path -path $file2))
|
||||
{
|
||||
Write-Error "Expected file does not exist"
|
||||
Write-Error "Expected files do not exist"
|
||||
}
|
||||
if(!((Get-Content $file) -ceq "Lorem ipsum dolor sit amet"))
|
||||
if(!((Get-Content $file1) -ceq "Lorem ipsum dolor sit amet") -or !((Get-Content $file2) -ceq "Lorem ipsum dolor sit amet"))
|
||||
{
|
||||
Write-Error "File contents of downloaded artifact are incorrect"
|
||||
Write-Error "File contents of downloaded artifacts are incorrect"
|
||||
}
|
||||
shell: pwsh
|
||||
|
||||
|
10
README.md
10
README.md
@@ -46,6 +46,14 @@ steps:
|
||||
working-directory: path/to/artifact
|
||||
```
|
||||
|
||||
Basic tilde expansion is supported for the `path` input:
|
||||
```yaml
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: my-artifact
|
||||
path: ~/download/path
|
||||
```
|
||||
|
||||
## Compatibility between `v1` and `v2`
|
||||
|
||||
When using `download-artifact@v1`, a directory denoted by the name of the artifact would be created if the `path` input was not provided. All of the contents would be downloaded to this directory.
|
||||
@@ -129,7 +137,7 @@ steps:
|
||||
|
||||
# @actions/artifact package
|
||||
|
||||
Internally the [@actions/artifact](https://github.com/actions/toolkit/tree/master/packages/artifact) NPM package is used to interact with artifacts. You can find additional documentation there along with all the source code related to artifact download.
|
||||
Internally the [@actions/artifact](https://github.com/actions/toolkit/tree/main/packages/artifact) NPM package is used to interact with artifacts. You can find additional documentation there along with all the source code related to artifact download.
|
||||
|
||||
|
||||
# License
|
||||
|
16
dist/index.js
vendored
16
dist/index.js
vendored
@@ -6634,6 +6634,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(__webpack_require__(470));
|
||||
const artifact = __importStar(__webpack_require__(214));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const path_1 = __webpack_require__(622);
|
||||
const constants_1 = __webpack_require__(694);
|
||||
function run() {
|
||||
@@ -6641,12 +6642,21 @@ function run() {
|
||||
try {
|
||||
const name = core.getInput(constants_1.Inputs.Name, { required: false });
|
||||
const path = core.getInput(constants_1.Inputs.Path, { required: false });
|
||||
let resolvedPath;
|
||||
// resolve tilde expansions, path.replace only replaces the first occurrence of a pattern
|
||||
if (path.startsWith(`~`)) {
|
||||
resolvedPath = path_1.resolve(path.replace('~', os.homedir()));
|
||||
}
|
||||
else {
|
||||
resolvedPath = path_1.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 = yield artifactClient.downloadAllArtifacts(path);
|
||||
const downloadResponse = yield 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}`);
|
||||
@@ -6658,12 +6668,12 @@ function run() {
|
||||
const downloadOptions = {
|
||||
createArtifactFolder: false
|
||||
};
|
||||
const downloadResponse = yield artifactClient.downloadArtifact(name, path, downloadOptions);
|
||||
const downloadResponse = yield 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(constants_1.Outputs.DownloadPath, path_1.resolve(path));
|
||||
core.setOutput(constants_1.Outputs.DownloadPath, resolvedPath);
|
||||
core.info('Artifact download has finished successfully');
|
||||
}
|
||||
catch (err) {
|
||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@@ -1782,9 +1782,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
||||
"version": "4.17.19",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
|
||||
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==",
|
||||
"dev": true
|
||||
},
|
||||
"loose-envify": {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as artifact from '@actions/artifact'
|
||||
import * as os from 'os'
|
||||
import {resolve} from 'path'
|
||||
import {Inputs, Outputs} from './constants'
|
||||
|
||||
@@ -8,6 +9,15 @@ async function run(): Promise<void> {
|
||||
const name = core.getInput(Inputs.Name, {required: false})
|
||||
const path = core.getInput(Inputs.Path, {required: false})
|
||||
|
||||
let resolvedPath
|
||||
// resolve tilde expansions, path.replace only replaces the first occurrence of a pattern
|
||||
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
|
||||
@@ -15,7 +25,9 @@ async function run(): Promise<void> {
|
||||
core.info(
|
||||
'Creating an extra directory for each artifact that is being downloaded'
|
||||
)
|
||||
const downloadResponse = await artifactClient.downloadAllArtifacts(path)
|
||||
const downloadResponse = await artifactClient.downloadAllArtifacts(
|
||||
resolvedPath
|
||||
)
|
||||
core.info(`There were ${downloadResponse.length} artifacts downloaded`)
|
||||
for (const artifact of downloadResponse) {
|
||||
core.info(
|
||||
@@ -30,7 +42,7 @@ async function run(): Promise<void> {
|
||||
}
|
||||
const downloadResponse = await artifactClient.downloadArtifact(
|
||||
name,
|
||||
path,
|
||||
resolvedPath,
|
||||
downloadOptions
|
||||
)
|
||||
core.info(
|
||||
@@ -39,7 +51,7 @@ async function run(): Promise<void> {
|
||||
}
|
||||
// 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, resolve(path))
|
||||
core.setOutput(Outputs.DownloadPath, resolvedPath)
|
||||
core.info('Artifact download has finished successfully')
|
||||
} catch (err) {
|
||||
core.setFailed(err.message)
|
||||
|
Reference in New Issue
Block a user