V2 Download Artifact (#27)
* V2 Preview (#19) * V2 Setup * Add end-to-end tests * Update tests * Update tests * Update tests * Update tests again * Misc Updates * Improve logs * Update release * Update README.md * @actions/artifact v0.2.0 * Update to the latest version of the @actions/artifact package * Update @actions/artifact to 0.3.1 * Misc Updates * Add .gitattributes * Update Readme * Update test YAMLpull/28/head v2.0
parent
b85295d276
commit
1de1dea89c
|
@ -0,0 +1,3 @@
|
|||
node_modules/
|
||||
lib/
|
||||
dist/
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"env": { "node": true, "jest": true },
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:import/errors",
|
||||
"plugin:import/warnings",
|
||||
"plugin:import/typescript",
|
||||
"plugin:prettier/recommended",
|
||||
"prettier/@typescript-eslint"
|
||||
],
|
||||
"plugins": ["@typescript-eslint"]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
* text=auto eol=lf
|
|
@ -0,0 +1,104 @@
|
|||
name: Test
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Build
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
runs-on: [ubuntu-latest, macos-latest, windows-latest]
|
||||
fail-fast: false
|
||||
|
||||
runs-on: ${{ matrix.runs-on }}
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set Node.js 12.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
|
||||
- name: npm install
|
||||
run: npm install
|
||||
|
||||
- name: Compile
|
||||
run: npm run build
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Format
|
||||
run: npm run format-check
|
||||
|
||||
# Test end-to-end by uploading two artifacts and then downloading them
|
||||
# Once upload-artifact v2 is out of preview, switch over
|
||||
- name: Create artifacts
|
||||
run: |
|
||||
mkdir -p path/to/artifact-A
|
||||
mkdir -p path/to/artifact-B
|
||||
echo "Lorem ipsum dolor sit amet" > path/to/artifact-A/file-A.txt
|
||||
echo "Hello world from file B" > path/to/artifact-B/file-B.txt
|
||||
|
||||
- name: Upload artifact A
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: 'Artifact-A'
|
||||
path: path/to/artifact-A
|
||||
|
||||
- name: Upload artifact B
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: 'Artifact-B'
|
||||
path: path/to/artifact-B
|
||||
|
||||
# Test downloading a single artifact
|
||||
- name: Download artifact A
|
||||
uses: ./
|
||||
with:
|
||||
name: 'Artifact-A'
|
||||
path: some/new/path
|
||||
|
||||
- name: Verify successful download
|
||||
run: |
|
||||
$file = "some/new/path/file-A.txt"
|
||||
if(!(Test-Path -path $file))
|
||||
{
|
||||
Write-Error "Expected file does not exist"
|
||||
}
|
||||
if(!((Get-Content $file) -ceq "Lorem ipsum dolor sit amet"))
|
||||
{
|
||||
Write-Error "File contents of downloaded artifact are incorrect"
|
||||
}
|
||||
shell: pwsh
|
||||
|
||||
# Test downloading both artifacts at once
|
||||
- name: Download all Artifacts
|
||||
uses: ./
|
||||
with:
|
||||
path: some/other/path
|
||||
|
||||
- name: Verify successful download
|
||||
run: |
|
||||
$fileA = "some/other/path/Artifact-A/file-A.txt"
|
||||
$fileB = "some/other/path/Artifact-B/file-B.txt"
|
||||
if(!(Test-Path -path $fileA) -or !(Test-Path -path $fileB))
|
||||
{
|
||||
Write-Error "Expected files do not exist"
|
||||
}
|
||||
if(!((Get-Content $fileA) -ceq "Lorem ipsum dolor sit amet") -or !((Get-Content $fileB) -ceq "Hello world from file B"))
|
||||
{
|
||||
Write-Error "File contents of downloaded artifacts are incorrect"
|
||||
}
|
||||
shell: pwsh
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# Ignore node_modules, ncc is used to compile nodejs modules into a single file in the releases branch
|
||||
node_modules/
|
||||
|
||||
# Ignore js files that are transpiled from ts files in src/
|
||||
lib/
|
|
@ -0,0 +1,3 @@
|
|||
dist/
|
||||
lib/
|
||||
node_modules/
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
75
README.md
75
README.md
|
@ -1,38 +1,91 @@
|
|||
# download-artifact
|
||||
# Download-Artifact v2
|
||||
|
||||
This downloads artifacts from your build.
|
||||
This downloads artifacts from your build
|
||||
|
||||
See also [upload-artifact](https://github.com/actions/upload-artifact).
|
||||
|
||||
# What's new
|
||||
|
||||
- Download all artifacts at once
|
||||
- Port entire action to typescript from a runner plugin so it is easier to collaborate and accept contributions
|
||||
|
||||
Refer [here](https://github.com/actions/download-artifact/tree/v1) for the previous version
|
||||
|
||||
# Usage
|
||||
|
||||
See [action.yml](action.yml)
|
||||
|
||||
Basic (download to current working directory):
|
||||
# Download a Single Artifact
|
||||
|
||||
Basic (download to the current working directory):
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/download-artifact@v1
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: my-artifact
|
||||
|
||||
- run: cat my-artifact
|
||||
- name: Display structure of downloaded files
|
||||
run: ls -R
|
||||
```
|
||||
|
||||
Download to specific directory:
|
||||
Download to a specific directory:
|
||||
```yaml
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/download-artifact@v1
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: my-artifact
|
||||
path: path/to/artifact
|
||||
|
||||
- run: ls path/to/artifact
|
||||
- name: Display structure of downloaded files
|
||||
run: ls -R
|
||||
working-directory: path/to/artifact
|
||||
```
|
||||
# Download All Artifacts
|
||||
|
||||
If the `name` input parameter is not provided, all artifacts will be downloaded. To differentiate between downloaded artifacts, a directory denoted by the artifacts name will be created for each individual artifact.
|
||||
|
||||
Example, if there are two artifacts `Artifact-A` and `Artifact-B`, and the directory is `etc/usr/artifacts/`, the directory structure will look like this:
|
||||
```
|
||||
etc/usr/artifacts/
|
||||
Artifact-A/
|
||||
... contents of Artifact-A
|
||||
Artifact-B/
|
||||
... contents of Artifact-B
|
||||
```
|
||||
|
||||
Download all artifacts to a specific directory
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/download-artifact@v2
|
||||
with:
|
||||
path: path/to/artifacts
|
||||
|
||||
- name: Display structure of downloaded files
|
||||
run: ls -R
|
||||
working-directory: path/to/artifacts
|
||||
```
|
||||
|
||||
Download all artifacts to the current working directory
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- uses: actions/download-artifact@v2
|
||||
|
||||
- name: Display structure of downloaded files
|
||||
run: ls -R
|
||||
```
|
||||
|
||||
# @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.
|
||||
|
||||
|
||||
# License
|
||||
|
||||
|
|
|
@ -4,9 +4,10 @@ author: 'GitHub'
|
|||
inputs:
|
||||
name:
|
||||
description: 'Artifact name'
|
||||
required: true
|
||||
required: false
|
||||
path:
|
||||
description: 'Destination path'
|
||||
required: false
|
||||
runs:
|
||||
# Plugins live on the runner and are only available to a certain set of first party actions.
|
||||
plugin: 'download'
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"name": "download-artifact",
|
||||
"version": "2.0.0",
|
||||
"description": "Download a build artifact that was previously uploaded in the workflow by the upload-artifact action",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"release": "ncc build src/download-artifact.ts && git add -f dist/",
|
||||
"check-all": "concurrently \"npm:format-check\" \"npm:lint\" \"npm:build\"",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint **/*.ts"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/download-artifact.git"
|
||||
},
|
||||
"keywords": [
|
||||
"Actions",
|
||||
"GitHub",
|
||||
"Artifacts",
|
||||
"Download"
|
||||
],
|
||||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/download-artifact/issues"
|
||||
},
|
||||
"homepage": "https://github.com/actions/download-artifact#readme",
|
||||
"devDependencies": {
|
||||
"@actions/artifact": "^0.3.1",
|
||||
"@actions/core": "^1.2.3",
|
||||
"@typescript-eslint/parser": "^2.27.0",
|
||||
"@zeit/ncc": "^0.22.1",
|
||||
"concurrently": "^5.1.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-github": "^3.4.1",
|
||||
"prettier": "^2.0.4",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
export enum Inputs {
|
||||
Name = 'name',
|
||||
Path = 'path'
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as artifact from '@actions/artifact'
|
||||
import {Inputs} from './constants'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const name = core.getInput(Inputs.Name, {required: false})
|
||||
const path = core.getInput(Inputs.Path, {required: false})
|
||||
|
||||
const artifactClient = artifact.create()
|
||||
if (!name) {
|
||||
// download all artifacts
|
||||
const downloadResponse = await artifactClient.downloadAllArtifacts(path)
|
||||
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
|
||||
const downloadOptions = {
|
||||
createArtifactFolder: false
|
||||
}
|
||||
const downloadResponse = await artifactClient.downloadArtifact(
|
||||
name,
|
||||
path,
|
||||
downloadOptions
|
||||
)
|
||||
core.info(
|
||||
`Artifact ${downloadResponse.artifactName} was downloaded to ${downloadResponse.downloadPath}`
|
||||
)
|
||||
}
|
||||
core.info('Artifact download has finished successfully')
|
||||
} catch (err) {
|
||||
core.setFailed(err.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
Loading…
Reference in New Issue