Compare commits

...

14 Commits

Author SHA1 Message Date
Konrad Pabjan 2a5974104b
Update README.md 2020-07-15 12:19:31 +02:00
Konrad Pabjan 7e5b6f00de
Misc Download Artifact Improvements (#43)
* Various improvements to download-artifact

* Resolve input path

* README updates

* PR feedback
2020-07-15 12:09:31 +02:00
Konrad Pabjan 385ad92b52
Create CONTRIBUTING.md 2020-07-13 12:55:53 +02:00
Konrad Pabjan 552dca742d
Create CODE_OF_CONDUCT.md 2020-07-13 12:49:43 +02:00
Josh Gross 6cdc83a8a8
Merge pull request #39 from actions/joshmgross/code-scanning
Create codeql-analysis.yml
2020-05-11 10:47:46 -04:00
Josh Gross 1e32d64f05
Add paths ignore for md files 2020-05-11 09:48:46 -04:00
Josh Gross c898b9b624
Create codeql-analysis.yml 2020-05-11 09:30:11 -04:00
Konrad Pabjan d0b19596d3
V2 Updates (#36)
* Update README with compatibilty differences between v1 and v2

* NPM package updates and rebuild index.js

* Update README

* Compat update
2020-04-30 22:50:01 +02:00
dependabot[bot] 6849460513
Bump @actions/http-client from 1.0.7 to 1.0.8 (#34)
Bumps [@actions/http-client](https://github.com/actions/http-client) from 1.0.7 to 1.0.8.
- [Release notes](https://github.com/actions/http-client/releases)
- [Changelog](https://github.com/actions/http-client/blob/master/RELEASES.md)
- [Commits](https://github.com/actions/http-client/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-30 16:05:47 +02:00
dependabot[bot] 1b06ce6dcd
Bump acorn from 7.1.0 to 7.1.1 (#28)
Bumps [acorn](https://github.com/acornjs/acorn) from 7.1.0 to 7.1.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/7.1.0...7.1.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-30 16:05:06 +02:00
Konrad Pabjan 1de1dea89c
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 YAML
2020-04-28 15:45:21 +02:00
Josh Gross b85295d276
Merge pull request #21 from actions/joshmgross/fix-example
Fix README example
2020-03-02 09:20:48 -05:00
Josh Gross 7d64653e56
Use `ls` instead of `cat` 2020-02-28 14:07:54 -05:00
Josh Gross ffb9221ff3
Fix README example 2020-02-28 14:05:50 -05:00
18 changed files with 10996 additions and 15 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
node_modules/
lib/
dist/

16
.eslintrc.json Normal file
View File

@ -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"]
}

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

47
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@ -0,0 +1,47 @@
name: "Code scanning - action"
on:
push:
paths-ignore:
- '**.md'
schedule:
- cron: '0 11 * * 5'
jobs:
CodeQL-Build:
strategy:
fail-fast: false
# CodeQL runs on ubuntu-latest and windows-latest
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, 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)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

104
.github/workflows/test.yml vendored Normal file
View File

@ -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

5
.gitignore vendored Normal file
View File

@ -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/

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
dist/
lib/
node_modules/

11
.prettierrc.json Normal file
View File

@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

76
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at opensource@github.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

52
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,52 @@
## Contributing
[fork]: https://github.com/actions/download-artifact/fork
[pr]: https://github.com/actions/download-artifact/compare
[style]: https://github.com/styleguide/js
[code-of-conduct]: CODE_OF_CONDUCT.md
Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
## Found a bug?
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/actions/download-artifact/issues).
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/actions/download-artifact/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or a **reproducable test case** demonstrating the expected behavior that is not occurring.
- If possible, use the relevant bug report templates to create the issue.
## What should I know before submitting a pull request or issue
The code related to `download-artifact` is split between this repository and [actions/toolkit](https://github.com/actions/toolkit) where the `@actions/artifact` npm package is housed. The npm package contains the core functionality to interact with artifacts. Any extra functionality on top of interacting with the apis such as search is inside this repository.
Artifact related issues will be tracked in this repository so please do not open duplicate issues in `actions/toolkit`.
## Submitting a pull request
1. [Fork][fork] and clone the repository
2. Configure and install the dependencies: `npm install`
3. Make sure the tests pass on your machine: `npm run test`
4. Create a new branch: `git checkout -b my-branch-name`
5. Make your change, add tests, and make sure the tests still pass
6. Make sure your code is correctly formatted: `npm run format`
7. Make sure your code passes linting: `npm run lint`
8. Update `dist/index.js` using `npm run release`. This creates a single javascript file that is used as an entry-point for the action
7. Push to your fork and [submit a pull request][pr]
8. Pat your self on the back and wait for your pull request to be reviewed and merged.
Here are a few things you can do that will increase the likelihood of your pull request being accepted:
- Write tests.
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
## Resources
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
- [GitHub Help](https://help.github.com)
Thanks! :heart: :heart: :heart:
GitHub Actions Team :octocat:

120
README.md
View File

@ -1,39 +1,137 @@
# 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
- Output parameter for the download path
- 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: cat path/to/artifact
- name: Display structure of downloaded files
run: ls -R
working-directory: path/to/artifact
```
## 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.
```
current/working/directory/
my-artifact/
... contents of my-artifact
```
With `v2`, there is no longer an extra directory that is created if the `path` input is not provided. All the contents are downloaded to the current working directory.
```
current/working/directory/
... contents of my-artifact
```
To maintain the same behavior for `v2`, you can set the `path` to the name of the artifact so an extra directory gets created.
```
- uses: actions/download-artifact@v2
with:
name: my-artifact
path: my-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
```
# Download path output
The `download-path` step output contains information regarding where the artifact was downloaded to. This output can be used for a variety of purposes such as logging or as input to other actions. Be aware of the extra directory that is created if downloading all artifacts (no name specified).
```yaml
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
id: download
with:
name: 'my-artifact'
path: path/to/artifacts
- name: 'Echo download path'
run: echo ${{steps.download.outputs.download-path}}
```
> Note: The `id` defined in the `download/artifact` step must match the `id` defined in the `echo` step (i.e `steps.[ID].outputs.download-path`)
# @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
The scripts and documentation in this project are released under the [MIT License](LICENSE)

View File

@ -4,9 +4,10 @@ author: 'GitHub'
inputs:
name:
description: 'Artifact name'
required: true
required: false
path:
description: 'Destination 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'

7587
dist/index.js vendored Normal file

File diff suppressed because it is too large Load Diff

2866
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

42
package.json Normal file
View File

@ -0,0 +1,42 @@
{
"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.4",
"@types/node": "^12.12.6",
"@typescript-eslint/parser": "^2.30.0",
"@zeit/ncc": "^0.22.1",
"concurrently": "^5.2.0",
"eslint": "^7.4.0",
"eslint-plugin-github": "^3.4.1",
"prettier": "^2.0.5",
"typescript": "^3.8.3"
}
}

7
src/constants.ts Normal file
View File

@ -0,0 +1,7 @@
export enum Inputs {
Name = 'name',
Path = 'path'
}
export enum Outputs {
DownloadPath = 'download-path'
}

49
src/download-artifact.ts Normal file
View File

@ -0,0 +1,49 @@
import * as core from '@actions/core'
import * as artifact from '@actions/artifact'
import {resolve} from 'path'
import {Inputs, Outputs} 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
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(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
core.info(`Starting download for ${name}`)
const downloadOptions = {
createArtifactFolder: false
}
const downloadResponse = await artifactClient.downloadArtifact(
name,
path,
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, resolve(path))
core.info('Artifact download has finished successfully')
} catch (err) {
core.setFailed(err.message)
}
}
run()

13
tsconfig.json Normal file
View File

@ -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"]
}