Skip to content

Commit ecb2146

Browse files
committed
add compression example
1 parent 5e7604f commit ecb2146

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ See also [download-artifact](https://github.com/actions/download-artifact).
1616
- [Upload an Entire Directory](#upload-an-entire-directory)
1717
- [Upload using a Wildcard Pattern](#upload-using-a-wildcard-pattern)
1818
- [Upload using Multiple Paths and Exclusions](#upload-using-multiple-paths-and-exclusions)
19+
- [Altering compressions level (speed v. size)](#altering-compressions-level-speed-v-size)
1920
- [Customization if no files are found](#customization-if-no-files-are-found)
2021
- [(Not) Uploading to the same artifact](#not-uploading-to-the-same-artifact)
2122
- [Environment Variables and Tilde Expansion](#environment-variables-and-tilde-expansion)
@@ -40,6 +41,7 @@ For more information, see the [`@actions/artifact`](https://github.com/actions/t
4041
1. Uploads are significantly faster, upwards of 90% improvement in worst case scenarios.
4142
2. Once uploaded, an Artifact ID is returned and Artifacts are immediately available in the UI and [REST API](https://docs.github.com/en/rest/actions/artifacts). Previously, you would have to wait for the run to be completed before an ID was available or any APIs could be utilized.
4243
3. The contents of an Artifact are uploaded together into an _immutable_ archive. They cannot be altered by subsequent jobs. Both of these factors help reduce the possibility of accidentally corrupting Artifact files.
44+
4. The compression level of an Artifact can be manually tweaked for speed or size reduction.
4345

4446
### Breaking Changes
4547

@@ -156,6 +158,45 @@ If multiple paths are provided as input, the least common ancestor of all the se
156158

157159
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.
158160

161+
### Altering compressions level (speed v. size)
162+
163+
If you are uploading large or easily compressable data to your artifact, you may benefit from tweaking the compression level. By default, the compression level is `6`, the same as GNU Gzip.
164+
165+
The value can range from 0 to 9:
166+
- 0: No compression
167+
- 1: Best speed
168+
- 6: Default compression (same as GNU Gzip)
169+
- 9: Best compression
170+
171+
Higher levels will result in better compression, but will take longer to complete.
172+
For large files that are not easily compressed, a value of `0` is recommended for significantly faster uploads.
173+
174+
For instance, if you are uploading random binary data, you can save a lot of time by opting out of compression completely, since it won't benefit:
175+
176+
```yaml
177+
- name: Make a 1GB random binary file
178+
run: |
179+
dd if=/dev/urandom of=my-1gb-file bs=1M count=1000
180+
- uses: actions/upload-artifact@v4
181+
with:
182+
name: my-artifact
183+
path: my-1gb-file
184+
compression-level: 0 # no compression
185+
```
186+
187+
But, if you are uploading data that is easily compressed (like plaintext, code, etc) you can save space and cost by having a higher compression level. But this will be heavier on the CPU therefore slower to upload:
188+
189+
```yaml
190+
- name: Make a file with a lot of repeated text
191+
run: |
192+
for i in {1..100000}; do echo -n 'foobar' >> foobar.txt; done
193+
- uses: actions/upload-artifact@v4
194+
with:
195+
name: my-artifact
196+
path: foobar.txt
197+
compression-level: 9 # maximum compression
198+
```
199+
159200
### Customization if no files are found
160201

161202
If a path (or paths), result in no files being found for the artifact, the action will succeed but print out a warning. In certain scenarios it may be desirable to fail the action or suppress the warning. The `if-no-files-found` option allows you to customize the behavior of the action if no files are found:

0 commit comments

Comments
 (0)