Skip to content

Commit e7eefc4

Browse files
authoredApr 28, 2020
V2 Upload Artifact (actions#70)
* V2 Preview (actions#54) * V2 Upload Artifact * Improve logs * Update release * Update test.yml * Update test.yml * Update test.yml * @actions/artifact v0.2.0 package * Add extra YAML test * Extra Documentation * Update README.md * Update README.md * Update NPM packages * Update to @actions/artifact 0.3.1 * Update readme from v2 preview to v2 * Add .gitattributes * Misc Updates * macOS to macos * Update YAML so only push events trigger on the master branch
1 parent 1283ca1 commit e7eefc4

18 files changed

+16404
-12
lines changed
 

‎.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
lib/
3+
dist/

‎.eslintrc.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": { "node": true, "jest": true },
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": { "ecmaVersion": 9, "sourceType": "module" },
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:import/errors",
10+
"plugin:import/warnings",
11+
"plugin:import/typescript",
12+
"plugin:prettier/recommended",
13+
"prettier/@typescript-eslint"
14+
],
15+
"rules": {
16+
"@typescript-eslint/no-empty-function": "off"
17+
},
18+
"plugins": ["@typescript-eslint", "jest"]
19+
}

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

‎.github/workflows/test.yml

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
paths-ignore:
7+
- '**.md'
8+
pull_request:
9+
paths-ignore:
10+
- '**.md'
11+
12+
jobs:
13+
14+
build:
15+
name: Build
16+
17+
strategy:
18+
matrix:
19+
runs-on: [ubuntu-latest, macos-latest, windows-latest]
20+
fail-fast: false
21+
22+
runs-on: ${{ matrix.runs-on }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v2
27+
28+
- name: Set Node.js 12.x
29+
uses: actions/setup-node@v1
30+
with:
31+
node-version: 12.x
32+
33+
- name: npm install
34+
run: npm install
35+
36+
- name: Compile
37+
run: npm run build
38+
39+
- name: npm test
40+
run: npm test
41+
42+
- name: Lint
43+
run: npm run lint
44+
45+
- name: Format
46+
run: npm run format-check
47+
48+
# Test end-to-end by uploading two artifacts and then downloading them
49+
- name: Create artifact files
50+
run: |
51+
mkdir -p path/to/dir-1
52+
mkdir -p path/to/dir-2
53+
mkdir -p path/to/dir-3
54+
echo "Lorem ipsum dolor sit amet" > path/to/dir-1/file1.txt
55+
echo "Hello world from file #2" > path/to/dir-2/file2.txt
56+
echo "This is a going to be a test for a large enough file that should get compressed with GZip. The @actions/artifact package uses GZip to upload files. This text should have a compression ratio greater than 100% so it should get uploaded using GZip" > path/to/dir-3/gzip.txt
57+
58+
# Upload a single file artifact
59+
- name: 'Upload artifact #1'
60+
uses: ./
61+
with:
62+
name: 'Artifact-A'
63+
path: path/to/dir-1/file1.txt
64+
65+
# Upload using a wildcard pattern, name should default to 'artifact' if not provided
66+
- name: 'Upload artifact #2'
67+
uses: ./
68+
with:
69+
path: path/**/dir*/
70+
71+
# Upload a directory that contains a file that will be uploaded with GZip
72+
- name: 'Upload artifact #3'
73+
uses: ./
74+
with:
75+
name: 'GZip-Artifact'
76+
path: path/to/dir-3/
77+
78+
# Verify artifacts. Switch to download-artifact@v2 once it's out of preview
79+
80+
# Download Artifact #1 and verify the correctness of the content
81+
- name: 'Download artifact #1'
82+
uses: actions/download-artifact@v1
83+
with:
84+
name: 'Artifact-A'
85+
path: some/new/path
86+
87+
- name: 'Verify Artifact #1'
88+
run: |
89+
$file = "some/new/path/file1.txt"
90+
if(!(Test-Path -path $file))
91+
{
92+
Write-Error "Expected file does not exist"
93+
}
94+
if(!((Get-Content $file) -ceq "Lorem ipsum dolor sit amet"))
95+
{
96+
Write-Error "File contents of downloaded artifact are incorrect"
97+
}
98+
shell: pwsh
99+
100+
# Download Artifact #2 and verify the correctness of the content
101+
- name: 'Download artifact #2'
102+
uses: actions/download-artifact@v1
103+
with:
104+
name: 'artifact'
105+
path: some/other/path
106+
107+
- name: 'Verify Artifact #2'
108+
run: |
109+
$file1 = "some/other/path/to/dir-1/file1.txt"
110+
$file2 = "some/other/path/to/dir-2/file2.txt"
111+
if(!(Test-Path -path $file1) -or !(Test-Path -path $file2))
112+
{
113+
Write-Error "Expected files do not exist"
114+
}
115+
if(!((Get-Content $file1) -ceq "Lorem ipsum dolor sit amet") -or !((Get-Content $file2) -ceq "Hello world from file #2"))
116+
{
117+
Write-Error "File contents of downloaded artifacts are incorrect"
118+
}
119+
shell: pwsh
120+
121+
# Download Artifact #3 and verify the correctness of the content
122+
- name: 'Download artifact #3'
123+
uses: actions/download-artifact@v1
124+
with:
125+
name: 'GZip-Artifact'
126+
path: gzip/artifact/path
127+
128+
# Because a directory was used as input during the upload the parent directories, path/to/dir-3/, should not be included in the uploaded artifact
129+
- name: 'Verify Artifact #3'
130+
run: |
131+
$gzipFile = "gzip/artifact/path/gzip.txt"
132+
if(!(Test-Path -path $gzipFile))
133+
{
134+
Write-Error "Expected file do not exist"
135+
}
136+
if(!((Get-Content $gzipFile) -ceq "This is a going to be a test for a large enough file that should get compressed with GZip. The @actions/artifact package uses GZip to upload files. This text should have a compression ratio greater than 100% so it should get uploaded using GZip"))
137+
{
138+
Write-Error "File contents of downloaded artifact is incorrect"
139+
}
140+
shell: pwsh

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
lib/
3+
__tests__/_temp/

‎.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
lib/
3+
node_modules/

‎.prettierrc.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid",
10+
"parser": "typescript"
11+
}

