Sub topic 4
Selecting files with paths, globs, and exclusions
This chapter assumes you can read a basic workflow file and have already uploaded one artifact with actions/upload-artifact@v4. Here you will control exactly which files go into an artifact.
The path input
The path input tells the action what to collect. It accepts three kinds of value:
- A single file, such as
reports/summary.json. - A directory, such as
dist/. Everything inside it is included, recursively. - A glob pattern, such as
reports/**/*.xml.
Relative paths resolve against the workspace, which is the directory where your repository was checked out. Absolute paths also work. Use forward slashes on every operating system, including Windows runners.
Glob syntax
Globs use the common wildcard rules:
| Pattern | Matches |
|---|---|
| `*` | Any characters within one path segment |
| `**` | Any number of nested directories |
| `?` | Exactly one character |
| `[abc]` | One character from the set |
For example, build/*.jar matches JAR files directly inside build. The pattern build/**/*.jar also matches JAR files in any subdirectory.
Multiple paths and exclusions
To upload several locations, use a YAML block scalar (the | character) with one pattern per line. A line that starts with ! removes matching files from the selection.
name: package
on: push
jobs:
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build && npm test
- uses: actions/upload-artifact@v4
with:
name: build-output
path: |
dist/
reports/**/*.xml
!dist/**/*.map
!reports/tmp/**
if-no-files-found: errorThis uploads the dist directory and all XML reports. It leaves out source maps and anything under reports/tmp.
YAML pitfalls
Two characters have special meaning in YAML and can break a single-line path value:
- A value starting with
*is read as a YAML alias, which causes a parse error. Writepath: "**/*.log"with quotes. - A value starting with
!is read as a YAML tag. Put exclusions inside a|block, as in the example above, or quote them.
Directory structure inside the artifact
The artifact keeps the directory layout of the selected files, but the layout depends on how many paths you gave.
- With one directory such as
dist/, the artifact root is the contents ofdist. A filedist/app.jsis stored asapp.js. - With several paths, the root is the least common ancestor directory of all matched files. For
dist/app.jsandreports/test.xml, that ancestor is the workspace. The artifact then containsdist/app.jsandreports/test.xml.
This matters when you download. If you upload dist/ alone and download into dist/, the layout matches your original. If you upload from two directories, the downloaded files carry their directory prefixes.
Hidden files
Since version 4.4, upload-artifact skips hidden files by default. A hidden file is one whose name, or whose parent directory's name, starts with a dot, such as .env or .coverage/. A pattern that clearly matches such a file will still leave it out. To include hidden files, opt in:
- uses: actions/upload-artifact@v4
with:
name: coverage
path: .coverage/
include-hidden-files: trueBe deliberate with this setting. Hidden files often hold credentials or local configuration, which the security chapter covers.
Common errors
- Nothing uploaded. The pattern is wrong or the files were not built. The default behavior is only a warning, so set
if-no-files-found: errorwhile debugging. - Unexpected folder layout. You uploaded from several directories and got a higher common ancestor than you expected. Upload one directory, or check the layout by running
ls -Rafter download. - Workflow fails to parse. A pattern starts with
*or!outside a block scalar. Quote it or move it into a|block. - Missing dotfile. Hidden files are excluded unless
include-hidden-files: trueis set.
Exercise
A step uses path: | with the lines out/ and !out/**/*.log, but the uploaded artifact still lacks out/.cache/data.bin. Name the likely cause and the fix.
Show answer
The file is inside a hidden directory (.cache), and upload-artifact v4.4 and later skips hidden files by default. The exclusion is not the cause, because it only matches .log files. Fix it by adding include-hidden-files: true to the step's with block.