gh release download: Fetch Release Assets in CI
gh release download retrieves the assets attached to a release, filtered by glob pattern.
Pipelines that consume a prebuilt binary or fixture from a release use gh release download to grab exactly the assets they need.
What it does
gh release download fetches assets from a named release tag, or the latest release if no tag is given. --pattern selects which assets by glob, and --archive downloads the source tarball or zipball instead of attached assets.
Common usage
gh release download v1.2.0
gh release download v1.2.0 --pattern "*-linux-amd64.tar.gz"
gh release download --pattern "*.deb" --dir ./artifacts
gh release download v1.2.0 --archive tar.gzFlags
| Flag | What it does |
|---|---|
| -p, --pattern <glob> | Download only assets matching the glob |
| -D, --dir <dir> | Directory to download into |
| -A, --archive <format> | Download source archive: zip or tar.gz |
| -O, --output <file> | Write a single asset to a specific path |
| --clobber | Overwrite existing files |
| -R, --repo <owner/repo> | Target a specific repository |
In CI
Set GH_TOKEN and permissions: { contents: read }. Without --pattern or --archive the command downloads every asset, which can be large; scope it. Use --clobber when a step may re-run and files already exist.
Common errors in CI
"release not found" means the tag does not exist or is a draft the token cannot see. "no assets match the file pattern" means the --pattern glob matched nothing; check the exact asset names with gh release view. "gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable" means GH_TOKEN is unset.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # history, tags, and git describe all need this
- run: |
git rev-parse --is-shallow-repository # expect false
git rev-parse --abbrev-ref HEAD # prints HEAD when detached