‎README.md

+112-8
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,149 @@
1-
# upload-artifact
1+
# Upload-Artifact v2
22

3-
This uploads artifacts from your workflow.
3+
This uploads artifacts from your workflow allowing you to share data between jobs and store data once a workflow is complete.
44

55
See also [download-artifact](https://github.com/actions/download-artifact).
66

7+
# What's new
8+
9+
- Easier upload
10+
- Specify a wildcard pattern
11+
- Specify an individual file
12+
- Specify a directory (previously you were limited to only this option)
13+
- Upload an artifact without providing a name
14+
- Fix for artifact uploads sometimes not working with containers
15+
- Proxy support out of the box
16+
- Port entire action to typescript from a runner plugin so it is easier to collaborate and accept contributions
17+
18+
Refer [here](https://github.com/actions/upload-artifact/tree/releases/v1) for the previous version
19+
720
# Usage
821

922
See [action.yml](action.yml)
1023

11-
Basic:
24+
### Upload an Individual File
1225
```yaml
1326
steps:
14-
- uses: actions/checkout@v1
27+
- uses: actions/checkout@v2
1528

1629
- run: mkdir -p path/to/artifact
1730

1831
- run: echo hello > path/to/artifact/world.txt
1932

20-
- uses: actions/upload-artifact@v1
33+
- uses: actions/upload-artifact@v2
34+
with:
35+
name: my-artifact
36+
path: path/to/artifact/world.txt
37+
```
38+
39+
### Upload an Entire Directory
40+
41+
```yaml
42+
- uses: actions/upload-artifact@v2
43+
with:
44+
name: my-artifact
45+
path: path/to/artifact/ # or path/to/artifact
46+
```
47+
48+
### Upload using a Wildcard Pattern:
49+
```yaml
50+
- uses: actions/upload-artifact@v2
2151
with:
2252
name: my-artifact
23-
path: path/to/artifact
53+
path: path/**/[abc]rtifac?/*
2454
```
2555
56+
For supported wildcards along with behavior and documentation, see [@actions/glob](https://github.com/actions/toolkit/tree/master/packages/glob) which is used internally to search for files.
57+
58+
Relative and absolute file paths are both allowed. Relative paths are rooted against the current working directory. Paths that begin with a wildcard character should be quoted to avoid being interpreted as YAML aliases.
59+
60+
The [@actions/artifact](https://github.com/actions/toolkit/tree/master/packages/artifact) package is also used internally to handle most of the logic around uploading an artifact. There is extra documentation around upload limitations and behavior in the toolkit repo that is worth checking out.
61+
62+
### Conditional Artifact Upload
63+
2664
To upload artifacts only when the previous step of a job failed, use [`if: failure()`](https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#job-status-check-functions):
2765

2866
```yaml
29-
- uses: actions/upload-artifact@v1
67+
- uses: actions/upload-artifact@v2
3068
if: failure()
3169
with:
3270
name: my-artifact
33-
path: path/to/artifact
71+
path: path/to/artifact/
72+
```
73+
74+
### Uploading without an artifact name
75+
76+
You can upload an artifact without specifying a name
77+
```yaml
78+
- uses: actions/upload-artifact@v2
79+
with:
80+
path: path/to/artifact/world.txt
81+
```
82+
83+
If not provided, `artifact` will be used as the default name which will manifest itself in the UI after upload.
84+
85+
### Uploading to the same artifact
86+
87+
Each artifact behaves as a file share. Uploading to the same artifact multiple times in the same workflow can overwrite and append already uploaded files
88+
89+
```yaml
90+
- run: echo hi > world.txt
91+
- uses: actions/upload-artifact@v2
92+
with:
93+
path: world.txt
94+
95+
- run: echo howdy > extra-file.txt
96+
- uses: actions/upload-artifact@v2
97+
with:
98+
path: extra-file.txt
99+
100+
- run: echo hello > world.txt
101+
- uses: actions/upload-artifact@v2
102+
with:
103+
path: world.txt
104+
```
105+
With the following example, the available artifact (named `artifact` which is the default if no name is provided) would contain both `world.txt` (`hello`) and `extra-file.txt` (`howdy`).
106+
107+
### Environment Variables and Tilde Expansion
108+
109+
You can use `~` in the path input as a substitute for `$HOME`. Basic tilde expansion is supported.
110+
111+
```yaml
112+
- run: |
113+
mkdir -p ~/new/artifact
114+
echo hello > ~/new/artifact/world.txt
115+
- uses: actions/upload-artifact@v2
116+
with:
117+
name: 'Artifacts-V2'
118+
path: '~/new/**/*'
34119
```
35120

121+
Environment variables along with context expressions can also be used for input. For documentation see [context and expression syntax](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions).
122+
123+
```yaml
124+
env:
125+
name: my-artifact
126+
steps:
127+
- run: |
128+
mkdir -p ${{ github.workspace }}/artifact
129+
echo hello > ${{ github.workspace }}/artifact/world.txt
130+
- uses: actions/upload-artifact@v2
131+
with:
132+
name: ${{ env.name }}-name
133+
path: ${{ github.workspace }}/artifact/**/*
134+
```
36135

37136
## Where does the upload go?
38137
In the top right corner of a workflow run, once the run is over, if you used this action, there will be a `Artifacts` dropdown which you can download items from. Here's a screenshot of what it looks like<br/>
39138
<img src="https://user-images.githubusercontent.com/16109154/72556687-20235a80-386d-11ea-9e2a-b534faa77083.png" width="375" height="140">
40139

41140
There is a trashcan icon that can be used to delete the artifact. This icon will only appear for users who have write permissions to the repository.
42141

142+
## Additional Documentation
143+
144+
See [persisting workflow data using artifacts](https://help.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts) for additional examples and tips.
145+
146+
See extra documentation for the [@actions/artifact](https://github.com/actions/toolkit/blob/master/packages/artifact/docs/additional-information.md) package that is used internally regarding certain behaviors and limitations.
43147

44148
# License
45149

0 commit comments

Comments
 (0)
Please sign in to comment.